5

I want to know how many channels can a selector can handle at maximum? I'm familiar with common I/O algorithms, but I don't know in NIO whether I can use a selector for handling (for example) 10000 sockets. Should use a number of threads and have a selector in each for handling a specific number of sockets?

While I found this, it didn't address this specific question.

Community
  • 1
  • 1
AmRzA
  • 190
  • 11
  • 1
    The second response to the question you linked seems to answer this question: if you're using less than 10,000 connections, the problem is likely elsewhere. Defining a specific maximum may not be possible without knowing a lot about the hardware it's on and other factors using resources. – Nathaniel Ford Dec 14 '15 at 19:24
  • @NathanielFord The second response is just unsourced rumour actually, and has now been deleted due to adverse comment. It is also irrelevant to the question that was asked. – user207421 Dec 15 '15 at 01:18

1 Answers1

5

There is no limit other than the number of socket descriptors. Some platforms have underlying limits, but NIO works around them with multiple OS selectors per Selector.

There was a limit up to about Java 1.4.1 but it's long gone.

Should use a number of threads and have a selector in each for handling a specific number of sockets?

It's possible, but I don't really see why you should. Maybe the peers might get more regular service that way, it depends what your code has to do with every request.

user207421
  • 305,947
  • 44
  • 307
  • 483