|
|
|
|
|
by wvenable
5997 days ago
|
|
> Not blocking the entire PHP process while waiting for database results, waiting for a file to download, waiting for memcached to respond, etc. The thing is, I need those database results -- I can't do anything else until I have them. I received a single request from the user and I'm spitting out a single HTML response back. That's what PHP is all about. And mulithreading as optimization itself wouldn't improve performance because I'd be taking away CPU from other requests that are running concurrently. > Web apps would use a lot less memory (and hardware) if people were not so afraid of threads. Fundamentally I don't disagree; there's a lot of cool work going with event-based web servers. However, I think those designs are great for very specific tasks like chat servers and but require too much fiddling when doing traditional stateless web work. However, it may indeed be the future. |
|
You could start requesting the database results for a user that is now waiting in the tcp connect queue, cutting latency significantly.
Most people handle this with load balancing between processes, but your blocked-for-DB-results-process is sitting idle using system resources, like memory.
If you only have one user using your site at a time, then this isn't a concern. But for everyone else, blocked processes are wasteful.
but require too much fiddling when doing traditional stateless web work
Well, yeah, because you don't have threads. When you do, everything is handled by libraries for you; you can think you're blocking, but actually not block the process.