Re: Question about non-blocking NIO and Selection Keys
- From: Zachary Turner <divisortheory@xxxxxxxxx>
- Date: Wed, 2 Jul 2008 01:33:39 -0700 (PDT)
On Jul 2, 12:03 am, Neil Coffey <neil.cof...@xxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Zachary Turner wrote:This could be an option, I considered it initially but wrote it off
Well, most of this is due to the fact that it was originally designed
around blocking sockets, and without a complete re-write it's hard to
do it correctly. The idea is that I want to wait *until the socket is
ready for writing*, then I want to write N bytes of data and return
immediately.
The sole reason this was changed from blocking to non-blocking is
because we need to support the case where the client can
asynchronously send a message to the server telling it to stop sending
more data, so the server needs to be able to do a non-blocking read,
because otherwise there's no way to say "is there data waiting? if so
read it, if not let me do other stuff".
Isn't your communication protocol just broken, then? What you
seem to be saying is that sometimes you need write/reads to be
sequenced, but sometimes you don't... Possibly things could be improved
by doing one of the following:
- use a separate connection for the asynchronous control message
(obviously wasteful, but OK for a small number of connections)
without much thought because non-blockign sockets seemed like the way
to go.
- make everything synchronous: after every portion of data sent, youActually tried this, but considering the volume of data being sent,
expect a response from the client "OK got that" or "OK got that but
don't send more"; if there's no data for you to send in X seconds,
send some "dummy" message (and expect a response) just to check if
the client is wanting to stop communication
the constant round trips back to the server were having a noticeable
performance impact. I got about 10% higher throughput just by
removing a 4 byte acknowledgement from client -> server after every
chunk of data.
- Of course, the client could also signal to the server that itWell, it's really more just like "I don't want any more of THAT
didn't want more data by closing the connection... :-)
data." But the server still has lots of other data to send.
The problem is that whatever I do has to fit nicely and transparently
into the implementation of a class that used to represent a blocking
socket, and is now scattered across 10s of thousands of lines of code
of our server. So what you said at the very beginning is pretty much
spot on. It needs to be blockign most of the time, but sometimes it
doesn't. I know it sounds stupid, but that's what happens when stuff
is designed poorly in the beginning and you just have to make
something work.
What I'm after is whatever is the closest I can possibly get to a
blocking socket with the added ability to "peek" at the socket's recv
buffer.
.
- References:
- Question about non-blocking NIO and Selection Keys
- From: Zachary Turner
- Re: Question about non-blocking NIO and Selection Keys
- From: Neil Coffey
- Question about non-blocking NIO and Selection Keys
- Prev by Date: My Favorite Browser Based Game – The Legacy of Holy Casle
- Next by Date: Re: nio charset doubt
- Previous by thread: Re: Question about non-blocking NIO and Selection Keys
- Next by thread: JScrollPane in GridBagLayout is either at minimum or contents' size
- Index(es):
Relevant Pages
|
Loading