简体   繁体   中英

NodeJS use IO threads for CPU work

Any result in google for this question refers to guides explaining how node does asynchronous operations with one thread. That not what I'm looking for.

Let say I need to process a blob, it takes 5 minutes of CPU time to process it.

I do not want to block my main thread as this worker will become unresponsive.

I would really like to to expose an interface for the logic that does the processing work, and pass it to one of the IO threads, just like in fs.readFile , and be let know when the processing is done.

How would I do that?

Javascript / Nodejs is single threaded. Your usecase seems to be fitting a message queue system. For example Rabbitmq

You basically end up with worker services (consumers) and task queuers. Your task queuers will fire a message to a message bus. the message bus forwards this message to another service.

I made a very simple example on github https://github.com/holoduke/nodejs_rabbitmq_simple_example

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