Code Monkey home page Code Monkey logo

Comments (4)

etingof avatar etingof commented on May 18, 2024

Have you been able to figure out, with the memory_profiler library, what objects are leaking?

Do you run your code in multiple threads?

So far I do not see obvious issues with your pysnmp code, however I have a few suggestions:

  • switch to pysnmp hlapi followed by SnmpEngine instance unloading to free up resources
  • use a single persistent SnmpEngine instance for all your SNMP queries -- not only it would be more efficient, it might work around possible bugs causing memory leak

from pysnmp.

westofpluto avatar westofpluto commented on May 18, 2024

Can you please elaborate on this answer? How exactly would I do "SnmpEngine instance unloading to free up resources"? Do you just mean that I should call

del snmpEngine

after I use it? Or is it more involved than that?

Yes we run the code in multiple threads.

from pysnmp.

etingof avatar etingof commented on May 18, 2024

Let me revise my original answer then. Assuming you are calling SNMPGet from a thread and you are not doing SNMP I/O asynchronously, my suggestion is to use something like this:

from pysnmp.hlapi import *
from pysnmp.hlapi.lcd import CommandGeneratorLcdConfigurator

class SNMPGet:
    """Instance of this class must be thread-local, not shared between threads."""
    def __init__(self, *):
        self._snmpEngine = SnmpEngine()

    def _internal_execute(self, tmp_object_identifiers):
        gen =  getCmd(self._snmpEngine,
                      CommunityData('public'),
                      UdpTransportTarget(('demo.snmplabs.com', 161)),
                      ContextData(),
                      *[ObjectType(ObjectIdentity(oid)) for oid in tmp_identifiers])

        errorIndication, errorStatus, errorIndex, varBinds = next(gen)

    def cleanup(self):
        """Running SnmpEngine instance against ever increasing set of targets may grow memory.
            To drop SnmpEngine's caches you can periodically call this method. The backside is
            slight drop in performance as hot caches will have to be repopulated.
        """
        CommandGeneratorLcdConfigurator.unconfigure(self._snmpEngine)

As a side note, if you are fetching many OIDs from many targets, async I/O may give you better performance compared to MT one.

from pysnmp.

etingof avatar etingof commented on May 18, 2024

If the leak shows up with the later pysnmp versions -- please reopen this issue. Thank you!

from pysnmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.