javascript - What happens if all node.js's worker threads are busy -
i try understand how node.js works , although have read article: when thread pool used? not sure happens if worker threads busy , async i/o operation ready executed.
if got http://www.future-processing.pl/blog/on-problems-with-threads-in-node-js/ article right, event loop blocked until worker thread free take care of additional i/o operation. imply if 5 users tried access webpage simultaneously (like profile page lets requires db-query), 5th user blocked until first db-query done , worker thread free again?
i/o in general not block event loop (there exceptions crypto module , things fs.*sync() methods) , in case of network i/o, libuv thread pool not used @ (only things dns (currently) , fs operations).
if database driver written in c++ node.js addon, there chance either block event loop (it's doing synchronous) or using libuv thread pool. if database driver written in javascript, typically uses sort of network i/o, mentioned not block , not use libuv thread pool.
so example, depending on how database driver implemented, 5 users serviced @ once. example, mysql @ protocol level supports 1 outstanding query @ time per connection. mysql drivers node.js queue additional queries until current query has finished. however, it's entirely possible mysql driver internally maintain sort of connection pool have greater concurrency.
however, if each of 5 requests instead causing disk, it's possible 5th request have wait until 1 of other 4 fs requests have finished, due current default size of libuv thread pool. doesn't mean event loop blocked, can still service new incoming requests , other things, 5th client have wait bit longer.
Comments
Post a Comment