From: John Kelly on 23 Jun 2010 00:39 Stein has an example of UNIX datagram sockets in his Networking book, but it includes other ideas that, to me, made it hard to see the forest for the trees. So I distilled it down to the bare essential elements related to socket setup. I use a loop with 100,000 iterations to test performance, and get about 40,000 round trips per second. A similar C solution gets about 55,000 round trips per second. Because syscall and context switch overhead is a limiting factor, the Perl code performs well compared to C. Please ignore bad practices in this code, it's only intended to show how to set up the datagram sockets, which to me, seemed mysterious without a simple example. --- CLIENT --- #!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; my $peer = '/tmp/server.sock'; my $node = '/tmp/client1.sock'; unlink $node; my $sock = IO::Socket::UNIX->new ( Local => $node, Peer => $peer, Type => SOCK_DGRAM ) or die "$!"; my $tn; my $data; for ($tn = 1; $tn < 100000; $tn++) { send ($sock, '1234567890_blah_blah_blah', 0) or die "$!"; recv ($sock, $data, 100, 0) or die "$!"; } print "tn=$tn\n"; --- SERVER --- #!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; my $node = '/tmp/server.sock'; unlink $node; my $sock = IO::Socket::UNIX->new ( Local => $node, Type => SOCK_DGRAM ) or die "$!"; my $peer; my $data; while (1) { $peer = recv ($sock, $data, 100, 0); send ($sock, $data, 0, $peer) || warn "$!"; } -- Web mail, POP3, and SMTP http://www.beewyz.com/freeaccounts.php
From: Uri Guttman on 23 Jun 2010 01:11 >>>>> "JK" == John Kelly <jak(a)isp2dial.com> writes: JK> Stein has an example of UNIX datagram sockets in his Networking book, JK> but it includes other ideas that, to me, made it hard to see the forest JK> for the trees. So I distilled it down to the bare essential elements JK> related to socket setup. JK> I use a loop with 100,000 iterations to test performance, and get about JK> 40,000 round trips per second. A similar C solution gets about 55,000 JK> round trips per second. Because syscall and context switch overhead is JK> a limiting factor, the Perl code performs well compared to C. so what is your actual question? uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: John Kelly on 23 Jun 2010 01:24 On Wed, 23 Jun 2010 01:11:12 -0400, "Uri Guttman" <uri(a)StemSystems.com> wrote: >>>>>> "JK" == John Kelly <jak(a)isp2dial.com> writes: > > JK> Stein has an example of UNIX datagram sockets in his Networking book, > JK> but it includes other ideas that, to me, made it hard to see the forest > JK> for the trees. So I distilled it down to the bare essential elements > JK> related to socket setup. > > JK> I use a loop with 100,000 iterations to test performance, and get about > JK> 40,000 round trips per second. A similar C solution gets about 55,000 > JK> round trips per second. Because syscall and context switch overhead is > JK> a limiting factor, the Perl code performs well compared to C. > >so what is your actual question? Do you expect all posts to ask for help? Why? -- Web mail, POP3, and SMTP http://www.beewyz.com/freeaccounts.php
From: Uri Guttman on 23 Jun 2010 01:50 >>>>> "JK" == John Kelly <jak(a)isp2dial.com> writes: JK> On Wed, 23 Jun 2010 01:11:12 -0400, "Uri Guttman" <uri(a)StemSystems.com> JK> wrote: >>>>>>> "JK" == John Kelly <jak(a)isp2dial.com> writes: >> JK> Stein has an example of UNIX datagram sockets in his Networking book, JK> but it includes other ideas that, to me, made it hard to see the forest JK> for the trees. So I distilled it down to the bare essential elements JK> related to socket setup. >> JK> I use a loop with 100,000 iterations to test performance, and get about JK> 40,000 round trips per second. A similar C solution gets about 55,000 JK> round trips per second. Because syscall and context switch overhead is JK> a limiting factor, the Perl code performs well compared to C. >> >> so what is your actual question? JK> Do you expect all posts to ask for help? Why? because they usually do. nothing you posted was signifigant as it was basic udp code that you can get from modules, books, documentation, etc. it wasn't particularly interesting even as a basic example. so if you had a reason other than asking a question, you could have stated that. seeing none, i had to ask why you posted it or you missed asking a question. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: John Kelly on 23 Jun 2010 07:16 On Wed, 23 Jun 2010 01:50:46 -0400, "Uri Guttman" <uri(a)StemSystems.com> wrote: > JK> Do you expect all posts to ask for help? Why? > >because they usually do. nothing you posted was signifigant as it was >basic udp code that you can get from modules, books, documentation, >etc. it wasn't particularly interesting I didn't realize you are the only person who ever reads this ng. How rude of me to invade your territory! :-D -- Web mail, POP3, and SMTP http://www.beewyz.com/freeaccounts.php
|
Next
|
Last
Pages: 1 2 3 4 5 6 7 Prev: FAQ 5.10 How can I use a filehandle indirectly? Next: FAQ 4.20 How do I unescape a string? |