当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Starting Node.js Thread Pool for Parallelism

问题描述:

Yes hello. I recently came to learn that Node.js is single-threaded. I would like to use my application faster (MongoDB/Express app) so I have written the following script (I want it to use 8 processors)

#!/bin/bash

node app.js &

node app.js &

node app.js &

node app.js &

node app.js &

node app.js &

node app.js &

node app.js &

When I try to run the script, I get many errors about ports being used, but I know that TCP allows for 65536 ports and it should only try to use 8. Do I need to update my Node.js to a new version?

I am running on Amazon Linux.

Thank you.

网友答案:

Each of the processes is trying to listen on the same port. You should use Node's built-in cluster module to handle creating the child processes for you, as it will allow a single port to be shared by all the children automatically.

分享给朋友:
您可能感兴趣的文章:
随机阅读: