Spring 引导 Cassandra 读取超时

Spring boot Cassandra read timeout

我在使用 Spring Boot + cassandra 网络应用程序时遇到问题。随着数据的增长,它开始出现,现在是非常普遍的情况。

所有查询有时都不起作用,CassandraRepository returns null。几秒钟后它再次工作,接下来几秒钟它又不工作了。所以 web 应用程序不断地 returns 200404 响应。相同的查询在 cqlsh 中一直有效。

我正在使用:

数据结构:

CREATE KEYSPACE data WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': '2'}  AND durable_writes = true;

CREATE TABLE data.image (
    hash text PRIMARY KEY,
    image blob
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

要配置 Cassandra 连接,我使用:

@Configuration
@EnableCassandraRepositories(basePackages = "...path...")
public class CassandraConfig extends AbstractCassandraConfiguration {

    @Bean
    public CassandraClusterFactoryBean cluster() {
        CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
        cluster.setContactPoints("127.0.0.1");
        cluster.setPort(91234);
        return cluster;
    }

为了检索数据,我使用 CassandraRepository@Query(("select * from image where id = ?0")) QueryAnnotation。检索到的数据包含图像斑点。

我认为读取超时是这里的一个问题,服务器的 HDD 磁盘速度较慢且 CPU 不是那么强大。但是我怎样才能用 spring boot starter 覆盖这个设置呢?

我试过使用

SocketOptions so = new SocketOptions();
so.setConnectTimeoutMillis(10000);
so.setReadTimeoutMillis(20000);
cluster.setSocketOptions(so);

没有成功。

我还能做些什么来获得稳定的工作解决方案?

nodetool repair 帮助 -> 几天后一切开始按预期工作。结论:写数据库太多了。