E45E
Skip to content

Memory size after "import pyroute2" is growing #1404

@ffourcot

Description

@ffourcot

Hello @svinota,

pyroute2 library has a « batterie included » philosophy in __init__.py. Almost everything is imported in top module. That is very convenient to abstract internal module hierarchy, and to show what pyroute2 provides, but loading so many modules has an important memory impact.

On my computer, with a fresh python interpreter:

>>> import sys
>>> import psutil
>>> len(sys.modules)
120
>>> int(psutil.Process().memory_info().rss / (1024 * 1024))
14
>>> from pyroute2 import IPRoute
>>> int(psutil.Process().memory_info().rss / (1024 * 1024))
33
>>> len(sys.modules)
383

I cannot just import what I need, e.g. IPRoute related code. I'm loading plan9 module, ipset, and much more.

Since pyroute2 is imported in a lot of script/daemon, the RAM consumption is an issue for us. We are maintaining a "out of tree" __init__.py file, with less line, but we are probably not alone to have this kind of issue.

I don't want to install pyroute2-minimal, since "sometimes" I perhaps need more features. But do you think we could find an approach (based on configuration? Environment?) to filter out what is imported on module top-level? In our case, it's okay for example to load WiSet "from pyroute2.wiset import WiSet" and to not provide it on top. We don't need it in every application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0