推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
SlipStupig
V2EX  ›  Python

关于 python 内存管理的一些想法

  •  
  •   SlipStupig · Feb 19, 2016 · 4127 views
    This topic created in 3919 days ago, the information mentioned may be changed or developed.
    看了一下 python 的代码内存申请释放使用的的 glibc 的 new 和 free ,看了国外测试换成 jemalloc 能提升一些性能(看起来还不错),但是都是使用的 LD_PRELOAD 去载入 jemalloc ,但是实际测试情况下来看好像没有什么用,难道只能改代码重新编译么?

    参看:
    http://derek.nodeconf.org/posts/why-im-switching-to-jemalloc-in-python/
    http://nuald.blogspot.com/2013/06/memory-reclaiming-in-python.html
    8 replies  •  2016-02-22 09:59:39 +08:00
    samuel
    samuel
    Feb 20, 2016
    1
    http://derek.nodeconf.org/posts/why-im-switching-to-jemalloc-in-python/
    这篇文章里的测试 case 并不是特别能体现 jemalloc 的优势:大量的碎片内存分配和多线程操作,测试里只是跑一个进程,连续申请很多相同大小的内存而已。

    LD_PRELOAD 只是把 malloc 的函数地址指向了 jemalloc 的动态库,这个过程不会有任何性能损耗,所以没必要重新编译
    fy
    fy
    Feb 20, 2016
    2
    按需优化吧,这不是热点吧? glibc 的实现也很不错了
    SlipStupig
    SlipStupig
    OP
    Feb 21, 2016
    3
    @fy malloc 内存申请性能真心不怎么样看一下测试结果就知道了
    http://img.ph.126.net/MnzyhfLLyEesD98wHZIZZA==/2298806134796631393.jpg
    SlipStupig
    SlipStupig
    OP
    Feb 21, 2016
    4
    @samuel 不是性能损耗的问题,那个主要是没有生效
    pynix
    pynix
    Feb 21, 2016
    5
    顶层优化更重要, python 貌似有内存块的实现。。。
    fy
    fy
    Feb 21, 2016
    6
    @SlipStupig 你找个大量小块内存的例子再试试?要看场景啊
    SlipStupig
    SlipStupig
    OP
    Feb 22, 2016
    7
    @pynix python 不是内存块, python 内存管理采用的是内存池技术 对于小块内存也强制用 4K 页面对齐,这个帖子先放这吧,我先看一下修改代码看一下结果
    pynix
    pynix
    Feb 22, 2016
    8
    @SlipStupig 。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2171 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:27 · PVG 21:27 · LAX 05:27 · JFK 08:27
    ♥ Do have faith in what you're doing.