javascript – 使用Monit,Daemonized Node.js每60秒失败一次

SO的大师

我使用monit& amp;运行Node.js作为守护进程事实证明它在点上每60秒失败一次.这是我的monit.log

root@mybox:/etc/monit# tail -f /var/log/monit.log
[UTC Sep  4 12:07:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:08:50] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8000] via TCP
[UTC Sep  4 12:08:50] info     : 'nodejs' trying to restart
[UTC Sep  4 12:08:50] info     : 'nodejs' stop: /sbin/stop
[UTC Sep  4 12:08:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:09:50] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8000] via TCP
[UTC Sep  4 12:09:50] info     : 'nodejs' trying to restart
[UTC Sep  4 12:09:50] info     : 'nodejs' stop: /sbin/stop
[UTC Sep  4 12:09:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:10:50] info     : 'nodejs' connection succeeded to INET[127.0.0.1:8000] via TCP

这是monitrc的monit配置

set logfile /var/log/monit.log

check host nodejs with address 127.0.0.1
    start program = "/sbin/start nodeapp"
    stop program  = "/sbin/stop nodeapp"
    if failed port 8000 protocol HTTP
        request /
        with timeout 10 seconds
    then restart

我在这个配置中做错了什么或者是否有其他原因Node似乎经常失败?我还应该在哪里找出这个问题?

谢谢.

最佳答案 首先确保应用程序在多次请求后不会崩溃.一个好方法是使用ab(apache基准).如果您确定您的代码是稳定的,那么它可能是Monit的一个问题.

ab -c 10 -n 1000 http://127.0.0.1:8000/
点赞