Web应用程序中的并发问题

问题描述:

在我开始做网络编程之前,我曾经认为这很容易。现在,经过一年的经验,我认为这可能真的很难主要是因为并发问题。

Before I have started to do web-programming I had thought it was easy. Now, after a year of experience I think it can be really damn hard mainly because of concurrency issues.

因为这是一个非常意想不到的发现,我试图问我更有经验的朋友(他们做了一些应用程序,如电子商店等)。具体来说,我问他们是否真的可能有并发问题需要解决,否则你有危险的数据变得不一致,他们是:没有想到这一点。这使我有点害怕我的理智,甚至一些疲惫的网络搜索有说服力地回答了这个问题。

Because that was some very unexpected finding out, I tried to ask my more experienced friends (they had made some apps like e-shops etc.) about it. Specifically, I asked them if you can really have concurrency issues that you need to solve or otherwise you are at danger of your data becoming inconsistent and they were like: "hmm, never thought of that". That made me a bit afraid of my sanity and not even some exhausting web search have persuasively answered the question.

因此,在这里,我要确保我的头脑不会导致一个非常白的polstered房间:

Hence, here I am to make sure that rails of my mind do not lead to a very white polstered room:

1)假设LAMP框架,是可能的apache运行的两个php脚本在执行中以任何可能的方式重叠?

1) supposing LAMP framework, is it possible for two php scripts run by apache to overlap in execution in any possible manner?

2)同一个脚本是否可以同时运行多次,其实例以任何可能的方式重叠?

2) is it possible for the same script to be run more than once at the same time with its instances overlapping in any possible manner?

3)是LAMP选择重要还是同样的东西适用于今天使用的任何Web开发环境?

3) was the LAMP choice important or does the same thing holds for like any web-development environment used today?

4)如果并发真的可以是一个问题,我不只是做事情,有没有任何理论,这将有助于我包围我的头,解决这些问题,像这样:嘿,有一个可能的并发问题 while:嘿,这是X的一个经典例子,可以用这种方式解决。

4) If the concurrency really can be a problem and i am not just making things up, is there any theory that would help me to wrap my head around it and solve these problems like this: "hey look, there is a possible concurrency issue" and after a while: "hey, this is a classic example of X, which can be solved this way".

5)为什么程序员倾向于把web开发看作科舍尔,同时认为他们可以轻松做到吗? (不需要回答这个,但事实现在让我现在,而我知道它以前是与我一样)

5) why programmers tend to look at web development as not being "kosher" while thinking they could do it easily? (no need to answer this but that fact pisses me off now while I know it used to be the same with me)

我知道,这可能是多吸引 -

I know, this is probably multi-sucky-general question from the *'s point of view but I have nobody really experienced around me that could help.

我不是真的认为保护共享资源的原则在Web应用程序和标准桌面程序之间太不同。资源是资源,应用程序可以多次运行,除非您特别阻止多个实例。

I don't really think the principles of protecting shared resources is too much different between web apps and standard desktop programs. Resources are resources and an app can be run more than once unless you specifically prevent multiple instances.


1)假设LAMP框架,由
apache运行的两个php脚本可能以任何可能的方式在执行中重叠?

1) supposing LAMP framework, is it possible for two php scripts run by apache to overlap in execution in any possible manner?

是的。 Apache可以在线程/进程中运行请求。两个PHP脚本请求可以同时运行。

Yes. Apache can run requests in threads/processes. Two PHP script requests could run at the same time.


2)同一个脚本可以多次运行
同时其实例以任何可能的方式重叠?

2) is it possible for the same script to be run more than once at the same time with its instances overlapping in any possible manner?

是的。 Apache可以在线程/进程中运行请求。两个PHP脚本请求可以同时运行。

Yes. Apache can run requests in threads/processes. Two PHP script requests could run at the same time.


3)是LAMP选择重要的或者像
今天使用的任何Web开发环境?

3) was the LAMP choice important or does the same thing holds for like any web-development environment used today?

Apache具有在多个线程中运行请求的方法。还有其他服务器使用异步方法。无论哪种方式,您不应该依赖Web服务器来为代码中的并发操作提供防护。这是您的代码检查资源的责任。

Apache has the methodology of running requests in multiple threads. There are other servers that use an async approach. Either way, you shouldn't rely on the web server to provide guards against concurrent ops in your code. That is the responsibility of your code to check resources.


4)如果并发真的可能是一个问题,我不只是使$有没有任何理论,这将有助于我包装我的头
周围,并解决这些问题,像这样:看起来,有一个
可能的并发问题一会儿:嘿,这是一个经典的
X的例子,可以这样解决。

4) If the concurrency really can be a problem and i am not just making things up, is there any theory that would help me to wrap my head around it and solve these problems like this: "hey look, there is a possible concurrency issue" and after a while: "hey, this is a classic example of X, which can be solved this way".

到您的代码的资源,以及您分享的内容。如果一个脚本实例需要使用文件系统,那么你的代码应该通过某种类型的同步来检查。数据库倾向于处理你对行或表的内部锁定。

It really comes down to the resources of your code, and what you are sharing. If a script for instance needs to work with the filesystem, then your code should be checking via some type of synchronization. Databases tend to handle that for you with internal locking to rows or tables.


5)为什么程序员倾向于将Web开发看作不是
kosher,同时认为他们可以轻松做到吗? (不需要回答
这个,但事实现在让我现在,而我知道以前是
与我相同)

5) why programmers tend to look at web development as not being "kosher" while thinking they could do it easily? (no need to answer this but that fact pisses me off now while I know it used to be the same with me)

我相信那些不知道如何做网页设计(特别是服务器端)的人认为它只是打字文档。一旦你这样做,你就意识到它的很多工作。

I am sure people that don't know how to do web design (especially server side) think its all just typing up word documents. Once you do it, you realize its a lot of work.