为何Node.js中DragonflyDB比Redis慢?与官方基准测试不符
问题:DragonflyDB读性能测试远慢于Redis,测试方式哪里出错?
我需要搭建一个读性能尽可能快的数据库,因此考虑了DragonflyDB——它在官方基准测试中宣称远快于Redis。这是2022年推出的内存数据库,与Redis(及Memcached)API几乎完全兼容,我需用它读写哈希或集合类型数据。
我编写了如下基准测试代码(设置N_ITER = 10_000):
Redis测试代码及结果
const Redis = require("ioredis") const redis = new Redis({ host: "localhost", port: 6380, password: "", }) console.time("1") const myRedisGetKeys = () => Promise.all(new Array(N_ITER).fill(1).map((_, i) => redis.get(i))) myRedisGetKeys().then(_ => { console.timeEnd("1") })
测试结果:1: 142.473ms
DragonflyDB测试代码及结果
const Redis = require("ioredis") const dragonfly = new Redis({ host: "localhost", port: 6379, password: "", }) console.time("2") const myDragonflyGetKeys = () => Promise.all(new Array(N_ITER).fill(1).map((_, i) => dragonfly.get(i))) myDragonflyGetKeys().then(_ => { console.timeEnd("2") })
测试结果:2: 728.216ms
可见DragonflyDB读性能比Redis慢5倍,我的测试方式哪里出了问题?
补充:若需,我可提供Python测试代码,该环境下Redis仅比DragonflyDB快20%。
内容的提问来源于stack exchange,提问作者Andrea Nicolai
相关产品推荐
相关产品推荐

