1

Working on a project which utilizes the SSHD of Apache's Mina I stumbled upon the number of NioWorkers, when I tried to fix a behavior when more than 1 simultaneous transfers of bigger files would fail in 70% of the attempts. Increasing this value seems to help, but I can't find a definiton online what NioWorkers actually are. I looked at Oracle's documentation of Package java.nio and stressed Google.

Can anyone provide a link or define what they're supposed to be?

Dennis Winter
  • 2,027
  • 4
  • 32
  • 45

2 Answers2

2

The first big difference between NIO and IO is that IO is stream oriented, where NIO is buffer oriented.

IO being stream oriented means that you read one or more bytes at a time, from a stream. What you do with the read bytes is up to you. They are not cached anywhere. Furthermore, you cannot move forth and back in the data in a stream. If you need to move forth and back in the data read from a stream, you will need to cache it in a buffer first.

NIO's buffer oriented approach is slightly different. Data is read into a buffer from which it is later processed. You can move forth and back in the buffer as you need to. This gives you a bit more flexibility during processing. However, you also need to check if the buffer contains all the data you need in order to fully process it. And, you need to make sure that when reading more data into the buffer, you do not overwrite data in the buffer you have not yet processed.

source: http://tutorials.jenkov.com/java-nio/nio-vs-io.html#main-differences-between-java-nio-and-io

So I assume that worker is a thread which moves data from network to buffer, checks data consistency and notify when data were received & prepared. That's my guess and I'm not aiming to be completely right. The same question has guided me here.

Sergei Voitovich
  • 2,804
  • 3
  • 25
  • 33
0

NIO2 worker threads are responsible for handling raw incoming packets from NIO2 asynchronous sockets. Once a packet has been partially decoded and found to be relevant to the SFTP subsystem (in this case), it is passed along to a sshd-SftpSubsystem-thread-xx for further handling.

This way, the NIO2 worker becomes available to handle the next incoming packet (which may be relevant for some other channel - e.g., SCP) and thus does not depend on the time it takes to process the previous packet.

We should be very careful in selecting the nio-worker thread count, as it depends on the traffic actually - in view of my previous explanation. Furthermore, at some time you may run into context switching overhead issues - obviously, the more SFTP connections you have the more sshd-SftpSubsystem-thread-xx threads are running and thus increase memory, CPU, I/O and context switch overhead.