I am using Nodemon with Forever Module on Ubuntu Server.
我在Ubuntu服务器上使用Nodemon和Forever模块。
I use this command to start my Node Server:
我使用此命令启动我的节点服务器:
forever start -c nodemon app.js --exitcrash
It works fine for few hours (approx 48 Hours), but after that my Server stops working with these errors:
它可以正常工作几个小时(大约48小时),但之后我的服务器停止处理这些错误:
Error: getaddrinfo EMFILE
TypeError: Cannot call method 'indexOf' of undefined
Error: Handshake inactivity timeout
These errors are caused due to Exceeding Limit of Open Files/Sockets.
这些错误是由于打开文件/套接字的超出限制引起的。
Now my question is:
现在我的问题是:
Can I use -m (Which sets to unlimited in my Operating System):
我可以使用-m(在我的操作系统中设置为无限制):
max memnory size (kbytes, -m) unlimited
Should I use the above command with -m? Are there any drawbacks?
我应该使用上面的命令和-m吗?有什么缺点吗?
Or is there any other efficient solution to fix Server crashing?
或者是否有其他有效的解决方案来修复服务器崩溃?
2 个解决方案
#1
2
If you have large number of users most probably you are hitting systems maximum number of requests queued to listen socket. If you are sure your server can handle the load you can increase from default 128 to something 1024.
如果您拥有大量用户,则可能会使系统最大数量的请求排队等待侦听套接字。如果您确定您的服务器可以处理负载,您可以从默认值128增加到1024。
And yes, increase the ulimit, so system can handle more load, but don't set to unlimited, just check what is enough to handle current load.
是的,增加ulimit,因此系统可以处理更多负载,但不设置为无限制,只需检查足以处理当前负载的内容。
Also go through this Increasing the maximum number of tcp/ip connections in linux will get some helpful info too
另外通过这个增加linux中tcp / ip连接的最大数量也会获得一些有用的信息
#2
0
This is probably not the ideal answer but using forever-service with nodemon will ensure your server restarts after it crashes.
这可能不是理想的答案,但使用nodemon的forever-service将确保服务器在崩溃后重新启动。
This is the command that worked for me. I'm including it because getting forever-service and nodemon to play well can be tricky.
这是对我有用的命令。我包括它因为永远服务和nodemon发挥得很好可能是棘手的。
It does the following: everytime a json or raml file in the applications dist/assets folder is modified, wait 10 seconds and then restart the node app (server.js script):
它执行以下操作:每次修改应用程序dist / assets文件夹中的json或raml文件时,等待10秒,然后重新启动节点应用程序(server.js脚本):
$ forever-service install raml --script server.js -f " -c nodemon" -o " --delay 10 --watch dist/assets -e json,raml --exitcrash" -e "PATH=/usr/local/bin:$PATH"
Then I can run:
然后我可以运行:
$ service raml start|stop|restart|status
I can also have the service start on server reboot with the chkconfig utility:
我还可以使用chkconfig实用程序在服务器重启时启动服务:
$ chkconfig --add raml
$ chkconfig raml on
#1
2
If you have large number of users most probably you are hitting systems maximum number of requests queued to listen socket. If you are sure your server can handle the load you can increase from default 128 to something 1024.
如果您拥有大量用户,则可能会使系统最大数量的请求排队等待侦听套接字。如果您确定您的服务器可以处理负载,您可以从默认值128增加到1024。
And yes, increase the ulimit, so system can handle more load, but don't set to unlimited, just check what is enough to handle current load.
是的,增加ulimit,因此系统可以处理更多负载,但不设置为无限制,只需检查足以处理当前负载的内容。
Also go through this Increasing the maximum number of tcp/ip connections in linux will get some helpful info too
另外通过这个增加linux中tcp / ip连接的最大数量也会获得一些有用的信息
#2
0
This is probably not the ideal answer but using forever-service with nodemon will ensure your server restarts after it crashes.
这可能不是理想的答案,但使用nodemon的forever-service将确保服务器在崩溃后重新启动。
This is the command that worked for me. I'm including it because getting forever-service and nodemon to play well can be tricky.
这是对我有用的命令。我包括它因为永远服务和nodemon发挥得很好可能是棘手的。
It does the following: everytime a json or raml file in the applications dist/assets folder is modified, wait 10 seconds and then restart the node app (server.js script):
它执行以下操作:每次修改应用程序dist / assets文件夹中的json或raml文件时,等待10秒,然后重新启动节点应用程序(server.js脚本):
$ forever-service install raml --script server.js -f " -c nodemon" -o " --delay 10 --watch dist/assets -e json,raml --exitcrash" -e "PATH=/usr/local/bin:$PATH"
Then I can run:
然后我可以运行:
$ service raml start|stop|restart|status
I can also have the service start on server reboot with the chkconfig utility:
我还可以使用chkconfig实用程序在服务器重启时启动服务:
$ chkconfig --add raml
$ chkconfig raml on