in reply to RE: RE: RE: eof without closing the pipe
in thread eof without closing the pipe

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)

Replies are listed 'Best First'.
Problem with that benchmark
by gryng (Hermit) on Jun 30, 2000 at 18:51 UTC
    Eduardo, as we mentioned in the Chatterbox, I think the problem with this benchmark lies with process creation, not TCP vs. PIPEs. With your PIPE code, you are spawning a new process of sendmail each time, however with your TCP code, sendmail is already running.

    Additionally, I have a test case on my computer at home (which I cannot get to easily at the moment), with a GO client/server program. Before I separated the two programs, the run time was about 25 seconds, full CPU usage. Once I moved to TCP my run time jumped to almost 2 minutes with CPU never topping over 30-40%. Changing my code once more to use UNIX sockets, I regained full CPU usage and an average run time of 29 seconds. I did not implement a PIPE solution, but I believe UNIX sockets are implemented as a PIPE so the number should between 25-29 seconds if I did, no? :)

    Anyway I just wanted to post officially something before everyone ran off making all there PIPE'd programs TCP! :)

    Ciao,
    Gryn

    (p.s. By GO client/server I mean the board game GO, the server sends a 19x19 text array to the client and the client responds back with a move in this case two random numbers. in the test cases mentioned above this was repeated for about 1,000 moves)