Python中字符串的解压缩
来源:互联网 发布:php生成word文档 编辑:程序博客网 时间:2024/06/04 19:04
今天在用Streaming-Python处理一个MapReduce程序时,发现reducer失败,原因为耗费内存达到极限了!仔细查看代码时,发现有一个集合里保存着URL,而URL长度是比较长的,直接保存确实是耗费内存,于是想到用压缩存储,然后用的时候再解压,虽然处理时间增加,但是耗费内存大大降低!
具体就是使用zlib模块
import zlib raw_data = "hello,world,ooooooooooooxxxxxxxxxxx"zb_data = zlib.compress(raw_data) print "len(raw_data)=%d, len(zb_data)=%d, compression ratio=%.2f"\ % (len(raw_data), len(zb_data), float(len(zb_data))/len(raw_data)) # len(raw_data)=35, len(zb_data)=25, compression ratio=0.71raw_data2 = zlib.decompress(zb_data)print raw_data2
如果存在网络传输,上面的方法可能失效;例如我跑了一个MapReduce,mapper中压缩,reducer中解压,结果报错:
Traceback (most recent call last): File "/hadoop/yarn/local/usercache/lming_08/appcache/application_1415110953023_46173/container_1415110953023_46173_01_000018/./build_visitor_company_ulti_info_red.py", line 25, in <module> urllist += zlib.decompress(urlitem) + ""zlib.error: Error -3 while decompressing data: incorrect header checklog4j:WARN No appenders could be found for logger (org.apache.hadoop.hdfs.DFSClient).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.暂时还没找到有效办法。
0 0
- Python中字符串的解压缩
- 字符串的解压缩
- java实现linux中gzip压缩解压缩算法:byte[]字节数组,文件,字符串,数据流的压缩解压缩
- c#实现linux中gzip压缩解压缩算法:byte[]字节数组,文件,字符串,数据流的压缩解压缩
- python 中字符串的表示
- python中字符串的使用
- python中字符串的声明
- Python中字符串的总结
- Python中字符串的操作
- python中字符串的使用
- python中字符串的使用方法
- Python中字符串的表示
- python 中 字符串的应用
- Python中字符串的操作
- Python中字符串的方法
- python中字符串的操作
- 【Python】Python中字符串的编码分析
- iOS 中图片的解压缩
- 修改struts2的action的后缀名
- MemStoreChunkPool&MSLAB提升HBASE GC性能
- 集成 admob Banner广告出错之二 _OBJC_CLASS_$_EKEvent
- Cocos2d-JS 快速入门二 HelloWord
- 【Leetcode】Binary Tree Level Order Traversal (Tree Traversal)
- Python中字符串的解压缩
- NSUnknownKeyException
- 80 port system
- Oracle表维护 快速备份删除数据
- UVA 409 Excuses, Excuses! (字符处理)
- ASP.NET Web API GZip
- Netbeans 快捷键
- UVA 10115 Automatic Editing(字符处理)
- cocos编译出错大全集