diff options
author | bustico | 2009-07-06 12:15:37 +0000 |
---|---|---|
committer | bustico | 2009-07-06 12:15:37 +0000 |
commit | 444095d3740e5d6c8f21d4c9121bd8d7a100e35d (patch) | |
tree | a7cef653ce08175c0874b2163b41db43b21a7ee2 | |
parent | f62ebfa82686020ab0ceea009c9688aae9cef9de (diff) | |
download | ivy-perl-444095d3740e5d6c8f21d4c9121bd8d7a100e35d.zip ivy-perl-444095d3740e5d6c8f21d4c9121bd8d7a100e35d.tar.gz ivy-perl-444095d3740e5d6c8f21d4c9121bd8d7a100e35d.tar.bz2 ivy-perl-444095d3740e5d6c8f21d4c9121bd8d7a100e35d.tar.xz |
put tcp socket in no_delay mode to reduce latency
-rw-r--r-- | Ivy.pm | 28 | ||||
-rwxr-xr-x | example/ivystat.pl | 5 |
2 files changed, 27 insertions, 6 deletions
@@ -212,6 +212,18 @@ use constant CALL_BY_REF => 1; use constant BIND_ONCE => 2; use constant MAX_TIMOUT => 1000; + +# TCP_NODELAY is for a specific purpose; to disable the Nagle buffering +# algorithm. It should only be set for applications that send frequent +# small bursts of information without getting an immediate response, +# where timely delivery of data is required (the canonical example is +# mouse movements). +use constant TCP_NO_DELAY_ACTIVATED => 1; + + +# Since Ivy is most of the time used to send events, we will priviligiate +# lag over throughtput, so _TCP_NO_DELAY_ACTIVATED is set to 1 +use constant MAX_TIMOUT => 1000; # pour pouvoir employer les regexps perl. Attention lors de l'utilisation # ne pas mettre un \n dans une chaine entre "" car l'\n sera interprete. use constant REG_PERLISSISME => ('w' => '[a-zA-Z0-9_]', @@ -1400,6 +1412,8 @@ sub _getBonjour ($) carp "Warning[$appName] Can't set flags for the socket: $!\n"; return; } + $appSock->sockopt(Socket::TCP_NODELAY, TCP_NO_DELAY_ACTIVATED); + binmode ($appSock); # on cree une entree pour $appSock dans la liste des regexp @@ -1443,8 +1457,10 @@ sub _getConnections ($) unless (fcntl($appSock, F_SETFL, $flags | O_NONBLOCK)) { carp "Can't set flags for the socket: $!\n"; return; - binmode ($appSock); } + + $appSock->sockopt(Socket::TCP_NODELAY, TCP_NO_DELAY_ACTIVATED); + binmode ($appSock); } @@ -1704,7 +1720,11 @@ sub _getMessages ($$) $self->_pong ($appSock, $id); } - elsif ($type == PONG) { + +# le traitement est basique, ne fonctionne que si le recepteur traite le pong +# avant qu'il n'envoie un deuxieme ping. Si les pings sont envoyés trop rapidement, +# aucun pong ne sera émit. + elsif ($type == PONG) { if (exists $self->[pongQueue]->{$appSock}) { my ($pingid, $time, $funcRef) = @{$self->[pongQueue]->{$appSock}}; # printf ("DBG>>> stocked Id = $pingid;; message id = $id\n"); @@ -2860,9 +2880,9 @@ Send a suicide to the application named $to. =item B<ping> $ivyobj->ping($to, $timeout); - Ivy::ping($to, $timeout); + Ivy::ping($to, \&callBack); -Send a ping message and wait until timeout to receive a pong. +Send a ping message, callBack will be called on response. =item B<after> diff --git a/example/ivystat.pl b/example/ivystat.pl index 933ad7c..0d4e2e4 100755 --- a/example/ivystat.pl +++ b/example/ivystat.pl @@ -234,7 +234,8 @@ sub writeLogs () # total : nb octets envoyés, nb mess envoyés, nb octets reçus, nb mess reçus # pour chaque agents en receptions : # nb octets envoyés, nb mess envoyés, - my (@sortedApp, $appf, $appn, $appt, $regx, $numRegx); + my (@sortedApp, $appf, $appn, $appt, $regx); + my $numRegx = 0; my %regxByNumOccur; # il faut que le filehandle LOG soit valide @@ -336,7 +337,7 @@ sub receivePongCb($$) $max = $time if $time > $max; $total += $time; $received ++; -# printf ("DBG> :$received: $appf [$min, $time, $max]\n"); + printf ("DBG> :$received: $appf [$min, $time, $max]\n"); @{$pingResponse{$appf}} = ($min, $max, $total, $received, $sent); } |