LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 03-31-2005, 06:49 PM   #1
bmorel
LQ Newbie
 
Registered: Mar 2005
Location: Paris, France
Distribution: RHEL 3
Posts: 17

Rep: Reputation: 0
Mail command (much) faster than sendmail


Hello all,

I'd like to understand why "mail" command is much faster than sendmail.
Here's an example :

mail my@email.com < a_mail_body.txt : about 15 mS
sendmail -t < a_mail.txt : about 300 mS (20x slower!)

mail does use sendmail internaly, doesn't it ? If it does, how can it speed up sendmail this way ? What's its secret?

I tried several sendmail options to speed it up, nothing works. (min 150mS using option -O DeliveryMode=q, which is not what I want !)

My aim is to speed up php's mail() function, which only delivers 3 emails/second using sendmail command.

Any clues ?

Thanks in advance
Ben
 
Old 04-01-2005, 04:27 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,047

Rep: Reputation: 95
Where does sendmail send to?

You'll find, Mail puts in in the sendmail queue '/var/mail/queue' (?)
and sendmail sends it later.

Whereas direct sendmail does it NOW

try 'sendmail -bp' to look at the queue after Mail.
 
Old 04-01-2005, 04:50 AM   #3
bmorel
LQ Newbie
 
Registered: Mar 2005
Location: Paris, France
Distribution: RHEL 3
Posts: 17

Original Poster
Rep: Reputation: 0
Lightbulb

Ok thank you for this answer, this explains a little bit why i'ts faster !
But then :

- Why does "sendmail -O DeliveryMode=q" is still 10x slower than "mail" ?
- Why does an e-mail sent with "mail" seem to be delivered very quickly ? Which process then tells sendmail to procede with the mail queue ?

Does someone have an url for in-details explanations of the "mail" command ?

Thanks in advance
Ben
 
Old 04-01-2005, 06:39 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,047

Rep: Reputation: 95
could it be this?

http://www.sendmail.org/tips/private-dns/
 
Old 04-01-2005, 08:13 AM   #5
bmorel
LQ Newbie
 
Registered: Mar 2005
Location: Paris, France
Distribution: RHEL 3
Posts: 17

Original Poster
Rep: Reputation: 0
Hm thanks for the link but I don't think it's the problem here.
My server seems to be properly configurated (working successfully for more than 1 year), and if I ask sendmail to "queue only", it should not try to reverse dns's

I'm really interested in knowing how "mail" works internally. Is its source code easily available ? And where can I find it ?

Thanks
Ben
 
Old 04-01-2005, 09:01 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,047

Rep: Reputation: 95
google of course
 
Old 04-01-2005, 05:41 PM   #7
bmorel
LQ Newbie
 
Registered: Mar 2005
Location: Paris, France
Distribution: RHEL 3
Posts: 17

Original Poster
Rep: Reputation: 0
After a couple of hours I finally found why !
I saw in the source code that mail (mailx is the real name of the package) fork()s itself to run multiple instances of sendmail simultaneously using multithreading !

That's why it's so fast :
- Program forks
- Child executes sendmail
- Parent exits
- sendmails are executed in background

Note: the mails are not simply queued, sendmail tries to deliver them directly !

Ben
 
Old 04-02-2005, 05:57 PM   #8
bmorel
LQ Newbie
 
Registered: Mar 2005
Location: Paris, France
Distribution: RHEL 3
Posts: 17

Original Poster
Rep: Reputation: 0
Hello again

My problem now is that I need to make sendmail command work in the background when calling it from php
(In order not to wait 300mS for each mail when I need to send 20 mails: my web user cannot wait 6 seconds for the page to load)

Unfortunately, multitasking in PHP is not powerful enough for the moment (I don't want to waste resources with a pcntl_fork() on a long program)

So the problem is that I can't right now make sendmail run in the background (with the & at the end of the command line) and pipe it some data.
Because the & makes it work at once in the background, not waiting for stdin.

I mean, this solution doesn't work : popen("/usr/sbin/sendmail -t -i &");
If I fwrite to this pointer, it's too late, sendmail has already gone into the background.

The only solution I found for the moment is to use a sendmail_fork command that I quickly wrote :

==============================================================
#include <stdio.h>
#define SENDMAIL_PATH "/usr/sbin/sendmail"

int main(int argc, char *argv[])
{
char buf[1024];
int i;
int pid;
FILE* p;
strcpy(buf, SENDMAIL_PATH);
for (i=1; i<argc; i++) {
strcat(buf, " ");
strcat(buf, argv[i]);
}
p = popen(buf, "w");
while ((i=fgetc(stdin)) != EOF) {
fputc(i, p);
}

pid = fork();

switch (pid) {
case -1:
printf("fork() error.\n");
return 1;
case 0:
pclose(p);
}

return 0;
}
==============================================================

This program, once compiled, can replace sendmail command.
This is of course a temporary solution.
Is there a good tip to make a program run in the background AFTER all the pipe is received ??

Thanks
Ben
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sendmail error Fetching mail could not lock /var/spool/mail/username sukhdev50 Linux - Networking 0 05-04-2005 03:41 AM
How can I use the Mail command with Sendmail Options Kalar Linux - Newbie 1 07-16-2004 10:35 PM
How to make Sendmail forward all incoming mail to localhost port 26 (Domino mail) speedgelb Linux - Software 2 04-04-2004 04:41 PM
sendmail: Routing dead mail to a shell command? noisybastard Linux - Networking 1 10-05-2003 04:13 PM
Is it possible to force Sendmail to deliver 'faster'? gboutwel Linux - Networking 1 05-25-2001 05:21 PM


All times are GMT -5. The time now is 03:20 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration