threadpool - Node.js thread pool and core usage -
i've read tons of articles , stackoverflow questions, , saw lot of information thread pool, no 1 talks physical cpu core usage. believe question not duplicated.
given have quad-core computer , libuv thread pool size of 4, node.js utilize 4 cores when processing lots of i/o requests(maybe more thousands)?
i'm curious i/o request uses thread pool. no 1 gives clear , full list of request. know node.js event loop single threaded uses thread pool handle i/o such accessing disk , db.
i'm curious i/o request uses thread pool.
disk i/o uses thread pool.
network i/o async beginning , not use threads.
with disk i/o, individual disk i/o calls still present javascript non-blocking , asynchronous though use threads in native code implementation. when exceed more disk i/o calls in process size of thread pool, disk i/o calls queued , when 1 of threads frees up, next disk i/o call in queue run using available thread. since javascript disk i/o non-blocking , assumes completion callback called sometime in future, queuing of requests when thread pool busy means take longer later i/o requests, otherwise javascript programming interface not affected.
given have quad-core computer , libuv thread pool size of 4, node.js utilize 4 cores when processing lots of i/o requests(maybe more thousands)?
this not node.js , hard answer in absolute reason. first referenced article below says on linux, i/o thread pool use multiple cores , offers small demo app shows that.
this specific os implementation , thread scheduler uses. node.js happily creates threads , uses them , os decides how make use of cpu given being asked overall on system. since threads in same process have communicate 1 in way, using separate cpu different threads in same process lot more complicated.
there couple node.js design patterns guaranteed take advantage of multiple cores (in modern os)
cluster app , create many clusters have processor cores. has advantage each cluster has own i/o thread pool can work independently , each can execute it's own javascript independently. 1 node.js process , multiple cores, never more 1 thread of javascript execution (this node.js referred single threaded - though use threads in library implementations). but, clustering, independent javascript execution each clustered server process.
for individual tasks might cpu-intensive (for example, image processing), can create work queue , pool of child worker processes hand work off to. has benefits in common clustering, more special purpose know cpu bottleneck , want attack specifically.
other related answers/articles:
how libuv threads in nodejs utilize multi core cpu
node.js on multi-core machines
Comments
Post a Comment