Nodejs One Request Blocks Another Requests
Solution 1:
Good read:
http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
A key line from that write up is:
…however, everything runs in parallel except your code
That means expensive I/O should be async but your code can block. but, it's typically expensive I/O that we're worried about blocking on the server.
See this other question for more details with an example: Node.js blocking the event loop?
Solution 2:
Because NodeJS is single threaded ( just like browser JavaScript ). It can only process one code at a time. We get the illusion of concurrency, because NodeJS has very fancy queue of code blocks which are fired in an asynchronous way. However once the block is processed no other block can be processed at the same time.
With NodeJS you have to make sure that every request ends (either successfuly or not), otherwise it may crash beyond any help (entire server, not only the request).
Also using process.nextTick
instead of classical loop may help your requests work faster ( i.e. be more scalable ).
Post a Comment for "Nodejs One Request Blocks Another Requests"