【问题标题】:Timeout Exception In CassandraCassandra中的超时异常
【发布时间】:2018-04-21 02:46:06
【问题描述】:

我使用Cassandra db 来获取一些频繁请求的数据。以下是我的代码

 public Map<String,String> loadObject(ArrayList<Integer> tradigAccountList){

        com.datastax.driver.core.Session session;
        Map<String,String> orderListMap = new HashMap<>();
        List<ResultSetFuture> futures = new ArrayList<>();
        List<ListenableFuture<ResultSet>> Future;


        try {
            session =jdbcUtils.getCassandraSession();
            PreparedStatement statement = jdbcUtils.getCassandraPS(CassandraPS.LOAD_ORDER_LIST);

            for (Integer tradingAccount:tradigAccountList){
                futures.add(session.executeAsync(statement.bind(tradingAccount).setFetchSize(3000)));
            }


                        for (ResultSetFuture future : futures){

                            for ( Row row : future.get().all()){
                                orderListMap.put(row.getString("cliordid"),row.getString("ordermsg"));
                            }
                        }

        }catch (Exception e){
        }finally {
        }
        return orderListMap;
    }

我同时发送大约 30 个请求,我的查询是这样的:

"SELECT cliordid,ordermsg FROM omsks_v1.ordersStringV1 WHERE tradacntid = ?"

每次运行此查询时,它都会大约获取至少30000 行。但是当我同时发送多个请求时,这将引发超时异常。

我的 Cassandra 集群有 2 个节点,每个节点有 32 个并发读写线程。请问谁能给我一个解决方案?

【问题讨论】:

  • 你能给我们看看表模式吗?

标签: java exception cassandra


【解决方案1】:
CREATE TABLE omsks_v1.ordersstringv1_copy1 (
    tradacntid int,
    cliordid text,
    ordermsg text,
    PRIMARY KEY (tradacntid, cliordid)
) WITH bloom_filter_fp_chance = 0.01
AND comment = ''
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 = '99.0PERCENTILE'
AND caching = {
    'keys' : 'ALL',
    'rows_per_partition' : 'NONE'
}
AND compression = {
    'sstable_compression' : 'LZ4Compressor'
}
AND compaction = {
    'class' : 'SizeTieredCompactionStrategy'
};

这是表架构

【讨论】:

    猜你喜欢
    • 2018-12-25
    • 2019-07-22
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    相关资源
    最近更新 更多