xmlrpclib修补程序以减少其内存消耗

lxmlrpc_monke的Python项目详细描述


lxmlrpc-xmlrpclib修补程序

这个模块monkeypatch python的xmlrpclib使用基于lxml的解析器 减少大型xmlrpc请求/响应(100+mb)的内存消耗

此模块仅对*python2.7*有用。

如果您受到xmlrpclib的high memory consumption的困扰,请仅使用

安装

此模块托管在PyPI 所以它可以通过pip轻松安装:

pip install lxmlrpc_monkey

使用量

要使用此模块,请执行以下操作

importxmlrpclibfromlxmlrpc_monkeyimportpatch_xmlrpclib# This line will monkey-patch xmlrpclib to use lxml for parserpatch_xmlrpclib()

基准(如何运行)

运行基准:

  1. 安装memory_profiler
  2. 使用python generate_data.py --path <demo data path> --size 50000000
  3. 准备数据
  4. 使用python benchmark.py --path <demo data path>

基准测试结果(50 MB(实际65 MB)数据文件)

看看xmlrpclib的`loads`函数中的`p.feed(data)`调用

*正在运行未修补的加载*

文件名:usr/lib/python2.7/xmlrpclib.py

Line #Mem usageIncrementLine Contents
1134104.7 MiB0.0 MiBdef loads(data, use_datetime=0):
1135“”“data -> unmarshalled data, method name
1136
1137Convert an XML-RPC packet to unmarshalled data plus a method
1138name (None if not present).
1139
1140If the XML-RPC packet represents a fault condition, this function
1141raises a Fault exception.
1142“”“
1143104.7 MiB0.0 MiBp, u = getparser(use_datetime=use_datetime)
>1144622.4 MiB517.7 MiBp.feed(data)
1145558.0 MiB-64.4 MiBp.close()
1146558.0 MiB0.0 MiBreturn u.close(), u.getmethodname()

*运行修补加载*

文件名:usr/lib/python2.7/xmlrpclib.py

Line #Mem usageIncrementLine Contents
1134106.9 MiB0.0 MiBdef loads(data, use_datetime=0):
1135“”“data -> unmarshalled data, method name
1136
1137Convert an XML-RPC packet to unmarshalled data plus a method
1138name (None if not present).
1139
1140If the XML-RPC packet represents a fault condition, this function
1141raises a Fault exception.
1142“”“
1143106.9 MiB0.0 MiBp, u = getparser(use_datetime=use_datetime)
>1144235.9 MiB129.0 MiBp.feed(data)
1145171.5 MiB-64.4 MiBp.close()
1146171.5 MiB0.0 MiBreturn u.close(), u.getmethodname()

文件名:bechmark.py

Line #Mem usageIncrementLine Contents
13104.7 MiB0.0 MiB@profile
14def bench_load(xmldata):
15104.7 MiB0.0 MiBprint (“Running unpatched loads”)
16106.9 MiB2.2 MiBloads(xmldata)
17
18106.9 MiB0.0 MiBlxmlrpc.patch_xmlrpclib()
19
20106.9 MiB0.0 MiBprint (“Running patched loads”)
21107.1 MiB0.2 MiBloads(xmldata)

基准测试结果(100 MB(实际129 MB)数据文件)

*正在运行未修补的加载*

-

文件名:usr/lib/python2.7/xmlrpclib.py

Line #Mem usageIncrementLine Contents
1134169.2 MiB0.0 MiBdef loads(data, use_datetime=0):
1135“”“data -> unmarshalled data, method name
1136
1137Convert an XML-RPC packet to unmarshalled data plus a method
1138name (None if not present).
1139
1140If the XML-RPC packet represents a fault condition, this function
1141raises a Fault exception.
1142“”“
1143169.2 MiB0.0 MiBp, u = getparser(use_datetime=use_datetime)
>11441203.0 MiB1033.8 MiBp.feed(data)
11451074.2 MiB-128.8 MiBp.close()
11461074.2 MiB0.0 MiBreturn u.close(), u.getmethodname()

*运行修补加载*

-

文件名:usr/lib/python2.7/xmlrpclib.py

Line #Mem usageIncrementLine Contents
1134171.6 MiB0.0 MiBdef loads(data, use_datetime=0):
1135“”“data -> unmarshalled data, method name
1136
1137Convert an XML-RPC packet to unmarshalled data plus a method
1138name (None if not present).
1139
1140If the XML-RPC packet represents a fault condition, this function
1141raises a Fault exception.
1142“”“
1143171.6 MiB0.0 MiBp, u = getparser(use_datetime=use_datetime)
>1144429.4 MiB257.8 MiBp.feed(data)
1145300.6 MiB-128.8 MiBp.close()
1146300.6 MiB0.0 MiBreturn u.close(), u.getmethodname()

文件名:bechmark.py

Line #Mem usageIncrementLine Contents
13169.2 MiB0.0 MiB@profile
14def bench_load(xmldata):
15169.2 MiB0.0 MiBprint (“Running unpatched loads”)
16171.6 MiB2.4 MiBloads(xmldata)
17
18171.6 MiB0.0 MiBlxmlrpc.patch_xmlrpclib()
19
20171.6 MiB0.0 MiBprint (“Running patched loads”)
21171.8 MiB0.2 MiBloads(xmldata)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
spring如何在java中将MimerReader的内容转换成字符串?   api为什么Java Map<K,V>为get和remove方法使用非类型化参数?   linux youtubedl从终端下载,但从java程序停止(同一命令)   java为webapp创建jar   根据控制代码质量的工具,JavaSpringbean不是线程安全的   git使用Java的gitlab API连接到gitlab   Hibernate标准中按嵌套属性(三级)的java排序   java Apache嵌入式derby TIMESTAMPDIFF函数在节光后额外返回1小时   java拒绝执行异常   java EditText可选择缩放   java ArrayIndexOutOfBoundsException在尝试通过反射访问内部类构造函数的参数注释时发生异常   java JMF大文件(2GB)无“movi”块错误   高效实现Java本机接口网络摄像头提要的性能   java显示shell排序过程   java静态空类   java如何检查反向比较器和原始比较器的相等性?   java从服务更新文本视图的最简单方法是什么?   java JTextField希望在我尝试使用时成为最终版本。getText()