benchmark your server (Mail Function)

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

benchmark your server (Mail Function)

Post by malcolmboston »

hi guys

i came up with this test last night after finally getting my local mail server working again :@

basically it tests how long it takes your server to send 100 e-mails and then calculates how long it would take to send various amounts, including 1000, 50,000, 1 million and even a billion amongst many others.

you only need to change the variable $email to your own e-mail server

I didnt develop this script to test how many e-mails i could send at once in a 'real-world' environment as i have absolutely no need to send more than say 100 at a time maximium, not in an of my current projects mind, i just wanted to try and emulate the sorts of volume that major mail providers must send all the time (msn, yahoo etc) and mainly to test just how fast my PHP server could cope with such volumes and scripts

i initially ran the script with 50,000 emails to myself, needless to say PHP died a horrible death calling out of memory, so i lowered the number and decided to calculate from there, also this made it easier to share my script with others to benchmark

i chose 100 mainly to get a fairly accurate score however its still a little inconsistent but very fun to see how many a billion e-mails would take to send, :D

i decided to wrap the majority of the code in some functions, after initially doing it without them, but it got too complex, which is my first time of using functions and im definitely going to be using them in the future, also it was the first use if ever needed for an else/if statement it actually added
an extra 18 lines of code to the script, but made is so much easier to 'administer'!

this script works without any database and was created using PHP 4.2.2 with only the GD Module as a non-standard package (which it doesnt use)

how did your server do?
the script is here for download

if any of you are worried about the sudden influx of 100 e-mails hitting your mailbox, dont worry, the total file size for all 100 is only 65kb, plus you could always set up that e-mail address as junkmail, it will still get there and wont harm the script at all

there is only one problem with this script which i am unaware of how to format
say you get a return of 16.14 Minutes, this does not mean 16 Minutes and 14 Seconds it means .14 of a minute so 16 minutes and around 8 seconds, just so you know, seconds work perfectly if anyone can advise me on how to change this it'd be appreciated

Please post your results here so we can all compare and hopefully find ways of running our servers at optimium performance

also i could of further improved the script by doing something like the following

Code: Select all

// pseudo code
mail("$email", "$subject", "$message", "$headers") * 100;
// but this wont work
// i believe i would need to create a loop statement, but
// am unsure on the syntax of this sort of thing as ive only worked
//  with queries - so bech if your reading
instead of

Code: Select all

mail("$email", "$subject", "$message", "$headers");
mail("$email", "$subject", "$message", "$headers"); 
mail("$email", "$subject", "$message", "$headers"); 
mail("$email", "$subject", "$message", "$headers"); 
// etc etc
lines of code(inc. comments):297
of which are mail functionality:100
and defining functions:82

Thanks
Mal
Last edited by malcolmboston on Wed Mar 24, 2004 2:17 pm, edited 3 times in total.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

my results
100 == 7.38 seconds.
500 == 36.90 Seconds
1k == 73.8 Seconds
5k == 6.15 Minutes
20k == 24.60 Minutes
50k == 61.50 Minutes
500k == 10.25 Hours
1m == 20.50 Hours
10m == 8.54 Days
500m == 13.78 Months
1bn == 27.55 Months

my hardware profile
- CPU and Speed => P4 1.6ghz :(
- Ram => 256 DDR 233mhz :(
- OS Windows 2000 w/service pack 4
- PHP Version => 4.2.2
- Test Server => localhost
- Mailbox => localhost

tonight i will test it on linux (RH9 'shrike') with an unmodified kernel, and left as is from when it was released (boxed) just to see what the sendmail feature is like on that, as most hosting is from linux machines and namely RH
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

For sending the 100 emails:

Code: Select all

$emailnum = 100; //number of emails
for($i=0;$i<$emailnum;$i++){
  mail("$email", "$subject", "$message", "$headers"); 
}
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ah cool

im assuming that works for most thing and now only mail

thank you very much sk8r, ill be sure to be using that alot in the future

Mal
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

This is be a fantastic idea for benchmarking your server, and could be one of a million things that we could test.

We could test the performance of making jpegs, opening and closing files on a local machine, connecting and disconnecting from MySQL, etc.

Smart. :)
Image Image
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

:D

post your results man!

ill do a GD test tonight
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Not that you would EVER send even more than 100 emails in a loop. You would open a socket to do it.

Mark
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

100 16.74 seconds.
500 83.70 Seconds
1000 167.40 Seconds
5000 13.95 Minutes
20000 55.80 Minutes
50000 139.50 Minutes
500000 23.25 Hours
1000000 46.50 Hours
10000000 19.38 Days
500000000 31.25 Months
1000000000 5.21 Years
Shared hosting (Gold Plan) at AkiraWeb.com
Image Image
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Bech100 wrote:Not that you would EVER send even more than 100 emails in a loop. You would open a socket to do it.

Mark
That's assuming we know how to do that. 8)
Image Image
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

and assuming we would want to do that

i used it to just test how my server could perform
(btw i dont know how to either, and probably will never want to or need to)

not to produce a spam program
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

malcolmboston wrote:(btw i dont know how to either, and probably will never want to or need to)
Same here.
Image Image
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

My own version:

Code: Select all

<?PHP
$email = "name@localhost";
$title = "test";
$body = "Testing...";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
function getmicrotime()
{
   list($usec, $sec) = explode(" ", microtime());
   return ((float)$usec + (float)$sec);
}
$start = getmicrotime();
for($i=0;$i<100;$i++){
    mail($email, $subject, $message, $headers);
}
$end = getmicrotime();
$time = $end - $start;
echo "Took " . $time . " seconds";
?>
Can't test it though, I don't have mail set up on my computer..
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Quicker ;) :

Code: Select all

<?php 
function getmicrotime() 
{ 
   list($usec, $sec) = explode(" ", microtime()); 
   return ((float)$usec + (float)$sec); 
} 
$start = getmicrotime(); 

$email = "name@localhost"; 
$title = "test"; 
$body = "Testing..."; 
$headers = "MIME-Version: 1.0\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
for($i=0;$i<100;$i++){ 
    mail($email, $subject, $message, $headers); 
} 

echo "Took " . (getmicrotime() - $start) . " seconds"; 
?>
Image Image
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

nice job :? missing some of my features?

it was my first time working with functions so gotta expect some bloat :cry:

but nice job mofo! :P
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Check this out:
http://64.223.172.54:12/mailtest.php

Thats the test (using exponentials instead of mail):

Code: Select all

function raise($num, $exp){
    $value = 1;
    for($i=0;$i<$exp;$i++){
        $value = $value * $num;
    }
    return $value;
}
$start = getmicrotime();
for($i=0;$i<1000;$i++){
    $array[$i] = raise($i,$i);
}
$end = getmicrotime();
I didn't know PHP had an infinite value :P
Post Reply