Helpful Docs to read before posting: (All Docs) | Config Docs | General FAQ | Mailing List Sending FAQ | Error FAQ

mail.cgi maxes cpu

How do I fix...

mail.cgi maxes cpu

Postby mdegive » Thu Apr 22, 2010 8:16 am

Our hosting company is complaining that mail.cgi is often maxing the cpu, see their email below:

>>When I ran lsof on the mail.cgi process the path for this script was indeed in /home/markusle/public_html/cgi-bin/dada. The script was running multiple times at 90% - 100% CPU:
11740 markusle 25 0 100 232:51.08 0.8 19456 16m 2068 R /usr/bin/perl -McPanelUserConfig mail.cgi
20235 markusle 25 0 100 221:08.48 0.8 19468 16m 2068 R /usr/bin/perl -McPanelUserConfig mail.cgi
26328 markusle 25 0 99 229:52.87 0.8 19468 16m 2068 R /usr/bin/perl -McPanelUserConfig mail.cgi
13827 markusle 25 0 99 218:05.56 0.8 19456 16m 2068 R /usr/bin/perl -McPanelUserConfig mail.cgi
25729 markusle 25 0 99 213:47.08 0.8 19468 16m 2068 R /usr/bin/perl -McPanelUserConfig mail.cgi
19623 markusle 25 0 99 210:49.47 0.8 19464 16m 2068 R /usr/bin/perl -McPanelUserConfig mail.cgi

You will want to review the script and if possible limit the amount of processes spawned by this script<<

What is causing this and is there a way to make sure it does not use that much cpu?

Thank You.

Michel
mdegive
 
Posts: 29
Joined: Tue Apr 29, 2008 7:32 am

Re: mail.cgi maxes cpu

Postby justin » Thu Apr 22, 2010 10:40 am

What version of Dada Mail are you using?


Not sure what would cause this - except having multiple mailings happening at once. Each mailing will have a separate process associated with it.
User avatar
justin
 
Posts: 5451
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: mail.cgi maxes cpu

Postby mdegive » Mon Apr 26, 2010 10:28 am

We have version 4 pro.

We have over 20 mailing lists so it possible to have more than one running at the same time.

We use the discussion list feature but I thought dada_bridge handled those. I have 2 cron jobs that run every 15 minutes:

/usr/bin/curl -s --get --data run=1\;passcode=\;verbose=1 --url http://www.....com/cgi-bin/dada/plugins/dada_bridge.pl
/usr/bin/curl http://www.....com/cgi-bin/dada/extensi ... _pickup.pl

so why mail.cgi?

and how can we prevent mail.cgi from bogging down the cpu?
mdegive
 
Posts: 29
Joined: Tue Apr 29, 2008 7:32 am

Re: mail.cgi maxes cpu

Postby justin » Mon Apr 26, 2010 11:10 am

Whew - 20 mailing lsits. That could be it :)

I've had problems in the past with web spiders spidering the archives and just going ape... stuff... with that.

So, you could just disable the archives in some of your lists.

The other option is to just have a script that sets a limit on how many copies of the mail.cgi can run at once. There is some setup to this, but:

Rename your mail.cgi script to: "mail.pm"


and save the below script:

Code: Select all
#!/usr/bin/perl

# A weird fix.
BEGIN {
   if($] > 5.008){
      require Errno;
      require Config;
   }
}





use lib qw(
            ./
            ./DADA
            ./DADA/perllib
);

use CGI::Carp qw(fatalsToBrowser);

$ENV{PATH} = "/bin:/usr/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

use Fcntl qw(:DEFAULT :flock   O_WRONLY   O_TRUNC      O_CREAT      );

my $State = '/home/youraccount/.dada_files/.tmp/counter.txt';


   $State = make_safer_per($State);
   
my $Limit = 25;

main_f();


sub main_f {


   plus();

   if(poll() >= $Limit){
   
      print "Status: 503 Service Unavailable\r\nContent-Type: text/html; charset=ISO-8859-1\r\r";

   }else{

      do(make_safer_per('mail.pm'));

   }
   
   minus();

   return;

}


sub poll {

   sysopen(FH, $State, O_RDWR|O_CREAT)                         or die "can't open counter: $!";
    flock(FH, LOCK_EX)                                          or die "can't flock counter: $!";
    my $num = <FH> || 0;
    close FH                                                 or die "can't close counter: $!";
   
       $num =~ s/^\s+//o;
      $num =~ s/\s+$//o;
      
      return $num;
      
}


