Issue Details (XML | Word | Printable)

Key: DIRMINA-119
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Trustin Lee
Reporter: dave irving
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
MINA

Multiple selector loops

Created: 09/Nov/05 06:42 PM   Updated: 07/Dec/05 06:03 PM
Return to search
Component/s: None
Affects Version/s: 0.8.0
Fix Version/s: 0.9.0

Time Tracking:
Not Specified

File Attachments:
  Size
Zip Archive Licensed for inclusion in ASF works multipleIoProcessors.zip 2005-12-02 07:59 PM dave irving 32 kB
Zip Archive Licensed for inclusion in ASF works multipleIoProcessors.zip 2005-12-02 07:54 PM dave irving 0.0 kB
Zip Archive prototype.zip 2005-11-09 06:47 PM dave irving 6 kB
Environment: All. Benefit is dependant on environment

Resolution Date: 03/Dec/05 01:41 PM


 Description  « Hide
Mina's SocketIoProcessor currently owns a Selector and employs a single Worker to run the NIO "selector loop".
I have been running tests where Im trying to maximise throughput and have found - that in certain multi-cpu environments - this worker thread can encounter a large amount of starvation even though CPU usage is fairly low.

By testing 2 selector-loops instead of 1, I managed to improve my overall test throughput by just under 30%.

The general idea is to do this:

- Each SocketIoProcessor.Worker encapsulates its own work queues associated Selector
- It should be possible to configure the number of Workers (and thus selectors) employed by SocketIoProcessor
- When a SocketSession is added to the SocketIoProcessor, a Worker is selected (round-robin) which will be associated with the SocketSession for its lifetime. This association is managed by SocketSession (get/setWorker)
- When someone asks SocketIoProcessor to do some work to a session, instead of doing it directly, the processor now asks the session for its Worker, and delegates to the worker (i.e, the same worker is always used for an individual session)

I've done some prototyping, and have also checked that the concept works with the latest build.
The prototype is very hacky - mainly because there are some refactoring issues i'd like feed-back on before I submit a "proper" patch for review. Namely:

- How do you want me to tell the SocketIoProcessor how many workers to use? One option is a system property - but thats pretty hacky. I dont think we need to support changing the number of workers after operation has begun (It'll probably be a function of the number of available CPUs) - and this makes the code simpler. However, as SocketIoProcessor is a (non lazy created) singleton, we need a way to get the param in. We could refactor, or maybe introduce a ProcessorOptions class or something. The SocketIoProcessor could interrigate this when initializing. Any direction on your desired approach would be appreciated

Cheers,

Dave

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #332564 Fri Nov 11 14:27:01 UTC 2005 trustin Resolved issue: DIRMINA-113 SocketIoProcessor should use ExceptionMonitor to log exceptions.
* SocketIoProcessor is not a singleton anymore. There's one SocketIoProcessor per SocketAcceptor(or SocketConnector)
* Changed the selector of SocketIoProcessor is initialized when Worker thread starts (lazy initialization)

Related issue: DIRMINA-119 Multiple selector loops
Files Changed
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionManagerFilterChain.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java

Repository Revision Date User Message
ASF #332577 Fri Nov 11 15:04:59 UTC 2005 trustin Related issue: DIRMINA-119 Multiple selector loops
* Added a new interface 'SocketSessionManager' to provide some socket-specific property.
Files Changed
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
ADD /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketSessionManager.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java

Repository Revision Date User Message
ASF #351884 Sat Dec 03 04:20:27 UTC 2005 trustin Resolved issue: DIRMINA-119 Multiple selector loops
* Applied Dave's patch with a few modifications
** Merged GlobalExceptionMonitor into ExceptionMonitor (ExceptionMonitor is an abstract class now)
** Renamed SocketIoProcessor.getSocketIoProcessor() to getInstance()
** Added more description to package.html
** Got rid of a log message which displays the number of processors
Files Changed
MODIFY /directory/network/trunk/src/java/org/apache/mina/common/ExceptionMonitor.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoConnector.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/package.html
MODIFY /directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/common/support/DefaultExceptionMonitor.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
MODIFY /directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBeanTest.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBean.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/common/IoSessionManager.java
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java

Repository Revision Date User Message
ASF #351885 Sat Dec 03 04:23:53 UTC 2005 trustin Related issue: DIRMINA-119 Multiple selector loops
* SocketIoProcessor overrides the system property to tell user the number of the processors employed actually.
Files Changed
MODIFY /directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java