推荐学习书目
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
matrix1010
V2EX  ›  Python

Python 高性能内存缓存库 Theine & 高并发优化 Asyncio 缓存框架 Cacheme

  •  
  •   matrix1010 ·
    Yiling-J · Mar 6, 2023 · 2612 views
    This topic created in 1172 days ago, the information mentioned may be changed or developed.

    最近对两个库又做了些完善,欢迎试用。顺便附上 benchmarks ,都是与比较流行的库进行对比。具体说明可以去看项目的 Readme ,benchmarks 也是 Readme 里直接复制过来的

    - Theine: https://github.com/Yiling-J/theine

    10k 请求测试

    Read Write Mix Zipf
    Theine(W-TinyLFU) API 3.42 ms 10.14 ms
    Theine(W-TinyLFU) Auto-Key Decorator 7.17 ms 18.41 ms 13.18 ms
    Theine(W-TinyLFU) Custom-Key Decorator 6.45 ms 17.67 ms 11.50 ms
    Cachetools LFU Decorator 15.70 ms 627.10 ms 191.04 ms
    Cacheout LFU Decorator 50.05 ms 704.70 ms 250.95 ms
    Theine(LRU) Custom-Key Decorator 5.70 ms 16.04 ms 10.91 ms
    Cachetools LRU Decorator 14.05 ms 61.06 ms 36.89 ms
    Cacheout LRU Decorator 47.90 ms 94.94 ms 68.25 ms

    - Cacheme: https://github.com/Yiling-J/cacheme

    简单说明一下 benchmarks 先从 redis 获取数据,不存在时调用 load 函数生成数据存入 redis 。load 函数会 sleep 100 ms 。

    200k 请求测试

    1k 并发

    Time Redis GET Load Hits
    Cacheme 30 s 166454 55579
    Cacheme-2 18 s 90681 55632
    Aiocache 46 s 200000 56367
    Aiocache-2 63 s 256492 55417
    Cashews 51 s 200000 56920
    Cashews-2 134 s 200000 55450

    10k 并发

    Time Redis GET Load Hits
    Cacheme 32 s 123704 56736
    Cacheme-2 20 s 83750 56635
    Aiocache 67 s 200000 62568
    Aiocache-2 113 s 263195 55507
    Cashews 68 s 200000 66036
    Cashews-2 175 s 200000 55709

    100k 并发

    Time Redis GET Load Hits
    Cacheme 30 s 60990 56782
    Cacheme-2 27 s 55762 55588
    Aiocache 80 s 200000 125085
    Aiocache-2 178 s 326417 65598
    Cashews 88 s 200000 87894
    Cashews-2 236 s 200000 55647
    4 replies    2024-03-27 23:57:00 +08:00
    qile1
        1
    qile1  
       Mar 16, 2023 via Android
    方便说下用来干啥,如何使用,使用场景
    能 fastapi 调用当缓存吗?
    matrix1010
        2
    matrix1010  
    OP
       Mar 16, 2023
    @qile1 Theine 是高速本地内存缓存,Cacheme 是同时支持本地 /远程缓存的缓存框架。如何使用请参考对应项目 github 上的 readme 。使用场景参考各类缓存及我用来对比的几个库的使用场景。Theine 自带 Django cache 支持,没用过 fastapi 不了解
    Auston
        3
    Auston  
       Mar 27, 2024 via Android
    大佬,这个和 redis 的区别是什么?
    matrix1010
        4
    matrix1010  
    OP
       Mar 27, 2024
    @1311317 老哥 redis 是这样工作的:Python 对象 - 序列化成字节 - 发送 tcp 请求把字节发送到 redis 服务器 - redis 存储。而我这个是这样工作的:Python 对象 - Theine 里的字典。读取就是反过来,我就不重写一遍了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1028 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 19:06 · PVG 03:06 · LAX 12:06 · JFK 15:06
    ♥ Do have faith in what you're doing.