This module monkeypatch python's xmlrpclib to use lxml based parser to reduce memory consumption on big xmlrpc requests / responses (100+ Mb)
This module is useful only for *python2.7*.
Use it only if you suffer from high memory consumption of xmlrpclib
This module is hosted on PyPI so it could be easily installed via pip:
pip install lxmlrpc_monkey
To use this module just do following
import xmlrpclib
from lxmlrpc_monkey import patch_xmlrpclib
# This line will monkey-patch xmlrpclib to use lxml for parser
patch_xmlrpclib()
To run benchmarks:
- install memory_profiler
- prepare data with
python generate_data.py --path <demo data path> --size 50000000
- run benchmarks with
python benchmark.py --path <demo data path>
look at `p.feed(data)
call in loads
` function of xmlrpclib
*Running unpatched loads*
Filename: /usr/lib/python2.7/xmlrpclib.py
Line # | Mem usage | Increment | Line Contents |
---|---|---|---|
|
104.7 MiB |
|
|
|
104.7 MiB |
|
|
|
622.4 MiB | 517.7 MiB |
|
|
558.0 MiB | -64.4 MiB |
|
|
558.0 MiB |
|
|
*Running patched loads*
Filename: /usr/lib/python2.7/xmlrpclib.py
Line # | Mem usage | Increment | Line Contents |
---|---|---|---|
|
106.9 MiB |
|
|
|
106.9 MiB |
|
|
|
235.9 MiB | 129.0 MiB |
|
|
171.5 MiB | -64.4 MiB |
|
|
171.5 MiB |
|
|
Filename: bechmark.py
Line # | Mem usage | Increment | Line Contents |
---|---|---|---|
|
104.7 MiB |
|
@profile def bench_load(xmldata): |
|
104.7 MiB |
|
|
|
106.9 MiB |
|
|
|
106.9 MiB |
|
|
|
106.9 MiB |
|
|
|
107.1 MiB |
|
|
*Running unpatched loads*
---
Filename: /usr/lib/python2.7/xmlrpclib.py
Line # | Mem usage | Increment | Line Contents |
---|---|---|---|
|
|
|
|
|
|
|
|
|
1203.0 MiB | 1033.8 MiB |
|
|
1074.2 MiB | -128.8 MiB |
|
|
1074.2 MiB |
|
|
*Running patched loads*
---
Filename: /usr/lib/python2.7/xmlrpclib.py
Line # | Mem usage | Increment | Line Contents |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-128.8 MiB |
|
|
|
|
|
Filename: bechmark.py
Line # | Mem usage | Increment | Line Contents |
---|---|---|---|
|
|
|
@profile def bench_load(xmldata): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|