4 ms·
Right, it's just that the thread that is kept waiting for database could serve other clients meanwhile. While keeping the thread sleeping, it's wasting system r
by kyberias 9y ago
Right, it's just that the thread that is kept waiting for database could serve other clients meanwhile. While keeping the thread sleeping, it's wasting system resources.
For example, ASP.NET has a small number of threads and each async call allows one thread to process another request.
- toast0 9y agoThat's true in a thread oriented environment; but it's not the case in a traditional PHP environment, with one OS process per client. A PHP process does not know how to context switch between many requests; if the process is waiting for I/O the OS will schedule a different process. In this model, sending multiple backend requests concurrently, regardless of how, is of value when it lowers the total request time and lets it accept another request sooner. You can send requests to the backend through async/await language features, or more simply by using apis that separate sending a request from waiting for a response, assuming network buffers are large enough to enqueue the request(s) without blocking.