卡桑德拉的超时例外

时间:2017-11-08 12:04:06

标签: java exception cassandra

我使用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个并发读写线程。请有人能为我提供解决方案吗?

1 个答案:

答案 0 :(得分:0)

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

这是表格架构