简体   繁体   English

Spring启动Cassandra读取超时

[英]Spring boot Cassandra read timeout

I have problem with Spring Boot + cassandra web application. 我有Spring Boot + cassandra Web应用程序的问题。 It started to appear with data grown, and now it's super common scenario. 它开始随着数据的增长而出现,现在它是超常见的场景。

All queries sometimes doesn't work, CassandraRepository returns null . 所有查询有时都不起作用, CassandraRepository返回null And few seconds later it works again, and next few seconds it's not working again. 几秒钟之后它再次起作用,接下来的几秒钟它再次无法工作。 So web application constantly returns 200 or 404 response. 因此,Web应用程序不断返回200404响应。 The same query works in cqlsh all time. 相同的查询cqlshcqlsh工作。

I'm using: 我正在使用:

  • spring-boot-starter-parent#2.1.3 弹簧引导启动父#2.1.3
  • spring-boot-starter-data-cassandra#2.1.3 弹簧引导起动数据卡桑德拉#2.1.3
  • Cassandra 3.11.3 (multiple clusters) Cassandra 3.11.3(多个集群)

Data structure: 数据结构:

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';

To configure Cassandra connection I use: 要配置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;
    }

To retrive data I'm using CassandraRepository with @Query(("select * from image where id = ?0")) QueryAnnotation. 要检索数据我正在使用带有@Query(("select * from image where id = ?0")) CassandraRepository @Query(("select * from image where id = ?0")) QueryAnnotation。 Retrieved data contains image blobs. 检索到的数据包含图像blob。

I think that read timeout is a problem here, servers have slow HDD disks and not so powerful CPUs. 我认为读取超时是一个问题,服务器具有较慢的HDD磁盘而不是那么强大的CPU。 But how can I overwrite this settings with spring boot starter? 但是如何使用spring boot starter覆盖此设置?

I've tried to use 我试过用

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

with no success. 没有成功。

What else can I make to have stable working solution? 我还能做些什么来获得稳定的工作解决方案?

nodetool repair helped -> after a few days everything started to work as expected. nodetool repair帮助 - >几天后一切都开始按预期工作。 Conclusion: too much write do database. 结论:写数据库太多了。

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

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