LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-16-2010, 05:32 AM   #1
ZX81
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
sendmail works, but opens 43 file handles per email -> problem


I'm using Sendmail 8.13.8 on a CentOS 5.5 vServer (Virtuozzo).

I'm using a loop in PHP to send a lot of HTML-mails via sendmail. Each mail is a mail with individual statistics for our users, so its not mass mailing, bcc is not an option.

It all works fine, but when I take a closer look there is a problem heading our way with a high number of mails:

For each mail sendmail opens up 43 files. Sometimes these open files get closed again very fast, sometimes not.

Here is an example using the PHP-script below, it sends 20 mails in a loop:


[root]# php test-mail.php
START: number of open files: 2113
END: number of open files: 2973


This is the worst case. The number of open files (lsof | wc -l) used to send the 20 mails is 860 => 43 open files per mail.

Sometimes the files are closed very fast, so I get results like this, too:


[root]# php test-mail.php
START: number of open files: 2113
END: number of open files: 2242


This shows 129 (3 * 43) open files, so the open files for 17 send mails are already closed, for 3 mails the 129 files are still open.

In the worst case and with lots of mails our server crashes, the numfile limit of 8192 in user_beancounters is reached (our ISP won't give us more than 8192).

Sendmail DeliveryMode is background.

Could it be that sendmail tries to send lots ob mails asyncronously and uses 43 open files for each? I'm only depending on sendmail to deliver the mails, normaly I wouldn't dare to touch the sendmail config (like 'if you don't know what you're doing, don't!').

Any ideas?

BTW: It is not a problem of PHP. I verified this by sending mails via SMTP localhost to sendmail (opened 43 files per mail) and sending mails via SMTP to an ISP-relay (did not open any files per mail).

Thank you very much for reading this,
best,
Andreas


This is the code for test-mail.php:

PHP Code:
<?php
$output 
shell_exec('lsof | wc -l');
echo 
"START: number of open files: $output";

// HTML message
$msg '<html><head><title>Test mail</title></head><body><p>Mailbody</p></body></html>';

// Set 'Content-type'-header
$header  'MIME-Version: 1.0' "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

for(
$i=0$i<20$i++) {
    
// send mail, this opens up 43 files for each
    
mail('you@yourdomain.com''Testmail '.$i$msg$header'-f [email]bounce@yourdomain.com[/email]');
}

$output shell_exec('lsof | wc -l');
echo 
"END: number of open files: $output";
?>
 
Old 12-17-2010, 06:56 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608
Quote:
Originally Posted by ZX81 View Post
Code:
$output = shell_exec('lsof | wc -l');
Running 'lsof' without switches is slow: add "-Pwln" to combat that.

More importantly it selects all processes the user can see. For example running '/usr/sbin/lsof | wc -l' from an unprivileged account without any foreground or background processes already returns 512 lines. Confining output by user name with '/usr/sbin/lsof -Pwnlu $LOGNAME' OTOH returns 53 lines and '/usr/sbin/lsof -Pwnlu $LOGNAME | egrep -v "(^lsof|^egrep)"' just 24 (note you can't avoid grep running '/usr/sbin/lsof -Pwnlu $LOGNAME -p ^"$(pgrep -f /usr/sbin/lsof)";'). But even then lsof will list all resources including network sockets, terminals and libraries that may be shared among concurrent processes. On top of that I do not see you continually measure and display failcnt of numfile for sendmail PIDs in /proc/user_beancounters so your current counter approach itself could be better.

Since your ISP does not allow your VPS to have numfile > 8192 you should take into account what sendmail needs to do to send an email. Apart from files opened during checks performed on mail submission, once email gets queued for immediate delivery host names need to be resolved and remote MTAs contacted before its able to actually send the message. Caching all possible lookups (nscd, caching name server) makes sense. Slowing down mail submission may make sense too. Additionally you could set up sendmail with a separate queue in which emails only get spooled and run a separate queue runner at reasonable intervals separating mail submission and mail transfer.
 
Old 12-17-2010, 07:36 AM   #3
ZX81
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Hi,

thank you very much for your time.

Quote:
On top of that I do not see you continually measure and display failcnt of numfile for sendmail PIDs in /proc/user_beancounters so your current counter approach itself could be better.
During my tests the failncnt is zero:

numfile 1734 1736 8192 8192 0

Sendmail is running smoothly:

root 28089 0.0 0.0 62812 2320 ? Ss Dec10 0:33 sendmail: accepting connections
smmsp 28097 0.0 0.0 57692 1780 ? Ss Dec10 0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue


But still every mail opens 43 files when send - not for long, but for too long when the server is handling some load, adding up to too many open files.

Do you think setting the sendmail DeliveryMode to 'interactice' would help? I read the sendmail documentation regarding this, but I'm still not sure what risks it would involve.

Best,
Andreas
 
Old 12-17-2010, 07:37 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608
Risks are outlined in http://www.sendmail.org/~ca/email/doc8.12/TUNING
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kernel file handles vs userspace file handles. jiml8 Programming 7 05-13-2008 06:32 PM
sendmail : How to email contents of a text file? concoran Linux - Newbie 5 03-09-2008 08:27 PM
email link in firefox opens wrong email client wabbalee Linux - Software 3 11-26-2006 04:41 AM
Not Enough File Handles Jaqflash Mandriva 4 03-08-2005 05:30 PM
Sendmail: How do I config to write separate file for every email 360 Linux - Software 4 03-31-2003 08:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration