suaveant has asked for the wisdom of the Perl Monks concerning the following question:
now if I change the code to use#!/idcom/bin/perl use IO::Socket::INET; use Time::HiRes qw( gettimeofday tv_interval ); use strict; our $PORT = 9991; if(fork) { my $s = IO::Socket::INET->new( LocalPort => $PORT, Listen => 5, Re +use => 1 ); my $c = $s->accept(); while(<$c>) { print {$c} $_; } } else { sleep 1; my $s = IO::Socket::INET->new( PeerAddr => 'localhost:'.$PORT ); for(1..5) { my $t0 = [gettimeofday]; print {$s} "func=mbs_descriptive&type="; print {$s} "&secid=313627KM2\n"; print ''.<$s>; print tv_interval( $t0, [gettimeofday] ),"\n"; } } OUTPUT func=mbs_descriptive&type=&secid=313627KM2 0.000458 func=mbs_descriptive&type=&secid=313627KM2 0.040329 func=mbs_descriptive&type=&secid=313627KM2 0.040905 func=mbs_descriptive&type=&secid=313627KM2 0.03986 func=mbs_descriptive&type=&secid=313627KM2 0.040938
A lot of our code kind of piecemeal prints to a socket like this, what is going on, and can I fix it without completely redesigning and existing codebase?print {$s} "func=mbs_descriptive&type=&secid=313627KM2\n"; instead of print {$s} "func=mbs_descriptive&type="; print {$s} "&secid=313627KM2\n"; <C> I then get <C> func=mbs_descriptive&type=&secid=313627KM2 0.000448 func=mbs_descriptive&type=&secid=313627KM2 9.3e-05 func=mbs_descriptive&type=&secid=313627KM2 0.000161 func=mbs_descriptive&type=&secid=313627KM2 7.8e-05 func=mbs_descriptive&type=&secid=313627KM2 7.7e-05
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help me understand/fix buffering issue for tcp?
by ikegami (Patriarch) on Nov 18, 2011 at 20:31 UTC | |
by suaveant (Parson) on Nov 21, 2011 at 14:01 UTC | |
by suaveant (Parson) on Nov 21, 2011 at 21:07 UTC | |
Re: Help me understand/fix buffering issue for tcp?
by andreas1234567 (Vicar) on Nov 21, 2011 at 14:31 UTC | |
by suaveant (Parson) on Nov 21, 2011 at 20:29 UTC |