Re: Java NIO: calling selector.select() before socketChannel.write()
Bob Lee <[email protected]> Wed, 16 Apr 2008 16:28:35 -0700
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
No. You should only need one selector for your whole app assuming everything else is CPU bound and you're only targeting one core. Bob On Wed, Apr 16, 2008 at 4:18 PM, Sergey Marakhov <[email protected]> wrote: > Ok, what do you think about another question: is there any need to > open/create separate selectors for reading and writing operations? Or even > more: opening a separate write selector per client connection? > > Thank you, > > Sergey Marakhov > > Phone: (613) 9811 8083 > > Quest Software > > > -----Original Message----- > From: Discussion of advanced Java topics. [mailto: > [email protected]] On Behalf Of Bob Lee > Sent: Thursday, April 17, 2008 1:04 AM > To: [email protected] > Subject: Re: [ADVANCED-JAVA] Java NIO: calling selector.select() before > socketChannel.write() > > Yeah, you use a selector when you want to deal with multiple streams from > a > single thread, the idea being that threads don't scale well enough to > support tens of thousands of connections. TheServerSide recently had an > article that claimed that thread impls have gotten efficient enough that > you > may be better off using blocking I/O. I would test it. > > Bob > > On Wed, Apr 16, 2008 at 12:22 AM, Avinash Lakshman <[email protected] > > > wrote: > > > There is no reason to do a select() before a write(). However when you > do > > perform a write() you may not write the entire set of bytes you want to > > write. In that event you want to register for OP_WRITE interest with the > > selector and when notified by the selector (when the socket is > writeable) > > push the remaining bytes out. > > > > Cheers > > A> Date: Tue, 15 Apr 2008 16:48:50 -0700> From: [email protected]> > > Subject: Re: [ADVANCED-JAVA] Java NIO: calling selector.select() before > > socketChannel.write()> To: [email protected]> > I've > never > > used Java's non-blocking I/O, but in POSIX non-blocking I/O, you> > typically > > use one select() for everything.> > Bob> > On Tue, Apr 15, 2008 at 4:27 > PM, > > Sergey Marakhov <[email protected]>> wrote:> > > Hi all.> >> > > I'm > > looking at ways to simplify our current implementation of socket> > > > communications between an agent and multiple clients. There is a client> > > > > connection object created per connected client, client connection is> > > > passed through an "incoming" selector and each client connection opens > its> > > > own outgoing selector. So, question 1: do I need to create separate> > > > outgoing selectors, or is using a single selector for both in and out> > > > operations is the way to go?> >> > Next, before each invocation of > > socketChannel.write(...) method, we do> > outgoingSelector.select(). Is > it > > necessary to do select() before write> > operations?> >> > Our knowledge > of > > NIO is rather limited, hence all this questions.> >> > Much > appreciated...> > > > Sergey> >> > ===================================> > This list is hosted > by > > DevelopMentor(R) http://www.develop.com> >> > View archives and manage > > your subscription(s) at> > http://discuss.develop.com> >> > > > ===================================> This list is hosted by > DevelopMentor(R) > > http://www.develop.com> > View archives and manage your subscription(s) > at > > http://discuss.develop.com > > _________________________________________________________________ > > Pack up or back up-use SkyDrive to transfer files or keep extra copies. > > Learn how. > > > > > http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008 > > =================================== > > This list is hosted by DevelopMentor(R) http://www.develop.com > > > > View archives and manage your subscription(s) at > > http://discuss.develop.com > > > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentor(R) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com