python - cassandra-driver 执行查询时,cassandra-driver 返回错误 OperationTimedOut

标签 python cassandra cql3

我使用 python 脚本传递给 cassandra 批处理查询,如下所示:

query = 'BEGIN BATCH ' + 'insert into ... ; insert into ... ; insert into ...; ' + ' APPLY BATCH;'
session.execute(query)



它工作了一段时间,但在启动脚本失败后大约 2 分钟内打印:

Traceback (most recent call last):<br>
  File "/home/fervid/Desktop/cassandra/scripts/parse_and_save_to_cassandra.cgi", line 127, in <module><br>
    session.execute(query)<br>
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1103, in execute<br>
    result = future.result(timeout)<br>
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 2475, in result<br>
    raise OperationTimedOut(errors=self._errors, last_host=self._current_host)<br>
cassandra.OperationTimedOut: errors={}, last_host=127.0.0.1<br>
<br>
<br>

我将超时从 cassandra.yaml 更改为:
read_request_timeout_in_ms:15000
range_request_timeout_in_ms:20000
write_request_timeout_in_ms:20000
cas_contention_timeout_in_ms:10000
request_timeout_in_ms:25000


然后我重新启动了cassandra,但没有帮助。错误一次又一次发生!

脚本失败时日志中的行:

INFO [BatchlogTasks:1] 2014-06-11 14:18:10,490 ColumnFamilyStore.java (line 794) Enqueuing flush of Memtable-batchlog@28149592(13557969/13557969 serialized/live bytes, 4 ops)
INFO [FlushWriter:10] 2014-06-11 14:18:10,490 Memtable.java (line 363) Writing Memtable-batchlog@28149592(13557969/13557969 serialized/live bytes, 4 ops)
INFO [FlushWriter:10] 2014-06-11 14:18:10,566 Memtable.java (line 410) Completed flushing; nothing needed to be retained. Commitlog position was ReplayPosition(segmentId=1402469922169, position=27138996)
INFO [ScheduledTasks:1] 2014-06-11 14:18:13,758 GCInspector.java (line 116) GC for ParNew: 640 ms for 3 collections, 775214160 used; max is 1052770304
INFO [ScheduledTasks:1] 2014-06-11 14:18:16,155 GCInspector.java (line 116) GC for ConcurrentMarkSweep: 1838 ms for 2 collections, 810976000 used; max is 1052770304
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,959 GCInspector.java (line 116) GC for ConcurrentMarkSweep: 1612 ms for 1 collections, 858404088 used; max is 1052770304
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,959 StatusLogger.java (line 55) Pool Name Active
Pending Completed Blocked All Time Blocked
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,959 StatusLogger.java (line 70) ReadStage 0 0 627 0 0
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java (line 70) RequestResponseStage 0
0 0 0 0
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java (line 70) ReadRepairStage 0 0 0 0 0
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java (line 70) MutationStage 0
0 184386 0 0
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java (line 70) ReplicateOnWriteStage 0 0 0 0 0

最佳答案

  1. 这是客户端超时(参见@Syrial 回复中的链接:http://datastax.github.io/python-driver/api/cassandra.html#cassandra.OperationTimedOut)

  2. 您可以更改 session default timeout :

    session = cluster.connect()
    session.default_timeout = 30  # this is in *seconds*
    
  3. 您可以更改 the timeout for a particular query :

    session.execute(statement, 30, ...)
    
  4. 您可以通过在 BATCH 中使用准备好的语句来大大加快执行速度。查看Batching statements sections in this post

  5. 如果您追求更好的结果,请阅读这些 performance notes

关于python - cassandra-driver 执行查询时,cassandra-driver 返回错误 OperationTimedOut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24157534/

相关文章:

java - Cassandra java 查询性能 count(*) 或 all().size()

mysql - Cassandra 和 MySql 集成 : How to deal with UUID keys?

cassandra - Cassandra 中的宽行与集合

python - Python中IF语句的评估

python - 为什么诗歌在运行 'add' 后删除一些条目?

python - 如何使用 Python 防止进出慢速 Cassandra 节点的流量

cassandra - 确定 Cassandra 中分区的节点

python - 如何使用 CPython 让泛型在 Python.NET 中工作

javascript - 如何从本地系统加载json文件并分配给某个变量

cassandra - CQL3:只有主键时如何检索TTL?