Hello I'm doing a perl smtp sender that uses Parallel::ForkManager,Net::SMTP,MIME::Base64 and Authen::SASL and I have 30 smtp servers and send to 10 addresses simultaneously using splice.When I start the script all is fine but after some time,like 5 minutes or so,the script causes very high cpu loading even over 100%.I just want to know if there is a way around this.

My machine is "Debian GNU/Linux 4.0 \n \l" with two "model name : Genuine Intel(R) CPU 2140 @ 1.60GHz" and "2067452" RAM and my code is this :
#!/usr/bin/perl require MIME::Base64; require Authen::SASL; use Net::SMTP; use Parallel::ForkManager; print "From address->email@domain.com: "; $from = <>; chomp $from; print "From name->Name: "; $fromname = <>; chomp $fromname; print "Subject->This is a test: "; $subject = <>; chomp $subject; print "Mail file->mail.txt: "; $mail = <>; chomp $mail; print "Addresses file->addresses.txt: "; $addresses = <>; chomp $addresses; print "SMTP file->smtp.txt: "; $smtpfile = <>; chomp $smtpfile; print "Max parallel SMTP->30: "; $max = <>; chomp $max; print "Max addresses per SMTP->10: "; $maxaddresses = <>; chomp $maxaddresses; open(MAIL, $mail); @boday = <MAIL>; close(MAIL); $body = ""; foreach $pew (@boday) { $body.="$pew"; } open(my $y, "<", "$smtpfile") or die "$smtpfile: $!"; my @y = <$y>; close($y); chomp @y; open(INFO, $addresses); @addresses = <INFO>; close(INFO); $" = ","; chomp @addresses; $pm = new Parallel::ForkManager($max); foreach $target (@addresses) { chomp $target; @tenaddresses = splice(@addresses, 0, $maxaddresses); $index_y++; $index_y = 0 if($index_y > $#y); my $pid = $pm->start and next; my $value = "$_$y[$index_y]"; @info = split(/ /, $value); $server = $info[0]; $username = $info[1]; $pass = $info[2]; print "[+] Sending with $server to @tenaddresses | "; $connection = Net::SMTP->new($server, Timeout => 10, Debug => 0, ); if (!defined($connection) || !($connection)) { print ("Error at connecting. Skipping.\n"); } else { $connection->auth($username, $pass); $connection->mail($from); $connection->recipient(@tenaddresses); $connection->data; $connection->datasend("From: $fromname <$from>\r\n"); $connection->datasend("Content-Type: text/html \r\n"); $connection->datasend("Subject: $subject\r\n"); $connection->datasend("\r\n"); $connection->datasend("$body\r\n"); $connection->datasend("\r\n"); $connection->dataend(); $connection->quit; print ("Done.\n"); } $pm->finish; }

In reply to Net::SMTP High Cpu Load by susanbrown

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.