【发布时间】:2016-01-15 23:19:22
【问题描述】:
我在我的项目中使用 Cassandra,并且在写入过程中遇到了超时问题,这与该人在这篇帖子中收到的相同 Cassandra cluster with bad insert performance and insert stability(目前我只使用一个节点进行测试,Java 驱动程序,最后释放卡桑德拉)。应用程序必须每天(在夜间)为每个用户插入大量数据。我有一个休息控制器,它接受文件,然后在它们并行到达时处理它们以在 Cassandra 中插入值。我必须为每个用户插入 100 万个条目,其中一个条目最多有 8 个值(时间不是那么重要,也可能需要 10 分钟)。根据Cassandra cluster with bad insert performance and insert stability 中提供的答案,我决定将 executeAsync()、Semaphore 和 PreparedStatement 添加到我的应用程序中,而之前我没有使用它们。
现在的问题是,使用可变键空间(每个用户一个)并且必须更新数据库中的列表,我无法在初始化阶段初始化我的 PreparedStatements,但我必须对每个文件至少执行一次已处理(一个文件包含 10+k 个条目),用户每天必须上传多达 100 个文件。因此,我收到以下警告:
Re-preparing already prepared query INSERT INTO c2bdd9f7073dce28ed973238ac85b6e5d6162fce.sensorMonitoringLog (timestamp, sensorId, isLogging) VALUES (?, ?, ?). Please note that preparing the same query more than once is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.
我的问题是:像这样使用 PreparedStatement 是一个好习惯,还是使用带有 executeAsync() 的普通插入更好?
谢谢
【问题讨论】:
标签: cassandra prepared-statement cql