S
S
Severovostok2014-06-10 14:20:09
Node.js
Severovostok, 2014-06-10 14:20:09

How to deal with blocking/non-blocking operations in Node.js?

Hello.
I can't figure out the issue of blocking/non-blocking operations in any way.
Let me give you an example (rather primitive):
Let's say 10 clients are connected to node.js (express + socket.io), 9 of which have already passed authorization, which is a blocking operation, does this mean that at the time of authorization by the 10th client ( blocking operation), will the remaining 9 also wait for the completion of his authorization (the 10th) or is this blocking only for a specific 10th user?
The question may seem silly, but I think in the usual php-apache bundle, where all this has already been decided.
Is there any detailed article (possible in English) or a book?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-06-10
@Severovostok

In node.js (stock, if we're not talking about threads or processes), only one operation can run at a time. True, there are nuances. Your authorization is unlikely to be completely blocking. You climb into the database - in node.js, as far as I remember, this is a non-blocking operation (well ... everything is a little more complicated, but still somehow), and while the request goes to the database, something else can be done.
But if suddenly you actually have some thoughtless operation that blocks the entire process, nothing else will be processed until the operation ends. No new connections are processed, and old ones... nothing at all. This will create problems if you have blocking operations that last more than tenths of a millisecond. That is, usually everything works out very quickly, and everything slow (accessing the file system, database) should be done asynchronously, so that something else could be done to the process while waiting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question