简体   繁体   中英

Why npm package pm2 fails to restart when CPU utilization reaches 80%?

Pm2 fails to restart when CPU Utilization reaches 80%. I noticed that this mostly happens when I send mail.

Do you think this problem is related to a memory leak or nodemailer?

Here I have added my code.

var smtpTransport = nodeMailer.createTransport({ host: 'myhostname', port: 465, secure:true, tls:{ rejectUnauthorized:false }, auth: { user: <>, pass: <> } })

var mailOptions = {

          from:       <<email>>,
          to:   <<email>>,
          subject:  '<<my text>>',
          html:     <<text>>
        };

        smtpTransport.sendMail(mailOptions, function(err,res){

            if(err)
            {
                console.log(err);
            }else{
                console.log(res.response);
            }
        });

Pm2 does not restart your application when it reaches high CPU, you can only specify a memory limit at which Pm2 will restart your app, as specified in the Docs http://pm2.keymetrics.io/docs/usage/memory-limit/ .

That being said crashing your server when it reaches a high CPU usage caused by executing a workload is not the way to go.

When your server reaches 80% of its capacity it either means that you have unoptimized code/leaks or you need to scale.

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