Redis is slow to get large strings

前端 未结 2 1106
粉色の甜心
粉色の甜心 2021-02-20 13:22

I\'m kind of a newb with Redis, so I apologize if this is a stupid question.

I\'m using Django with Redis as a cache.

I\'m pickling a collection of ~200 objects

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 14:10

    Redis is not designed to store very large objects. You are not supposed to store your entire collection in a single string in Redis, but rather use Redis list or set as a container for your objects.

    Furthermore, the pickle format is not optimized for space ... you would need a more compact format. Protocol Buffers, MessagePack, or even plain JSON, are probably better for this. You should consider to apply a light compression algorithm before storing your data (like Snappy, LZO, Quicklz, LZF, etc ...).

    Finally, the performance is probably network bound. On my machine, retrieving a 20 MB object from Redis takes 85 ms (not 3 seconds). Now, if I run the same test using a remote server, it takes 1.781 seconds, which is expected on this 100 Mbit/s network. The duration is fully dependent on the network bandwidth.

    Last point: be sure to use a recent Redis version - a number of optimization have been done to deal with large objects.

提交回复
热议问题