[SNMP4J] problem when running snmp walk for a long time

Frank Fock fock at agentpp.com
Fri Jan 25 21:14:06 CET 2008


Hi,

You should not create a Snmp session for each
request. The overhead is too big especially
if you are sending requests concurrently.

Running 60 threads for performing 60 concurrently
walks is a bad idea either! A thread pool with
as many threads as there are CPUs in the host
will provide best performance. You need such
a thread pool for processing the responses only.
Thus, using a multi-threaded message dispatcher
is all you need.

Always have in mind, that a thread needs about
one MByte of memory!

Best regards,
Frank

YUAN Shuai wrote:
> hi all, here is the situation:
> 
> In each thread, I put a snmp walk request in a while-loop, so that the walk can be done at every 0 and 30 second.
> 
> Nearly 60 threads are created, and after running for about 3 hours, I got the following error and my other running applications just got errors too such as 'dll error' :
> 
> Exception in thread "Thread-34" java.lang.OutOfMemoryError: unable to create new native thread
>         at java.lang.Thread.start0(Native Method)
>         at java.lang.Thread.start(Thread.java:597)
>         at java.util.Timer.<init>(Timer.java:154)
>         at java.util.Timer.<init>(Timer.java:122)
>         at org.snmp4j.Snmp.<init>(Unknown Source)
>         at org.snmp4j.Snmp.<init>(Unknown Source)
>         at snmpacc.SNMPAccWalk.createSnmpSession(SNMPAccWalk.java:80)
>         at snmpacc.SNMPAccWalk.walkLeaf(SNMPAccWalk.java:106)
>         at scout.PERFWalker.run(PERFWalker.java:80)
>         at java.lang.Thread.run(Thread.java:619)
> 
> and
> 
> java.net.SocketException: No buffer space available (maximum connections reached?): Socket creation failed
>         at java.net.PlainDatagramSocketImpl.datagramSocketCreate(Native Method)
>         at java.net.PlainDatagramSocketImpl.create(PlainDatagramSocketImpl.java:73)
>         at java.net.DatagramSocket.createImpl(DatagramSocket.java:317)
>         at java.net.DatagramSocket.<init>(DatagramSocket.java:208)
>         at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
>         at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
>         at org.snmp4j.transport.DefaultUdpTransportMapping.<init>(Unknown Source)
>         at snmpacc.SNMPAccWalk.createSnmpSession(SNMPAccWalk.java:79)
>         at snmpacc.SNMPAccWalk.walkLeaf(SNMPAccWalk.java:106)
>         at scout.PERFWalker.run(PERFWalker.java:80)
>         at java.lang.Thread.run(Thread.java:619)
> 
> However I am sure to invoke the close() method, and the following is my walkLeaf():
> 
>     public String walkLeaf(String oid) throws IOException {
> //        System.out.println("walk oid:" + oid);
>         Address address = new UdpAddress(IPAddress.toString() + "/161");
>         Snmp snmp = createSnmpSession();
>         Target target = createTarget();
>         target.setVersion(getVersion(Version));
>         target.setAddress(address);
>         target.setRetries(retries);
>         target.setTimeout(timeout);
>         target.setMaxSizeRequestPDU(65535);
>         snmp.listen();
>         PDU request = new PDU();
>         request.setType(PDU.GET);
>         request.add(new VariableBinding(new OID(oid)));
>         
>         PDU response = null;
>         
>         ResponseEvent responseEvent = snmp.send(request, target);
>         if (responseEvent == null) {
>             return "no response";
>         }
>         
>         // receive the result
>         response = responseEvent.getResponse();
>         
>         // close the connection
>         snmp.close();
>         snmp = null;
>         
>         if (response == null) {
>             return "no response";
>         }
>         
>         return new String(response.get(0).getVariable().toString());
>     }
> 
> anyone get any idea dealing with this? THANK YOU!
> 
> vmape, 2008.01.24
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list