Article View: comp.unix.programmer
Article #10Re: UDP questions
From: Todd Sandor
Date: Wed, 28 Oct 1992 13:48
Date: Wed, 28 Oct 1992 13:48
68 lines
3713 bytes
3713 bytes
In article <1992Oct23.161349.8038@digi.lonestar.org> elin@digi.lonestar.org (Eddy Lin) writes:
+I have two questions about UNIX domain UDP.
+1. Does anybody have information about the speed of UNIX domain UDP ?
+ Is it faster or slower than message queue ?
No specific facts for you here, but UCP is fast. The more important question
is, can you application handle lost message? If can not, suggest using
stream sockets, or SysV message queues.
+2. According to Richard Stevens in UNIX Network Programming, UNIX domain
+ UDP can be considered reliable except it does not provide flow control.
+ Therefore, it is possible for a datagram client to send data so fast
+ that buffer starvation can occur. My question is "Can I figure out
+ the buffer size ?". Also when buffer starvation occurs, what happen
+ to the data ? Is the data lost or it just waiting for free buffer ?
----
To find out the buffer size, use the getsockopt() call, but what you will
really want to do is set the socket size to the max., the max. being 52428.
To get the receive size, set it and get it again, do the following:
int optlen;
int tmpsize;
int receivesize = 52428;
optlen = sizeof(receivesize);
if ((getsockopt(my_socket, SOL_SOCKET, SO_RCVBUF,
(char *) &tmpsize, &optlen)) < 0)
prt_error("Error in getsockopt() call (%s)", OSU_perror());
if ((setsockopt(my_socket, SOL_SOCKET, SO_RCVBUF,
(char *) &receivesize, sizeof(receivesize))) < 0)
prt_error(ERR_SERIOUS,"socket() receive size not increased (%s)",
OSU_perror());
optlen = sizeof(receivesize);
if ((getsockopt(my_socket, SOL_SOCKET, SO_RCVBUF,
(char *) &receivesize, &optlen)) < 0)
prt_error( ERR_SERIOUS, "Error in getsockopt() call (%s)",
OSU_perror());
---
When buffer starvation occurs, you get a socket overflow (data is
lost). To see how many socket overflows you have:
netstat -s | grep overflow
NOTE: The SunOS (and probably any BSD originating Unix OS's) only buffer
UP to 256 socket messages, irregarless of the buffer size. Test were
performed on various send buffer sizes to see when overflows occur,
got the following results:
* Message Size # of messages in a socket
*(# bytes in message)
* 1- 112 256
* 113- 224 171
* 225- 336 128
* 337- 448 102
* 449- 511 85
* 512- 1012 51
* 1013- 1584 approximately 52428 / (Message Size + 16)
* 1585- 1999+ 18
As you can see, if each message is 1 byte, and you have set the receive queue
on the receiving socket to be 52428 bytes, it will only buffer 256 bytes before
get a socket overflow (mbuf management). To some people, UDP is know as
the Unreliable Datagram Protocol (instead of User Datagram Protocol).
Have fun ...
--
OSI buys you the promise of richer applications than the IP suite, at the cost
of immaturity, complexity, inefficiency and incompleteness (unknown author).
Todd Sandor Newbridge Networks: Kanata, Ontario Canada
todds@newbridge.com Phone: 591-3600 (ext 1011)
Technical Details
Message-ID:
<1992Oct28.134815.2996@Newbridge.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!cunews!nbkanata!nexus!toddsReferences:
<1992Oct23.161349.8038@digi.lonestar.org>Show Full Headers
Complete Article Headers
Newsgroups: comp.unix.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!cunews!nbkanata!nexus!todds From: todds@Newbridge.COM (Todd Sandor) Subject: Re: UDP questions Message-ID: <1992Oct28.134815.2996@Newbridge.COM> Keywords: UDP Sender: usenet@Newbridge.COM (USENET News System) Nntp-Posting-Host: faerie_queene Organization: Newbridge Networks Corporation References: <1992Oct23.161349.8038@digi.lonestar.org> Distribution: usa Date: Wed, 28 Oct 1992 13:48:15 GMT Lines: 68