gautam has asked for the wisdom of the Perl Monks concerning the following question:

Respect to monks,
I'm listening for syslogs on a socket in the following manner
my $MySocket=new IO::Socket::INET->new(LocalPort=>$listenport,Proto=>' +udp'); while(1) { #receive syslog $MySocket->recv(my $text,1500); #some logging statements #put it in a queue $MyQueue->enqueue($text); }
I find during stress testing that I'm missing some syslogs(roughly 5%). I'm assuming this is because of the time taken to process the statements after the recv().

I think receiving the syslog and enqueing it in the same line of code would help. Any ideas on how to go about this? Any suggestions/comments are welcome.

Thanks in advance

Replies are listed 'Best First'.
Re: Need help with Socket recv
by aquarium (Curate) on Mar 29, 2006 at 14:55 UTC
    if you think that shoving around at max 1500 characters is too slow, then pass a pointer instead of the text. btw udp is a non-guaranteed delivery protocol...so if the socket is busy (even just reading data) when more data is ready, it may get lost.
    the hardest line to type correctly is: stty erase ^H
      Hey aquarium, thanks for the reply. I'm now sure the UDP socket is dropping packets. Any idea on how to increase the "socket" buffer size?
Re: Need help with Socket recv
by traveler (Parson) on Mar 29, 2006 at 15:44 UTC
    1) Try adding Listen=>25 to your new (if the OS does not support a queue of 25, it will be set to the maximum). 2) Are you losing data in the logging or in the queue?
      Hey traveler, Does increasing the number of listen queues work with UDP too? I was under the impression that the queues handled connections for tcp sockets.
        Doh! Right. There is a queue size setting for UDP, but I cannot remember if it is a kernel compile time setting or an ioctl or what.
Reduced the UDP Socket packet drops by increasing buffer size
by gautam (Initiate) on Mar 30, 2006 at 11:24 UTC
    Heya and thanks for all the help/tips. I was able to reduce the packet drops by increasing the UDP buffer size. I still need to optimize the UDP buffer based on the message size and frequency etc, but atleast it works. After creating the socket, I used setsockopt() to increase the socket buffer size using the following line
    setsockopt($MySocket,SOL_SOCKET,SO_RCVBUF,100000);
    To see your current socket buffer size you can use the following code
    my $packed = getsockopt($MySocket,SOL_SOCKET,SO_RCVBUF); my $mybuffer = unpack("I", $packed); print "\n Buffer size : $mybuffer \n";
    Again, thanks for all the input