简体   繁体   English

Cassandra Java 驱动程序警告

[英]Cassandra java driver warning

I keep seeing this message in the logs, mainly everytime the query is made.我一直在日志中看到此消息,主要是每次进行查询时。

Query SELECT username AS col6,gender AS col1,last_name AS col2,email AS col3,first_name AS col4,something_uuid AS col5,group_email AS col7,deleted AS col8,puars AS col9 FROM something_data WHERE username=?;查询 SELECT username AS col6,gender AS col1,last_name AS col2,email AS col3,first_name AS col4,something_uuid AS col5,group_email AS col7,deleted AS col8,puars AS col9 FROM something_data WHERE username=?; is not prepared on /XX.YY.91.205:9042, preparing before retrying executing.未在 /XX.YY.91.205:9042 上准备,在重试执行之前准备。 Seeing this message a few times is fine, but seeing it a lot may be source of performance problems.多次看到此消息是好的,但看到很多次可能会导致性能问题。

The query is made using a mapper.get("username") ---> com.datastax.driver.mapping.Mapper使用 mapper.get("username") ---> com.datastax.driver.mapping.Mapper 进行查询

That's how I initialize the mapper in the constructor.这就是我在构造函数中初始化映射器的方式。 After that I don't use the mappingManager anymore.之后我不再使用 mappingManager 了。

this.mapper = mappingManager.mapper(MyPojo.class);

Any clues why?任何线索为什么?

It looks like that you aren't keeping the instance of the MappingManager for a long time, but recreate it every time you fetch the data.看起来您并没有长时间保留MappingManager的实例,而是在每次获取数据时重新创建它。 It's a big mistake - MappingManager should have the same life time as Cluster and Session objects.这是一个大错误 - MappingManager应该与ClusterSession对象具有相同的生命周期。

The mapping manager is responsible for extracting the field annotations from your class, generating queries, preparing them & then executing.映射管理器负责从您的类中提取字段注释、生成查询、准备它们然后执行。 The prepared queries are cached inside mapping manager, so when it destroyed, the cache is lost, and when you trying to perform get again, the process is repeated, leading to significant overhead - query need to be prepared again, and this is significant network overhead, so actually your queries are slower than if you used non-prepared queries.准备好的查询被缓存在映射管理器中,所以当它被破坏时,缓存就会丢失,当你再次尝试执行get时,这个过程会重复,导致显着的开销 - 查询需要再次准备,这是重要的网络开销,因此实际上您的查询比使用未准备好的查询要慢。

Just move MappingManager instance to some static block, so it could be reused for all your mapper operations.只需将MappingManager实例移动到某个静态块,这样它就可以重用于所有映射器操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM