Number of simultaneous requests a PHP server supports

Asked

Viewed 1,285 times

2

Let’s say I have a server with a 4-core/8 i7 processor threads.

In an architecture multi-threaded, assuming that a thread by request, only 8 simultaneous requests will be allowed, since the processor has 8 threads?

Whether PHP servers are multi-threaded, how they can respond to thousands of simultaneous connections?

  • I believe that with simultaneous you mean: "customers accessing at the same time". Theoretically there is no limitation, I mean, the limitation is your equipment. You may have some client lag (browsers make several attempts before giving up), but if your server is well configured it can serve 8000+ simultaneous clients.

  • Since this in debugging time would require many machines to do a realistic test, it is not done in development environment, To get an idea of the real capacity of the server will have to put it online and monitor its status. Of course, a common desktop won’t display the same performance as a server with 4 Xeon, 128 GB of memory. Even though there are many processors, there is a bottleneck in the network (a router, a NIC).

  • In practice if you need to meet a lot of customers will have to do some kind of load balancing with an intelligent router that distributes the connections by anycast with load distance parameter.

2 answers

3


They don’t. Simultaneous only the amount of existing processors. There is an illusion of simultaneity, as occurs on your computer now. It has hundreds or thousands of processes running and it seems that everything is simultaneous, but it is not. There is a change of execution.

The operating system will schedule a thread each time on each existing processor. As the exchange happens very fast it seems superficially that they are running simultaneously, but if you do a basic test of time you will see that it is not quite so.

We’re talking about a processor. It turns out that most of the tasks involve input and output, so while reading or writing data externally to the processor it becomes idle so have several threads, well more than these 8 can be useful since as a thread waits for the external resource to respond to another that is not depending on external resource can perform, which helps give the illusion of simultaneity.

Actually today it is more common for applications to work asynchronously and not depend so much on threads explicit to compensate for the use of external access.

Anyway I have my doubts if a single server can meet thousands of "simultaneous" requests with PHP.

Node limits the virtual amount of Cpus because it works asynchronously, there is no need to use threads in excess because the processor is triggered as needed, there need be no competition from CPU resources. It queues the requests in excess since there is no way to meet more than the capacity of the hardware, thus saves with the management and so scale much better, apart from the fact that the use is not so much in the "luck" of the moment.

The Node has been known to do this, but all technologies do this today, in general they use the libuv. In general people do not understand much of what they are doing, they read something and think it is what is written without questioning, without understanding what is happening there.

Read It’s always guaranteed that a multi-threaded application runs faster than using a single thread? to better understand.

  • Just adding another point worth clarifying. Platforms that process millions or billions of requests don’t just have a web server, they usually have N web Servers and N load balancers at the front.

  • Thank you. OK, I realized that a processor can only process one thread at a time, because then they say that the processor has 8 threads? So a multi-thread architecture, like the one used by some PHP servers, these threads are not the processor threads, as Julio Neto said in his answer?

  • There is a difference of definition. There is 1 chip with 4 independent processors inside it and each with the ability to run two separate processing lines each, hence gives the 8 threads really simultaneous, all others will interpose. In general people use more or less certain terminologies. thread is thread there is no thread low or high level. Thread is an operating system concept delivered to applications. We links explains all this.

1

Applications are not limited to the threads and colors of the processors. In fact, only the operating system has access to these low-level threads. And systems typically have Apis so that applications can create a virtually unlimited number of threads, dividing CPU time between them.

  • But that’s PHP servers, right? I’m studying Nodejs and it seemed to me that it’s limited by the number of threads of the processor, at least I got that idea.

  • This is something specific to nodejs. It was a project choice to nodejs to be single thread. So really it is limited to the low-level threads of the machine. But nothing prevents there being an API for Node q to create high-level threads like other languages Servers do.

  • It is worth remembering that, a PHP application, being interpreted, creates a thread of the application by request. A Node.js application is instantiated by a thread that receives and handles all requests, and for each request, a sub thread is created and receives injection of already instantiated services.

  • 3

    @Thiagolunardi Not necessarily. See for example a well-made PHP application like that of the guerrilamail, is a single loop, which meets many TCP requests simultaneously, asynchronously. It is a state machine that manages several sockets, very robust by the way. Asymchronism is something relatively simple to obtain with sockets, in any language (independent of being interpreted).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.