简体   繁体   中英

Multi-core multi-process node application and single-core single-process node application performance What is the difference

我很困惑libuv具有线程池机制,使用多个进程的必要性是什么?

The documentation says that (emphasis mine):

libuv provides a threadpool which can be used to run user code and get notified in the loop thread . This thread pool is internally used to run all file system operations , as well as getaddrinfo and getnameinfo requests.

To sum up, first of all libuv uses multiple threads internally to run blocking operations without blocking the loop(s) (filesystem, DNS).
Secondly, you can use them more or less for the same reasons. Imagine you have a cpu bound task that you don't know how/don't want to/cannot split in parts to be executed through different ticks, you can still spawn a thread (a work request actually) and let it execute on a separate thread. This way, your loop won't be in a stall waiting for those tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM