sendmails works, but opens 43 file handles per email -> problem


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users sendmails works, but opens 43 file handles per email -> problem
# 1  
Old 12-16-2010
sendmails 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:

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 bounce@yourdomain.com');
}

$output = shell_exec('lsof | wc -l');
echo "END: number of open files: $output";
?>

# 2  
Old 12-16-2010
Most of those open files are shared libraries. Some are config files.
Every time you execute a command like mailx -s 'subject' user@my.com < filename
you incur the overhead of loading the shared libraries, and config files.

The beauty of shared libraries is that they are usually memory resident, shared among all processes, so you can actually run several sendmail processes concurrently, and not really impact the system more than if you ran a single instance of it.

So, I must be missing something.

try
Code:
ldd sendmail

to see what I mean.
# 3  
Old 12-17-2010
Hi Jim,
thank you for the information.

> The beauty of shared libraries is that they are usually memory resident, shared among all processes

This is my understanding, too - otherwise lots of processes (not only sendmail) would crash every server. These are the libs used:

[root]# ldd /usr/lib/sendmail
libssl.so.6 => /lib64/libssl.so.6 (0x00002ab174bca000)
libcrypto.so.6 => /lib64/libcrypto.so.6 (0x00002ab174e16000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00002ab175167000)
libwrap.so.0 => /lib64/libwrap.so.0 (0x00002ab175380000)
libhesiod.so.0 => /usr/lib64/libhesiod.so.0 (0x00002ab175589000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00002ab17578d000)
libdb-4.3.so => /lib64/libdb-4.3.so (0x00002ab1759c6000)
libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x00002ab175cbc000)
libldap-2.3.so.0 => /usr/lib64/libldap-2.3.so.0 (0x00002ab175ed5000)
liblber-2.3.so.0 => /usr/lib64/liblber-2.3.so.0 (0x00002ab176110000)
libc.so.6 => /lib64/libc.so.6 (0x00002ab17631e000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00002ab176675000)
libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2 (0x00002ab17688b000)
libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x00002ab176ab9000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00002ab176d4e000)
libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3 (0x00002ab176f51000)
libdl.so.2 => /lib64/libdl.so.2 (0x00002ab177176000)
libz.so.1 => /usr/lib64/libz.so.1 (0x00002ab17737a000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00002ab17758f000)
/lib64/ld-linux-x86-64.so.2 (0x00002ab17465b000)
libkrb5support.so.0 => /usr/lib64/libkrb5support.so.0 (0x00002ab1777aa000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00002ab1779b2000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00002ab177bb5000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x00002ab177dcd000)


Sendmail is running:

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

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

Best,
Andreas
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to leak file handles

This is a strange one. We have an issue where our system is leaking SCTP file handles. There are people working on this and in the mean time we have a monitoring script that alarms when we need to perform actions to manually clear them. For testing purposes I want to write a script that... (0 Replies)
Discussion started by: RECrerar
0 Replies

2. UNIX for Advanced & Expert Users

How UNIX/AIX handles a file deep down, say it's being read while another one tries to rename it?

Hi Thinkers, On AIX 5.3, we have a monitor program that reads the log file and searching for a certain string pattern that we define(say "transactionException"), if it sees it then it will raise an alert by sending an email. Because the log file XXX.log is rolling into XXX.log.0, XXX.log.1,... (2 Replies)
Discussion started by: TheGunMan
2 Replies

3. OS X (Apple)

Programatically change which opens a file type

Hi there, If we have 2 apps on our customers machines that can both open files of a certain file extension, is there any way via shell commands to set which application should be the default? Essentially, I'm hoping to replicate Get Info > Open With > Change All, but using a script. Thanks... (0 Replies)
Discussion started by: davewg
0 Replies

4. Shell Programming and Scripting

Position to last line when vi opens a file.

Any Idea without entering any keystroke I can go to end of line in vi when I opening the file. When I am opening Vi I want to goto last line. when I give vi + filename it does not work. Any clue why it does not work. Thanks. (3 Replies)
Discussion started by: ekb
3 Replies

5. UNIX for Dummies Questions & Answers

Selectionbox, script which opens more than one file at once?

hello everybody I´m very new at shell and programming :eek: and i have the following question/problem: I need a script for framemaker (based on shell) which opens a new document from a template (.fm). Then imports a .doc file and then save it as a .mif. Actually my script works with one... (3 Replies)
Discussion started by: tio86
3 Replies

6. Shell Programming and Scripting

Monitor open file handles used by a process

We have a process that is running out of file handles. Is there some command line way to determine this that we can include into a cron script? Please let me know JAK (3 Replies)
Discussion started by: jakSun8
3 Replies

7. Shell Programming and Scripting

perl help with pipes and file handles (simple issue)

Hello, I have a program which opens a pipe for communication using file handle and forks 5 child processes. @waitlist = (1,2,3,4,5); foreach $item (@waitlist) { pipe *{$item},RETHAND; unless ($pid = fork()) { # Child process print RETHAND... (1 Reply)
Discussion started by: the_learner
1 Replies

8. Shell Programming and Scripting

SSH in batch mode and File-Handles in a loop

Hi all I try to execute SSH commands on several hosts in a while-loop. There seems to be a problem with file-handle, first cycle works correct but no other one will follow due to the while condition is false even that there are many more host entries (lines) in all_hosts.dat. ... (3 Replies)
Discussion started by: DaveCutler
3 Replies

9. UNIX for Advanced & Expert Users

File Handles

Hi, perhaps you can answer my question.....;) How can I check, how many file handles are used and how can i increase the value for maximum file handles??? (3 Replies)
Discussion started by: sjaeger
3 Replies
Login or Register to Ask a Question