• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Phishion
V2EX  ›  程序员

请问 Python 操作 Redis 写入数据每秒 5W 算正常么?

  •  
  •   Phishion · Oct 6, 2021 · 3142 views
    This topic created in 1686 days ago, the information mentioned may be changed or developed.

    代码如下,使用了 pipeline,10W 数据执行下来要 2s,这个算是正常速度么?请问还有啥跑更快的办法么?

    
    from datetime import datetime
    from redis import StrictRedis
    redis = StrictRedis(host='redis', port=6379, db=0)
    
    def test_redis(count):
        pipeline = redis.pipeline()
        process_start = datetime.now().timestamp()
        for value in range(1, count):
            user_key = 'user:id:' + str(value)
            pipeline.set(user_key, 'bar')
        pipeline.execute()
        process_elapsed = round(datetime.now().timestamp() - process_start, 2)
        print("\nDone ({}s).\n".format(process_elapsed))
        
    test_redis(100000)
    
    8 replies    2021-10-07 11:18:15 +08:00
    srx1982
        1
    srx1982  
       Oct 6, 2021
    换个解释器试试
    superrichman
        2
    superrichman  
       Oct 6, 2021   ❤️ 1
    Done (0.96s).
    你可能需要内存超频 /doge
    Phishion
        3
    Phishion  
    OP
       Oct 6, 2021
    @superrichman 感谢测试,我用的 VPS, 只能给啥用啥,你这个是挺快的
    ynkkdev
        4
    ynkkdev  
       Oct 6, 2021   ❤️ 1
    1.24s

    来自普通办公笔记本
    Phishion
        5
    Phishion  
    OP
       Oct 6, 2021
    @youngce 谢谢测试,可能是某云的 VPS 内存性能实在不行,也可能是我 Redis 跑在 Docker 上的原因(我没测试是不是有关联)
    notyss
        6
    notyss  
       Oct 7, 2021
    你是想测试 redis 还是 python 还是 python 的 redis library
    zhchyu999
        7
    zhchyu999  
       Oct 7, 2021
    测试下 redis 的 redis-benchmark 测试下 redis 的性能,看看瓶颈在哪里
    Phishion
        8
    Phishion  
    OP
       Oct 7, 2021
    @notyss 我就想测试一下在项目中实际的写入速度,脱离 Python 没啥意义
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3604 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 04:41 · PVG 12:41 · LAX 21:41 · JFK 00:41
    ♥ Do have faith in what you're doing.