Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- From: "Maxim Yegorushkin" <maxim.yegorushkin@xxxxxxxxx>
- Date: 21 Dec 2006 00:28:06 -0800
Alex Fraser wrote:
"Rainer Weikusat" <rainer.weikusat@xxxxxxxxx> wrote in message
news:87slfhser2.fsf@xxxxxxxxxxxxxxxxxxxx
"Alex Fraser" <me@xxxxxxxxxxx> writes:
[...]
It seems to me that MSG_WAITALL does not make sense on non-blocking
sockets. (I am not convinced it is much use for blocking sockets
either.)
It is useful for bulk downloads.
...but not much else.
For a start, either you must be expecting the sender to send at least as
many bytes as the size argument to recv() or to close the connection after
sending. So MSG_WAITALL has strictly limited applicability.
I agree wholeheartedly.
Even if the above is satisfied, MSG_WAITALL can harm throughput if the size
passed to recv() is "too large" and you are performing some kind of stream
processing (for instance, decompressing it). I guess this is just an extra
restriction on applicability.
Assuming your application processes data fast enough, you can expect recv
to return for each 'link-layer PDU' (eg ethernet frame) received unless
the kernel handles TCP PSH somehow (at least Linux doesn't).
The above is only true if the delay between when the thread blocked in
recv() becomes ready to run (the relevant receive buffer becomes non-empty)
and actually running (a CPU becomes available) is always small. On a loaded
system, ie one where the average delay is larger, additional data could
sometimes be received and queued to the socket buffer during the delay. I
would expect the average bytes per recv() to increase in this case. If so,
that means MSG_WAITALL provides less benefit on a loaded system.
The other thing is that using MSG_WAITALL makes you not scalable: the
thread is blocked in read/recv while it could handle several
nonblocking sockets using select/poll/epoll/kqueue/whatever. In other
words, it may only be applicable to a some class of client
applications, not for servers hanling multiple connections/clients.
To scale it, one would have to create a thread per connection, which is
not quite elegant (at least in unix world). Saving a few system calls
does not make much sense, unless your profiler shows that this is the
bottleneck.
p.s. I don't understand why the thread digressed to MSG_WAITALL and a
blocking socket, since the original question was about non-blocking
socket and MSG_WAITALL.
.
- Follow-Ups:
- Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- From: Rainer Weikusat
- Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- From: David Schwartz
- Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- References:
- BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- From: softwaredoug
- Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- From: Alex Fraser
- Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- From: Rainer Weikusat
- Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- From: Alex Fraser
- BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- Prev by Date: Re: Imp: shared memory
- Next by Date: Re: Implementing a http server
- Previous by thread: Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- Next by thread: Re: BSD sockets: recv with MSG_WAITALL should return EWOULDBLOCK?
- Index(es):
Relevant Pages
|