Re: How to increase Socket buffer size?
by chromatic (Archbishop) on May 06, 2003 at 06:18 UTC
|
How did you determine that you're losing packets due to buffer overflows? There are a lot of things that can go wrong between two hosts; how did you narrow it down? UDP doesn't guarantee package delivery; that's why they call it Unreliable. :)
If reliability is that important to you, you could implement packet numbers, reassembly for out-of-order packet delivery, and retransmission guidelines. Of course, it may end up looking a lot like TCP. Would it be possible to switch protocols?
| [reply] |
|
Ofcourse, I have flow sequence number in the packed data with which I can determine the packet loss. If the packet is lost in the n/w then I am sure we can't help. But increasing the socket buffer size is one of the measures that we can take to avoid the packet loss, to handle situations when there is resource problem on the system. I agree that this would not necessarily mean the packet loss would be eliminated -- the very reason for having something like TCP :) I was just thinking of a preventive measure.
Thanks,
-sureshr
| [reply] |
Re: How to increase Socket buffer size?
by pzbagel (Chaplain) on May 06, 2003 at 06:24 UTC
|
Actually, if your application uses UDP then it is most likely designed to tolerate some packet loss. That is the whole point of UDP. With TCP you get handshakes, checksums, acknowledgements, but you pay for it with some overhead and sacrificing some speed. With UDP you get none of that, instead you get a fast protocol with low overhead. At the same time your client program sends it's packets and doesn't care if they get there or not.
Perhaps you need to rethink your strategy regarding this UDP application. Dropping some packets may not be so bad in the long run. Or what about rewriting the socket code in C so it can suck down the packets faster?
Hope this gives you some ideas.
Cheers
| [reply] |
|
I am fine with losing 'some packets', but the whole idea of increasing the buffer size is to 'minimize' the packet loss, which I am sure would help during peak resource utilization of the system.
Thanks,
-sureshr
| [reply] |
Re: How to increase Socket buffer size?
by perlplexer (Hermit) on May 06, 2003 at 14:01 UTC
|
On UNIX you'd use setsockopt() and SO_RCVBUF/SO_SNDBUF to set the size of the receive/send buffers. I don't know if this is going to work on Windows but it's worth a try...
--perlplexer | [reply] |
Re: How to increase Socket buffer size?
by RMGir (Prior) on May 06, 2003 at 14:12 UTC
|
Wild guesses follow, so you've been warned.
In C (or C++) on Unix (and maybe Win32? Not sure), you'd do this by doing a
int newMaxBuff=512000;
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &newMaxBuff, sizeof(newMaxBuff))
+;
IO::Socket has setsockopt and sockopt methods. Have you tried setting SO_RCVBUF using those methods? Using getsockopt, you could at least check if using setsockopt changed _something_.
As I said, wild guesses...
--
Mike | [reply] [d/l] |
|
perlplexer & mike,
$sock->sockopt(SO_RCVBUF, $max_recv_buff_sz);
works for me. gr8
where $sock is a IO::Socket::INET object. SO_RCVBUF is defined in Socket.pm. INET seems to be derived from IO::Socket which derives from Socket. So ideally, one should be able to set the socket buffer size of a socket created using Socket class & its method setsockopt. In my case sockopt<\code> method calls <code>setsockopt internally, by deriving.
Thanks ppl,
Suresh R
| [reply] [d/l] [select] |
Re: How to increase Socket buffer size?
by valdez (Monsignor) on May 06, 2003 at 08:24 UTC
|
Look at Listen option of IO::Socket::INET; please note that if you are using the constant value SOMAXCONN, you are already using the maximum number of pending connections available for your system.
update: my answer is totally wrong.
Sorry, Valerio
| [reply] [d/l] |
|
I think you are referring to increasing the number of connections that can be accepted, rather than increasing the socket buffer size...
| [reply] |
Re: How to increase Socket buffer size?
by Anonymous Monk on May 06, 2003 at 12:56 UTC
|
It appears you will have to recompile Socket, as well as know what to modify (it's not apparent) to affect the buffer size | [reply] |
Re: How to increase Socket buffer size?
by ibanix (Hermit) on May 07, 2003 at 13:40 UTC
|
can't afford packet loss
Use TCP? That's what it was designed for. Fault-tolerant transmission.
$ echo '$0 & $0 &' > foo; chmod a+x foo; foo; | [reply] [d/l] |