Skip to content

RFC: Allow modular import of the api and models #771

@xvello

Description

@xvello

Using kubernetes==8.0.1 on Linux, importing the Python Kubernetes client imports every model and api, amounting to a 35 to 40 MB RSS overhead. It also brings a significant wall-time penalty (even on repeat runs, to remove the IO time).

Comparaison graph

Ideally, one should be able to only import the types they need, as the golang client allows to: imports are segmented by apigroup, for example one can only import core/v1 without the rest of the APIs.

Would that be possible, possibly on a different import path than kubernetes.client, to keep compatibility? I'm not familiar enough with how the swagger generator works to know where to look into.

Raw data

Python 3.6.7

$ /usr/bin/time python -c "print('OK')"
0.02user 0.00system 0:00.03elapsed 97%CPU (0avgtext+0avgdata 8744maxresident)k
0inputs+0outputs (0major+1032minor)pagefaults 0swaps
$ /usr/bin/time python -c "import json"
0.03user 0.00system 0:00.03elapsed 100%CPU (0avgtext+0avgdata 9328maxresident)k
0inputs+0outputs (0major+1156minor)pagefaults 0swaps
$ /usr/bin/time python -c "from kubernetes import client"
0.41user 0.08system 0:00.50elapsed 99%CPU (0avgtext+0avgdata 45356maxresident)k
0inputs+0outputs (0major+21877minor)pagefaults 0swaps

Python 2.7.15

$ /usr/bin/time python -c "print('OK')"
0.01user 0.00system 0:00.02elapsed 60%CPU (0avgtext+0avgdata 6452maxresident)k
0inputs+0outputs (0major+680minor)pagefaults 0swaps
$ /usr/bin/time python -c "import json"
0.01user 0.01system 0:00.04elapsed 69%CPU (0avgtext+0avgdata 6840maxresident)k
0inputs+0outputs (0major+770minor)pagefaults 0swaps
$ /usr/bin/time python -c "from kubernetes import client"
0.29user 0.32system 0:02.98elapsed 20%CPU (0avgtext+0avgdata 46124maxresident)k
0inputs+0outputs (0major+17298minor)pagefaults 0swaps

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions