所以我有一个小而简单的Redis数据库。它包含136689个键,这些键的值是包含27个字段的哈希映射。我正在通过服务器节点上的Python接口访问该表,每次调用需要加载大约1000-1500个值(最终每秒将看到大约10个请求)。一个简单的调用如下所示:
# below keys is a list of approximately 1000 integers,
# not all of which are in the table
import redis
db = redis.StrictRedis(
host='127.0.0.1',
port=6379,
db=0,
socket_timeout=1,
socket_connection_timeout=1,
decode_responses=True
)
with db.pipeline() as pipe:
for key in keys:
pipe.hgetall(key)
results = zip(keys,pipe.execute())
总时间约为328ms,每个请求的平均时间约为0.25ms
Question: This is very slow for a small database and relatively few queries per second. Is there something wrong with my configuration or the way I'm calling the server? Can something be done to make this faster? I don't expect the table to get much bigger so I'm perfectly happy sacrificing disk space for speed.
在每个键(没有管道)上调用hget
的速度较慢(如预期的那样),并且揭示了时间分布是双峰的。较小的峰值对应于不在表中的键,较大的峰值对应于不在表中的键。你知道吗
我的conf文件如下:
port 6379
daemonize yes
save ""
bind 127.0.0.1
tcp-keepalive 300
dbfilename mytable.rdb
dir .
rdbcompression yes
appendfsync no
no-appendfsync-on-rewrite yes
loglevel notice
我启动服务器时使用:
> echo never > /sys/kernel/mm/transparent_hugepage/enabled
> redis-server myconf.conf
我还用redis-cli --intrinsic-latency 100
测量了内在延迟,它给出了:
Max latency so far: 1 microseconds.
Max latency so far: 10 microseconds.
Max latency so far: 11 microseconds.
Max latency so far: 12 microseconds.
Max latency so far: 18 microseconds.
Max latency so far: 32 microseconds.
Max latency so far: 34 microseconds.
Max latency so far: 38 microseconds.
Max latency so far: 48 microseconds.
Max latency so far: 52 microseconds.
Max latency so far: 60 microseconds.
Max latency so far: 75 microseconds.
Max latency so far: 94 microseconds.
Max latency so far: 120 microseconds.
Max latency so far: 281 microseconds.
Max latency so far: 413 microseconds.
Max latency so far: 618 microseconds.
1719069639 total runs (avg latency: 0.0582 microseconds / 58.17 nanoseconds per run).
Worst run took 10624x longer than the average latency.
这表明我应该可以得到更好的延迟。但是,当我用:> redis-cli --latency -h 127.0.0.1 -p 6379
检查服务器延迟时,我得到min: 0, max: 2, avg: 0.26 (2475 samples)
这似乎表明~0.25ms是我的服务器的延迟,但这似乎表明我从Python看到的每个请求的延迟与CLI相同,但看起来都非常慢。你知道吗
与每个键相关联的hashmap(解码后)的大小约为1200字节。所以我运行了以下基准测试
redis-benchmark -h 127.0.0.1 -p 6379 -d 1500 hmset hgetall myhash rand_int rand_string
====== hmset hgetall myhash rand_int rand_string ======
100000 requests completed in 1.45 seconds
50 parallel clients
1500 bytes payload
keep alive: 1
100.00% <= 1 milliseconds
100.00% <= 1 milliseconds
69060.77 requests per second
这似乎支持我的延迟非常高,但没有真正告诉我为什么。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