Node.js maxing out at 1000 concurrent connections

前端 未结 2 793
滥情空心
滥情空心 2020-12-04 08:48

We\'re benchmarking node performance using a simple Hello World node server on AWS (EC2).

No matter what size instance we use Node always appears to max out at 1000

相关标签:
2条回答
  • 2020-12-04 09:22

    Use the posix module to raise the limit on the number of file descriptors your process can use.

    Install posix

    npm install posix
    

    Then in your code that runs when you launch your app...

    var posix = require('posix');
    
    // raise maximum number of open file descriptors to 10k,
    // hard limit is left unchanged
    posix.setrlimit('nofile', { soft: 10000 });
    
    0 讨论(0)
  • 2020-12-04 09:28

    You've reached the default limit of file descriptors a process can use (1024). You can check the limit on the command line by running "ulimit -n". To change the limit, you need to edit /etc/security/limits.conf. Add the follow block:

    * soft nofile 65535
    * hard nofile 65535
    root soft nofile 65535
    root hard nofile 65535
    

    "*" applies to all users except root. Limits for root must be added separately. There are soft and hard limit. Users are allowed to change their own limits up to the soft limit but not exceeding the hard limit.

    Once the file has been edited, log out and back in again. Verify the change by running ulimit -n. Restart your Node process and you should be good to go.

    There's also a system-wide file descriptor limit that can be increased with the following command:

    sysctl -w fs.file-max=65535
    
    0 讨论(0)
提交回复
热议问题