Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Net::SMTP v local MTA

by cLive ;-) (Prior)
on Jan 12, 2002 at 01:19 UTC ( #138142=perlquestion: print w/replies, xml ) Need Help??

cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, In my evergoing quest to make my CGI scripts cross platform, I've moved the e-mail sending subs over to Net::SMTP (I used to use just sendmail, but the NT people weren't very happy :).

In testing though, I notice that there is a significant difference in performance when sending using Net::SMTP over piping to Sendmail. I assume this is because piping to Sendmail just puts the message in the mail queue, whereas Net::SMTP actually physically sends the mail.

So, my question is, to avoid the overhead:

  • should I fork the sending? (up to 3 e-mails get sent per script execution though)
  • should I create a local queue and an 'every 5 minutes cron job' to parse the queue and send?
  • or has some else found a better way of dealing with cross platform mailers?

Input, as always, humbly welcomed.

cLive ;-)

ps - IANAL (I Am Not A Laccolith)

Replies are listed 'Best First'.
Re: Net::SMTP v local MTA
by lhoward (Vicar) on Jan 12, 2002 at 02:31 UTC
    I've done a good bit of benchmarking of Net::SMTP vs other methods for sending mail, and have found that Net::SMTP (or another SMTP transporter) is almost always the winner. But you can do some things in SMTP that would hurt performance. A few things that could be effecting you:
    • SMTP connections - it is best when using SMTP to establish one connection to the mailer and then pipe multiple messages across this connection. This may not be an option if you are sending only a single message with your CGI.
    • reverse DNS - if your mail server is doing reverse-DNS lookups on each connection that could also slow down your aparent throughput when using Net::SMTP
Re: Net::SMTP v local MTA
by hossman (Prior) on Jan 12, 2002 at 02:58 UTC
    The other 2 posters have touched on this, but just to be explicit:

    • There only reason why Net::SMTP would be (more then negligably) slower then using /foo/bin/sendmail directly is if you are connecting to an SMTP host on a remote machine. In which case the lag is either in the network, or on the remote SMTP host.
    • Net::SMTP determines the default SMTP host based on Net::Config, which is set at installation time.
    • You can override the default SMTP host in the constructor for Net::SMTP
    • Assuming you construct your Net::SMTP object using "localhost" as the SMTP host, you probably shouldn't see any noticable performance difference between if and /foo/bin/sendmail
Re: Net::SMTP v local MTA
by gav^ (Curate) on Jan 12, 2002 at 02:36 UTC
    I prefer Mail::Sendmail over Net::SMTP as it makes things even simpler, but using Net::SMTP allows you to hold the connection open and send all 3 in one go.

    If you are running a SMTP server on localhost you shouldn't have a problem with speed. I have a CGI script that sends up to 10 in one go which runs fine. If I was, I'd either fork (if I didn't care about NT) or spool locally.

    Of course there are other options, I've handled this before by having a flag in the DB that says 'email this user X' and a cron job that handles it.

    Hope this helps...

      localhost - the word hits me like a wet fish.

      Yes, I moved the script to my live server. No I didn't update the host in $smtp->mail(HOST) line.

      That would also explain why my messages were getting rejected...

      d'oh, d'oh, d'oh.

      I think I'll just keep sending them live for now...

      cLive ;-)

      /me giggles manically at his own stupidity

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://138142]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-11-26 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?