在将结果发送到数据库之前,我正在进行一些计算,将其存储在REDIS数据库中。
目前,我在单独的GAE实例(使用NodeJS处理的单线程计算)中对每块10k项进行批处理操作,虽然计算速度确实很好,但执行HSET操作的推送操作需要很长时间,因此会导致不同线程中的一些延迟(因为REDIS是单线程-使用Google基本实例的fyi )。
我做错了什么?我怎样才能让它比现在更快地被推进(比如成批的或者其他的)?
const key = '123';
for (const [column, value] of results) {
await this.appendRedisHashValue(key, column, value);
}
public async appendRedisHash(key: string, field: string, value: any) {
const appendRedisHashAsync = promisify(this.redisClient.hset).bind(this.redisClient);
return appendRedisHashAsync(key, field, JSON.stringify(value));
}正如您所看到的,我只是使用HSET逐个推送每个项目,想知道我们是否可以在单个HSET事务中执行某种SQL transactions并推动10k项,而不是每次都追加REDIS。
每个块(10k项)在保存到REDIS后的大小为43 in (因此总共100 k项提供430 in)。对于某些架构设计,必须将其存储在单个REDIS散列中。
当前速度(毫秒),每个作业在并行的单独线程中运行:
"push": 13608
"finishedAt": "2020-05-08T22:51:26.045Z"
push": 13591,
"finishedAt": "2020-05-08T22:51:29.640Z"
"push": 15738,
"finishedAt": "2020-05-08T22:51:59.177Z"
"push": 21208,
"finishedAt": "2020-05-08T22:51:44.432Z"
"push": 13332,
"finishedAt": "2020-05-08T22:51:28.303Z"
"push": 10598,
"finishedAt": "2020-05-08T22:51:44.455Z"
"push": 27249,
"finishedAt": "2020-05-08T22:51:58.458Z"
"push": 36270,
"finishedAt": "2020-05-08T22:52:00.708Z"
"push": 25106,
"finishedAt": "2020-05-08T22:52:02.234Z"
"push": 12845,
"finishedAt": "2020-05-08T22:52:02.254Z"如有任何反馈,将不胜感激。
发布于 2020-05-09 02:43:44
您要做的是用一个键/值多次调用hset。这是不好的,因为往返延迟。
对10k键/值执行此操作将是10k往返行程。
您可以使用具有多个键/值的hset,因此它将是一次到redis的旅程。例如
hset field1 value1 field2 value2 field3 value3
https://stackoverflow.com/questions/61689936
复制相似问题