【发布时间】:2019-08-19 08:16:12
【问题描述】:
我使用 org.springframework.data.cassandra.core.cql.support.PreparedStatementCache 来缓存preparedStatement。 但是需要很多内存。 看起来如果我仍然使用 PreparedStatement,缓存永远不会清理并增加(尽管我们使用相同的 cql 查询!!!)。 如果我不再给他打电话,记忆就会减少。
我的应用程序使用 springboot /cassandra dse 我们都在 tomcat 中测试(windows 和 linux 服务器,超过 500 req/s)。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<exclusions>
<exclusion>
<groupId>com.datastax.dse</groupId>
<artifactId>dse-java-driver-core</artifactId>
</exclusion>
</exclusions>
</dependency>
private final PreparedStatementCache cache = PreparedStatementCache.create();
public Channel findByIdChannel(String idChannel) {
List<Channel> listChannel = cassandraTemplate
.getCqlOperations()
.query(
findByIdChannelQuery(idChannel),
(row, rowNum) -> cassandraTemplate.getConverter().read(Channel.class, row));
if (listChannel.isEmpty()) {
return null;
}
return listChannel.get(0);
}
private BoundStatement findByIdChannelQuery(String idChannel) {
String cql = "select * from channel where idchannel = '" + idChannel + "'";
return CachedPreparedStatementCreator.of(
cache, cql).createPreparedStatement(session)
.bind();
}
任何提高性能的建议(不是关于使应用程序缓存和方法级别)? 我们如何修复preparedStatementCache的大小?
非常感谢。
【问题讨论】: