- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试优化从 Redis 获取数据的性能。该服务器当前在我的 2015 Macbook Pro 上本地运行。
第一:问题说明目前我只有 32 个 key 存储为散列。其中 16 个在每个散列值中存储相当长的 JSON 字符串,每个散列中有 <300 个字段。其余的都非常小,所以我对它们没有任何问题。
在一个 Spring Boot 应用程序中,使用 Spring Data Redis 模板,通过 Jedis 连接,通过管道传输 4 个 HGETALL 命令 4 次,检索 16 个大哈希的总时间约为 1700 毫秒。
我的问题:我如何着手寻找真正的瓶颈?我已经检查了 SLOWLOG,它告诉我在服务器上执行的操作非常快,每个 HGETALL 命令 < 1 毫秒,这是可以预料的。这意味着瓶颈必须在 Java 应用程序和 Redis 服务器之间。延迟是否可能是另一个 ~1650ms 的原因? (延迟似乎不是其他较小哈希的问题。)或者它可能是我的 JSON 字符串的反序列化?我不确定如何测试它,因为我无法在 RedisTemplate 代码中放入计时器。
下面是我用来流水线化 HGETALL 命令的代码:
private Map<Date, Map<Integer, Departure>> pipelineMethod(List<String> keys, String keyspace) {
long pipeTime = System.currentTimeMillis();
List<Object> results = redisTemplate.executePipelined(
(RedisCallback) (connection) -> {
for (String key : keys) {
long actionTime = System.currentTimeMillis();
connection.hGetAll((keyspace + key).getBytes());
System.out.println("HGETALL finished in " + (System.currentTimeMillis()-actionTime) + "ms");
}
return null;
}
);
System.out.println("Pipeline finished in " + (System.currentTimeMillis()-pipeTime) + "ms");
Map<Date, Map<Integer, Departure>> resultMap = new ConcurrentHashMap<>();
for (int i = 0; i < keys.size(); i++) {
if (results.get(i) == null) {
resultMap.put(new Date(Long.parseLong(keys.get(i))), null);
log.debug("Hash map from redis on " + new Date(Long.parseLong(keys.get(i))) + " was null on retrieval");
}
else
resultMap.put(new Date(Long.parseLong(keys.get(i))), (Map<Integer, Departure>) results.get(i));
}
return resultMap;
}
如有任何建议,我们将不胜感激。
最佳答案
尝试使用带连接池的生菜客户端
private GenericObjectPoolConfig getPoolConfig() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
//All below should use the propertysources;
poolConfig.setMaxTotal(20);
poolConfig.setMaxIdle(20);
poolConfig.setMinIdle(0);
return poolConfig;
}
@Bean
@Primary
public RedisConnectionFactory redisConnectionFactory() {
DefaultLettucePool lettucePool = new DefaultLettucePool(redisHost, Integer.valueOf(redisPort).intValue(), getPoolConfig());
lettucePool.setPassword(redisPass);
lettucePool.afterPropertiesSet();
LettuceConnectionFactory clientConfig = new LettuceConnectionFactory(lettucePool);
clientConfig.afterPropertiesSet();
return clientConfig;
}
@Bean
public RedisTemplate<?, ?> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
return template;
}
关于java - 如何使用 Spring Data Redis 和本地 Redis 服务器查找性能瓶颈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39472333/
我有一个具有以下结构的表: ID, SourceID, EventId, Starttime, Stoptime 所有 ID 列都是 char(36),时间是日期。 问题是查询表真的很慢。我有 7 百
我们的应用程序服务器架构经过设置,以便每个服务调用都经过自定义构建的 WCF 服务路由器 - 这是一个使用请求消息 header 中嵌入的信息将传入请求分发到适当服务的服务。 我们在使用此 WCF 服
在分析一个计算数千个元素的层次聚类的 Java 应用程序时,我意识到 ArrayList.get占用执行集群化部分所需 CPU 的一半左右。 该算法搜索两个更相似的元素(因此它是 O(n*(n+1)/
我正在处理大数组(~6x40 百万),我的代码显示出很大的瓶颈。我在 MatLab 编程经验丰富,但对内部过程(如内存等......)知之甚少。 我的代码如下(只是要点,当然所有变量都初始化了,特别是
我正在尝试创建一个独立的类来维护与服务器的 Tcp 连接。 我正在使用以下类变量: TcpClient tcpClient; NetworkStream networkStream; BinaryRe
快速多线程问题... 我在内存中有一个包含大约 20,000 个项目的字典对象。如果我有多个线程尝试读取此对象,您会认为这会造成瓶颈吗? 净 3.5 。字典对象将是只读的 字典是只读的,所以我不关心读
我们有 2 台服务器: 文件 API 核心 API 不同服务器上的文件 API 和不同的核心 API。我们希望通过相同的域和端口进行访问,我们使用 nodeJS 作为后端平台。 所以我们想出了一个代理
我想并行下载/上传文件到 Azure。默认情况下,由于日志文件上的锁定,AzCopy 不允许在同一副本上多次运行。我通过将每个实例指向不同的日志文件(使用/Z )在同一台计算机上运行多个 Azcopy
因此,我将获取 10000 个 2 页 pdf 文件,并使用 iTextSharp 将它们合并为一个。 这是我正在做的一些松散代码: Document document = new Document(
我目前有一个多线程程序,可以抓取网站并将其文本写入文件。 CPU 方面,我可以同时运行大量线程,但 I/O 很快就会成为瓶颈。我想我可以让每个线程写入数组阻塞队列,但我知道我将生成超过可用 32GB
我在使用 PLINQ 时遇到了一些我似乎无法解释的奇怪结果。我一直在尝试并行化 Alpha Beta 树搜索以加快搜索过程,但它实际上减慢了搜索速度。我希望当我提高并行度时,我会每秒线性增加节点...
在对给定数组中的前 n = 1000 个元素进行排序时,为什么 bottleneck.argpartsort 具有最佳性能是否有原因(考虑到我没有搞砸某些事情)? 我创建了以下脚本: d = nump
我有一个已由 OpenMP 并行化的循环,但由于任务的性质,有 4 个 critical 子句。 分析加速并找出哪些关键子句(或可能非关键(!))在循环内占用最多时间的最佳方法是什么? 我使用 Ubu
我有一个使用 UIImage 对象的应用程序。到目前为止,我一直在使用像这样初始化的图像对象: UIImage *image = [UIImage imageNamed:imageName]; 在我的
对于以下问题场景,我们应该查看哪些 mySQL 服务器变量以及哪些阈值很重要: CPU 限制 磁盘读取限制 磁盘写入绑定(bind) 对于每种情况,除了获得更好的硬件或将数据库扩展到多台服务器之外,建
在我的工作表中,我有四个不同的类别。对于每个类别,有 3~5种不同的价格。还有其他属性。结果,每个类别都重复了很多次,总共有 30,000 行。工作表的第一行包含所有列名。每个类别跨越连续的行。因此,
我是 Spark、SparkR 以及所有 HDFS 相关技术的新手。我最近安装了 Spark 1.5.0 并使用 SparkR 运行一些简单的代码: Sys.setenv(SPARK_HOME="/p
Win 7/SolrNet 0.4.0/C# winforms .net 4.0 客户端。 我正在使用 Solrnet 和一个 winforms 线程应用程序将多个位图和一些数学描述符写入 Solr
我有一个 Android 后台服务,它会不时报告位置。当我通过 wifi 在本地测试时它工作得很好,但是当在 3G 连接中测试时(有时在 Edge 上)我发现应用程序显然进入了瓶颈并且不执行 onLo
我正在使用实时数据在网页上使用 SVG 绘制一些线条。为了管理数据,我使用 Angular.js 并管理可视化,我使用 D3.js。 我设置了一个 Angular Controller 来保存数据(行
我是一名优秀的程序员,十分优秀!