[SNMP4J] MessageDispatcher reduce threads with Java.nio

Jeff Garrett jeffrey.s.garrett at gmail.com
Fri Jul 27 21:28:49 CEST 2007


Hi.
I am using SNMP4J for creating a large number of network elements and having
them communciate with a seperate management software.  So far, things have
been real good.  But, now I have reached a point that I cannot get around so
simply.

Each network element is running on a different port, on the same machine,
over UDP.  I want it all on the same machine for simplicity and cost.  The
only flaw with this is there is at least 1 thread per network element, and I
want to create 5000+ network elements (I currently top out at 2500-3000
threads due to out of memory error from the awt event queue, and I have heap
size to around 1GB).
I have been reading a little about Java NIO and it sounds like it is
something that I can use in this project to increase performance and
decrease the amount of threads and memory used.  I was thinking it might be
possible to use it with the message dispatcher.

Currently, in my project, each network element creates and starts listening
(creates a thread) to its transport mapping (UDP port) and registers this
information with the message dispatcher via the addTransportMapping method
for snmp.  Each network element also adds its commandResponder
implementation, since there are slightly different types and models and this
affects the data sent back.  When an SNMP message arrives, the message will
come in over its UDP port and the message dispatcher will dispatch the
message to the proper commandResponder, which responds with data, simulating
a real network element.

What I want is, instead of each network element creating a thread to listen
on a UDP port, I register its UDP port with a Java NIO channel.  And when an
SNMP message comes in over a registered UDP port and into the channel, it
will be selected by the message dispatcher (via the Java NIO selector) and
sent to the proper CommandResponder.  The last part (commandResponder)
shouldn't involve any changing - I think the only change, if any, would
involve the way the messageDispatcher works.  This way I can have a handful
of threads running for the selector (say 10) and not have to create a thread
for each network element.

Has anyone ever done this before, or something like it?  Does anyone think
this is a good/bad idea?
I appologize if its already available somewhere - I looked but did not find
much information that was useful.

Thanks,
Jeff G.



Currently:
for(int port=1000; port<6000; port++){
   // setup the UDP transport mapping for each network element
   transport = new DefaultUdpTransportMapping(new UdpAddress(ipAddress,
port));
   transport.listen();
   // add the transport mapping to the messageDispatcher via the snmp object
   snmp.addTransportMapping(transport);

   //add the command responder
*   *messageDispatcher.addCommandResponder(this);
}

What I want:
for(int port=1000; port<6000; port++){
   // add the UDP port to the channel for each network element
   ServerSocket sock = server.socket();
   sock.bind(new UdpAddress(ipAddress, port));

    //add the command responder
*   *messageDispatcher.addCommandResponder(this);
}

// create the ServerSocketChannel and set it so there is no blocking.
Addresses will be bound to this channel later on (see above)
ServerSocketChannel server = ServerSocketChannel.open();
server.configureBlocking(false);

//add the ServerSocketChannel to the message dispatcher and have the message
dispatcher select an SNMP message from the channel when a message arrives
????????
// ..........................



More information about the SNMP4J mailing list