redis-benchmark -n 1000000 -t set -q -c 1
上述基准提供每秒 19k 的请求
但是我的 Nodejs Benchmarking for 'set' 命令每秒只提供 10k 请求
那么,与我的 nodejs 应用程序每秒 10k 请求相比,为什么 redis-benchmark 每秒有 19k 请求?
const Redis = require("ioredis");
const {
performance
} = require('perf_hooks');
// Ready the Redis client A
const RedisAClient = new Redis({ host: "127.0.0.1", port: 6379 });
// Call our benchmarking
Benchmarking();
// Our benchmarking function
async function Benchmarking() {
// Sleep async function
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const loopNumbers = 10000;
let processedTasks = 0;
const WholeTime = performance.now();
for (let i = 0; i < loopNumbers; i++) {
// Call redis for set command
RedisAClient.set("testing", i, function (err, reply) {
processedTasks++;
});
// If it is last loop then log the benchmark
if (i == loopNumbers - 1) {
// Wait for the all tasks to complete
while (processedTasks != (loopNumbers)) { await sleep(1); }
console.log((performance.now() - WholeTime) + "ms")
}
}
}