sub minus {

   sysopen(FH, $State, O_RDWR|O_CREAT)                         or die "can't open counter: $!";
    flock(FH, LOCK_EX)                                          or die "can't flock counter: $!";
    my $num = <FH> || 0;
    seek(FH, 0, 0)                                              or die "can't rewind counter: $!";
    truncate(FH, 0)                                          or die "can't truncate counter: $!";
    (print FH $num-1, "\n")                                      or die "can't write counter: $!";
    close FH                                                 or die "can't close counter: $!";
   
}




sub plus {
      
   sysopen(FH, $State, O_RDWR|O_CREAT)                         or die "can't open counter: $!";
    flock(FH, LOCK_EX)                                          or die "can't flock counter: $!";
    my $num = <FH> || 0;
    seek(FH, 0, 0)                                              or die "can't rewind counter: $!";
    truncate(FH, 0)                                          or die "can't truncate counter: $!";
    (print FH $num+1, "\n")                                      or die "can't write counter: $!";
    close FH                                                 or die "can't close counter: $!";
   
}




sub make_safer_per {

   my $string = shift || undef;
   
   if($string){
      $string =~ tr/\0-\037\177-\377//d;    # remove unprintables
      $string =~ s/(['\\])/\$1/g;           # escape quote, backslash
      $string =~ m/(.*)/;
   return $1;
   }else{
      return 0;
   }

}





as, "mail.cgi". upload it to your server, change the permission to 755.

You will need to make the following changes in the script:

Code: Select all
my $State = '/home/youraccount/.dada_files/.tmp/counter.txt';



You'll need to change this to the absolute path to some file ( you do not have to make this file, already). I kind of suggest doing what I'm doing - using the advanced installation, and putting the path into your, ".tmp" directory and calling the file, "counter.txt" .

Then, you can optionally set the other variable:

Code: Select all
 my $Limit = 25;


This sets how many copies of Dada Mail you'd allow to run. It's set at 25 - you can set it less.

If that all works, there you go - you won't get a huge amount of processes running at once.

The only other thing - to be prudent, would be to set a cronjob - something like this:

Code: Select all
0 * * * * rm /home/youraccount/.dada_files/.tmp/counter.txt


This will remove (delete) that counter file every hour - should stop the script from getting sort of a dead lock.

Make sure to get this path right - it *will* remove something and you don't want the wrong thing to be removed!
User avatar
justin
 
Posts: 5451
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: mail.cgi maxes cpu

Postby mdegive » Tue Apr 27, 2010 7:57 am

I created the new mail.cgi script and renamed the old one to mail.pl. Sent an email and it all seems to work like before except that now I can't get in the web interface: http://www.backdraft-technologies.com/c ... avor=admin, I get 500 Server Error, and there are no errors in the log?
mdegive
 
Posts: 29
Joined: Tue Apr 29, 2008 7:32 am

Re: mail.cgi maxes cpu

Postby justin » Tue Apr 27, 2010 3:12 pm

I created the new mail.cgi script and renamed the old one to mail.pl. Sent an email and it all seems to work like before except that now I can't get in the web interface: http://www.backdraft-technologies.com/c ... avor=admin, I get 500 Server Error, and there are no errors in the log?


That's not what I said to do, at all. You just made a blank file for the, "mail.cgi" file. That's not going to work.

Mailing is working, because it's handled via the dada/plugins/dada_bridge.pl script, and not Dada Mail.
User avatar
justin
 
Posts: 5451
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: mail.cgi maxes cpu

Postby mdegive » Mon May 03, 2010 10:14 am

Jsutin,

I think we are mis-comunicating here:

You said rename mail.cgi to mail. pl, I did.

You said to create a new mail.cgi with the script you provided, I did.

Michel
mdegive
 
Posts: 29
Joined: Tue Apr 29, 2008 7:32 am

Re: mail.cgi maxes cpu

Postby justin » Mon May 03, 2010 2:49 pm

Here's what I said:

Rename your mail.cgi script to: "mail.pm"


mail.pm - not mail.pl - could have made all the difference,
User avatar
justin
 
Posts: 5451
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Re: mail.cgi maxes cpu

Postby mdegive » Thu May 06, 2010 7:03 am

sorry, I had missed that.

Ok, so now my mail.pm is there and I set the perms to 755, and I still get error 500 with nothing in the log, now what?
mdegive
 
Posts: 29
Joined: Tue Apr 29, 2008 7:32 am

Re: mail.cgi maxes cpu

Postby justin » Thu May 06, 2010 4:49 pm

Have you made the necessary changes I outlined?
User avatar
justin
 
Posts: 5451
Joined: Wed Feb 13, 2008 8:41 pm
Location: Denver, CO

Next

Return to Errors While Running Dada Mail

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Loading