Reputation: 49
I'm new to node.js and am building out services using restify, mongoose and mongodb. One of the services I'm building requires an email to be sent and does not require the consumer of the service to be informed of the send status of the email. I created the code using below as a test and it's working the way I want but I want to ensure there are no potential issues that I'm not seeing. My concern is that if this service is invoked 1,000 times within a short duration and the email is sending somewhat slowly (1-3 seconds each) then will this cause performance degradation on my node server? I'm not sure how these items are queued internally and if there is a limit to try to stay under. I assume process.nextTick essentially queues items for execution but is there a limit to the number of items before you start to overwhelm node's event loop? Here is my test code:
var sendUsingTemplate = function(template, mergeData) {
console.log('emailManager.sendUsingTemplate starting...');
console.log('template: ' + template);
console.log('mergeData: ' + mergeData);
process.nextTick(function(){
console.log('setting up async code in here...');
setTimeout(function() {
console.log('ok done with async!');
}, 10000);
});
};
Upvotes: 0
Views: 3176
Reputation: 203519
Since sending e-mail is essentially an I/O-based operation, I don't think you need process.nextTick
(because I/O is handles pretty well by Node anyway).
However, I would suggest you use a local MTA (Mail Transfer Agent) that will take on the part of actually sending the e-mail (the SMTP-part). In that setup, Node will send the mail to the local MTA (which is a fast operation), and the MTA will start delivering those e-mails. An MTA will also usually take care of queuing mail when a receiving mailserver is offline or is temporarily rejecting incoming messages.
nodemailer can be configured to use SMTP to deliver e-mail, or to hand them off to sendmail (which is the transport you should use); node-email only hands e-mail off to sendmail. In both cases, sendmail
can also be another MTA like Exim or Postfix, which provide a sendmail-compatible interface.
Upvotes: 2