java - 在生菜中,我发现 redis 集群上的 async mget 比流水线慢得多
问题描述
我正在为一个新项目编写一些基准测试,但遇到了一个问题,即生菜(版本 5.1.3),我发现下面的代码使用了 mget:
@Override
public Set<V> getKeys(final Set<Long> keySet) {
try {
return asyncCommands.mget(keySet.toArray(new Long[0])).get(
5, TimeUnit.SECONDS
).stream().map(keyValue -> keyValue.getValue()).collect(Collectors.toSet());
} catch (Exception e) {
throw new RuntimeException(e);
}
比自己使用流水线要慢得多(比如慢 100 倍以上):
List<RedisFuture<V>> futures = new ArrayList<>(keySet.size());
keySet.forEach(
key -> futures.add(asyncCommands.get(key))
);
asyncCommands.flushCommands();
LettuceFutures.awaitAll(5, TimeUnit.SECONDS,
futures.toArray(new RedisFuture[0]));
final Set<V> collect = futures.stream().map(
future -> {
try {
return future.get(1, TimeUnit.SECONDS);
} catch (Exception e) {
log.warn("", e);
throw new RuntimeException();
}
}
).filter(
Objects::nonNull
).collect(Collectors.toSet());
return collect;
与 redis 服务器报告的相比,这两个似乎都相当慢,但可能还有其他因素。javadocs说mget应该使用流水线,那么为什么它比我自己做流水线要慢得多?我做错了什么?
编辑:对于我启用了 autoflushcommands 的 mget,对于流水线它被禁用。
更新:发现性能低下的罪魁祸首是编解码器慢,当编解码器速度慢时,有什么办法可以提高整体吞吐量?
解决方案
推荐阅读
- bixby - Bixby:音频播放器概念
- angular - 如何修复“找不到模块'@angular/core'”。message-format-config.d.ts 中的 InjectionToken(错误 TS2307)
- mongodb - 如何正确编写嵌套的 bson.M{}
- php - MethodNotAllowedHttpException 有问题
- ios - 存档时找不到 FirebaseMessaging.h 文件
- c# - 如何在 NEST、C# 中为 date_histogram 按周编写等效查询
- sql-server - 从前一个日期获取详细信息
- c# - PictureBox 可以加载不同的图像作为变量变化吗?
- mongodb - 如何在mongo中对后续元素进行分组?
- ruby - 如何概括我的代码以找到两个具有更多数字 4,5 或 6 的数字的回文数,我该怎么做才能使其更快地工作?