我使用的是部署在3个不同VM上的3节点cassandra 3.0.14。我有很多数据(数十亿),我想在我的Cassandra架构中进行快速搜索。
我在Cassandra上做了很多研究,但我仍然面临着一些我不能理解的问题:
1-当我使用cqlsh时,我可以执行一个查询来分析我所有的数据库
SELECT DISTINCT val_1 FROM myTable;正在工作。
然而,我不能使用我的java代码和datastax驱动程序发出相同的请求。我的脚本返回:
Caused by: com.datastax.driver.core.exceptions.OperationTimedOutException: [/XX.XX.XX.XX:9042] Timed out waiting for server response
2-一些请求正在使用cqlsh工作,但发出更具体的请求将导致请求超时:
OperationTimedOut: errors={'127.0.0.1': 'Client request timeout. See Session.execute[_async](timeout)'}, last_host=127.0.0.1
例如,如果我发出以下请求:
SELECT val_1 FROM myTable where time>'2018-09-16 09:00:00';将工作SELECT val_1 FROM myTable where time>'2018-09-16 09:00:00' and time<'2018-09-17 09:00:00';将导致超时
我将request_timeout_in_ms更改为60,但我知道这不是一个好的做法。我也增加了我的read_request_timeout_in_ms和range_request_timeout_in_ms,但我仍然有前面的问题。
还会有人有同样的问题吗?
-Nicolas
发布于 2018-11-03 03:47:51
尝试在Java代码中调整客户端超时,如下所示:
//configure socket options
SocketOptions options = new SocketOptions();
options.setConnectTimeoutMillis(30000);
options.setReadTimeoutMillis(300000);
options.setTcpNoDelay(true);
//spin up a fresh connection (using the SocketOptions set up above)
cluster = Cluster.builder().addContactPoint(Configuration.getCassandraHost()).withPort(Configuration.getCassandraPort())
.withCredentials(Configuration.getCassandraUser(), Configuration.getCassandraPass()).withSocketOptions(options).build();发布于 2018-11-03 18:15:15
这是因为您使用Cassandra的方式不正确。只有在查询中指定了分区键时,范围操作、distinct等才能工作得最好。否则,Cassandra将需要扫描整个集群,试图找到您需要的数据,这将导致即使在中型数据库上也会超时。不要使用ALLOW FILTERING来强制执行查询。
在Cassandra中,数据库结构是围绕您想要执行的查询进行建模的。我推荐使用DS201 & DS220 courses from the DataStax Academy。
https://stackoverflow.com/questions/53122666
复制相似问题