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

now, maybe i am mistaken... however, opening up a socket connection, no matter how simple, should be MARKEDLY slower than opening up a pipe, no matter what the situation. If you are opening up a socket to a host you have to deal with: however, if you are opening up a pipe, to a process on the local machine then the situation is: if speed is your constraint, and you are attempting to maximize the throughput (here being messages per minute) I can not conceive of a way faster than communicating directly with sendmail through a pipe.

UPDATE: thanks to lhoward i have now learned that in modern operating systems, much to my suprise, the TCP subsystem has been optimized WAY better than I ever thought it would be, so, my entire coment above, should be disreguarded and i should be flogged for not having benchmarked in the first place :) keep the learning coming...

Replies are listed 'Best First'.
RE: RE: RE: eof without closing the pipe
by lhoward (Vicar) on Jun 30, 2000 at 17:12 UTC
    Opening a socket is typically as fast or faster than opening a pipe.

    Pipe issues:

    • Have the overhead of starting a separate process. (you may or may not have this overhead when doing a TCP socket connection depending on if the server is forking or threading)
    socket/TCP port issues:
    • Most OSes have highly optimized TCP/IP stacks, generally much more optmized than the OSes core pipe processing functions. For today's applications network performance is typically much more important than pipe performance.
    • localhost TCP/IP connections (where client and server are on the same host) do not go out "on the wire", they are typically highly optimized with direct memory-to-memory exchange of the data. Localhost network connections have practially 0 network overhead.
      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)

        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)