1

I found a NodeJS script on Github rocketchat_loadtest_message_listener that allows to load test an NodeJS application called Rocket Chat. The script uses the NodeJS module cluster; when the script is executed for the load testing, it forks individual processes for each user.

I have been testing with 10000 users, and in somewhere around I receive an error and my script exits. In htop, I can see it creates around 8000 threads created before it exits.

node[43580]: pthread_create: Resource temporarily unavailable
internal/cluster/worker.js:54
  return this.process.send.apply(this.process, arguments);
                           ^

TypeError: Cannot read property 'apply' of undefined
    at Worker.send (internal/cluster/worker.js:54:28)
    at main (/home/ubuntu/rocketchat_loadtest_message_listener/message_listener/app.js:194:20)
    at Object.<anonymous> (/home/ubuntu/rocketchat_loadtest_message_listener/message_listener/app.js:277:3)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)

htop screenshot

What seems to be the problem? Is it the linux kernel preventing or the NodeJS/NodeJS module to create the process/threads? I had tried altering the ulimit -s but didn't see any difference. Here's the result of ulimit -a.

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 127506
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 127506
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
sumit-sampang-rai
  • 701
  • 1
  • 7
  • 16
  • did you solve it ? i just only run npx sequelize to migrate fresh seed , on my server had run 2 api server . and the ulimit -a is same like u – Yogi Arif Widodo Sep 20 '22 at 03:11

3 Answers3

2

After looking into the Internet, I found this bug report on launchpad. Then I launched Amazon Linux 2 and found out a difference. The difference is that Amazon Linux 2 had a file /etc/security/limits.d/20-nproc.conf and the Ubuntu didn't have it. Inside the file was:

*          soft    nproc     4096
root       soft    nproc     unlimited

I ran my script on Amazon Linux 2 as root and it worked. I was able to create threads I desired and the script ran faster than in Ubuntu as well. I created the file on Ubuntu, ran the script as root but still didn't work. Seems like Ubuntu does have some problem in it.

sumit-sampang-rai
  • 701
  • 1
  • 7
  • 16
1

I had this issue with cPanel terminal.

Worked in WHM terminal with root user..

Nahid
  • 2,911
  • 1
  • 20
  • 17
0

Just found the solution to this on our WHM server. We had to disable the Shell Fork Bomb Protection to get node to run npm run production

Søren Beck Jensen
  • 1,676
  • 1
  • 12
  • 22