[SNMP4J] Performance issue with single SNMP session
bretonlais at gmail.com
bretonlais at gmail.com
Sun Mar 14 20:59:45 CET 2010
Hi,
I'm having an issue sending/receiving a large number (>50 at a time) get
PDU's to approximately 200 different SNMP agents using a single SNMP
instance. The problem I am having is two-fold:
One, since my requests are synchronous, I have to synchronize the send
method and wait for a response from the snmp session, which is a bottleneck
for my application.
Two, I've attempted to do away with the synchronization, but then most of my
responses return null when I parse the PDU response.
Is there a way to correct this performance problem? Or do I need to create
an snmp session each of my 200 different devices? Please advise. I've tried
asynchronous methods, but I seem to run into the same type of problem. I've
included a section of my SNMP implementation
public PDU get(String oid, String community,
String targetIP) throws SnmpException {
VariableBinding var = new VariableBinding();
var.setOid(createOID(oid));
PDU request = new PDU();
request.add(var);
request.setType(PDU.GET);
Target target = createTarget(community, targetIP);
PDU response = null;
try {
response = send(request, target);
} catch (IOException ex) {
logger.error("Error sending getPDU {} ", ex.getMessage());
}
return response;
}
private synchronized PDU send(PDU request, Target target) throws
IOException
{
PDU response = null;
ResponseEvent responseEvent;
//long startTime = System.currentTimeMillis();
responseEvent = snmp.send(request, target);
if (responseEvent != null) {
response = responseEvent.getResponse();
//logger.info("Received response for {} after {} millis. " ,
target.getAddress(),System.currentTimeMillis()-startTime);
} else {
}
return response;
}
private Snmp createSnmpSession() {
Snmp snmpSession = null;
AbstractTransportMapping transport;
threadPool = ThreadPool.create("DispatcherPool", 10);
MessageDispatcher mtDispatcher =
new MultiThreadedMessageDispatcher(threadPool, new
MessageDispatcherImpl());
mtDispatcher.addMessageProcessingModel(new MPv1());
mtDispatcher.addMessageProcessingModel(new MPv2c());
try {
transport = new DefaultUdpTransportMapping(new UdpAddress("
0.0.0.0/161"));
snmpSession = new Snmp(mtDispatcher, transport);
} catch (IOException ex) {
logger.error("Unable to create SNMP session {} ",
ex.getMessage());
}
return snmpSession;
}
Thanks,
Matt
More information about the SNMP4J
mailing list