i stand absolutely corrected. i guess i am showing the
fact that some of the things i learned are no longer quite
as accurate as they were when i picked them up :) so, i
wrote a bit of code to test this out: #!/usr/bin/perl -w
use strict;
use IO::Socket;
use Benchmark;
my $to_mail_addy = "junk\@????????.net";
my $from_mail_addy = "junk\@????????.net";
my $mailhost = "localhost";
sub with_pipe {
open(SENDMAIL, "|/usr/sbin/sendmail") or die "cannot open sendmail"
+;
print SENDMAIL "To: $to_mail_addy\n";
print SENDMAIL "From: $from_mail_addy\n";
print SENDMAIL "Subject: A speed test...\n";
print SENDMAIL "Content-type: text/plain \n\n";
print SENDMAIL "Blah blah blah... this is my content...";
close(SENDMAIL);
}
sub with_socket {
my $sock = new IO::Socket::INET(PeerAddr => 'localhost',
PeerPort => 25,
Proto => 'tcp');
die "unable to create $sock" unless defined $sock;
print $sock "Hello arino.net\n";
print $sock "MAIL FROM: $from_mail_addy\n";
print $sock "RCPT TO: $to_mail_addy\n";
print $sock "DATA\n";
print $sock "Subject: A speed test...\n";
print $sock "Blah blah blah... this is my content...";
print $sock ".\n";
print $sock "quit\n";
close($sock);
}
timethese (1000, {"WITH PIPES" => \&with_pipe,
"WITH SOCKET" => \&with_socket });
[ed@darkness ed]$ perl speedtest.pl
Benchmark: timing 1000 iterations of WITH PIPES, WITH SOCKET...
WITH PIPES: 22 wallclock secs ( 0.26 usr 0.68 sys + 6.95 cusr 4.93
+csys = 12.82 CPU) @ 1063.83/s (n=1000)
WITH SOCKET: 17 wallclock secs ( 1.76 usr + 1.13 sys = 2.89 CPU) @ 3
+46.02/s (n=1000)
so we see that sockets ARE much faster than pipes, which
to me was counter intuitive... I guess they really have
optimized the bejeezus out of the TCP stack... time to
have a little chat with my networking professor :)
UPDATE: out of curiosity, people have asked what
the system specs were like on the machine i ran the
tests on:
| Processor |
Pentium II (Deschutes) 348.491034 Mhz |
| RAM |
Memtotal - 193060 kB
MemFree - 20864 kB |
| OS |
Linux 2.2.13 i686 (redhat) |
|