I'm trying to understand the idea of non-blocking web server and it seems like there is something I miss.
I can understand there are several reasons for "block" web request(psuedocode):
CPU bound
string on_request(arg)
{
DO_SOME_HEAVY_CPU_CALC
return "done";
}IO bound
string on_request(arg)
{
DO_A_CALL_TO_EXTERNAL_RESOURCE_SUCH_AS_WEB_IO
return "done";
}sleep
string on_request(arg)
{
sleep(VERY_VERY_LONG_TIME);
return "done";
}- are all the three can benefit from non-blocking server?
- how the situation that do benefit from the non-blocking web server really do that? I mean, when looking at the Tornado server documentation, it seems like it "free" the thread. I know that a thread can be put to sleep and wait for a signal from the operation system (at least in Linux), is this the meaning of "freeing" the thread? is this some higher level implementation? something that actually create a new thread that is waiting for new request instead of the "sleeping" one?
- Am I missing something here?
Thanks