gpt4 book ai didi

performance - Redis 性能 : Many queries returning small objects vs one query returning large objects

转载 作者:IT王子 更新时间:2023-10-29 05:59:29 27 4
gpt4 key购买 nike

我是 Redis 的新手,到目前为止我真的很喜欢它。然而,我开始怀疑使用返回大对象(在 JSON 中存储信息)的单个查询是否更好 - 性能方面 - 或者我是否应该使用更小的查询,返回更小的对象?

最佳答案

Redis is single threaded application. Each query would be executed strictly one by one.

答案取决于您的需求和查询响应的大小。如果您尝试在一个查询中获取大量键(使用 MULTI 或使用 LUA 脚本),您可能会阻止您的服务器接受新查询。一次查询可让您将总时间保持在尽可能短的水平。

每个查询是:

  1. 解析查询。
  2. 获取数据。
  3. 通过网络发送。

例如:

-------------------------------------------------------------------> time 
| | | |
client send query(Q) | | got it(G)!
redis execute(E, server blocked) send response(SR)

但是,如果你做很多小的查询,信息的总时间会更长。

-------------------------------------------------------------------> time 
| | | | | | | | | |
client Q | | G | ... Q | | G | ...
redis E SR idle E SR idle

答案是(如果你有高负载系统):

  • 如果您需要接收有关数十个键的数据,则更愿意让它们进行一些查询。
  • 如果您的每个 key 都有一定数量的数据(例如很多千字节),请使用多次查询。

此外,如果您想保存 JSON,请考虑强制使用某种序列化(例如 messagepack 或 lz)以最小化内存消耗。

关于performance - Redis 性能 : Many queries returning small objects vs one query returning large objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34290162/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com