简体   繁体   中英

Node.js WebSocket Daemon

I've built somewhat simple websocket server application in node.js on a google cloud running debian, also created daemon service for it "websocket". The service was created with this script . Now, I've got to the load-testing using Artillery

The weird thing is - when I run my app like "node Server.js" it is able to handle up to ~ 300 requests per second without any trouble, but runnnig it like "sudo service websocket start" it stops responding at 50 RPS after about ~20-30 seconds. At this point artillery shows errors: ECONNRESET: NUMBER_OF_ERRORS and websocket becomes unavailable. The moment I stop the load-testing it instantly becomes available and responds to requests. Service shows "active (running)" the whole time.

I see nothing in the log or journal. Found no info on the web.

I'm kind of new to the linux, is there any additional limitations on the daemon that cause this?

All this is running on Debian 8 Jessie, in a Google Cloud VM. Node.js websocket module is nodejs-websocket: https://www.npmjs.com/package/nodejs-websocket

Have been able to work around this using PM2 as follows:

Install npm install -g pm2

start service as a daemon, naming it 'websocket' pm2 start /home/admin/websocket/Server.js --name="websocket"

remember daemons to restart on fail pm2 save

make PM2 startup with the machine pm2 startup -> sudo su -c "env PATH=$PATH:/usr/bin pm2 startup linux -u admin --hp /home/admin"

pm2 list to view all PM2 processes

See here and here for the reference.

PS Didn't have to remove previous service for this to work.

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