【问题标题】:Cassandra python driver: Client request timeoutCassandra python驱动程序:客户端请求超时
【发布时间】:2018-07-17 03:42:00
【问题描述】:

我设置了一个简单的脚本来将新记录插入 Cassandra 数据库。它在我的本地机器上运行良好,但是当我将数据库移动到远程机器时,我从客户端收到超时错误。如何正确设置此驱动程序的超时?我已经尝试了很多东西。我在我的 IDE 中破解了超时,让它在没有超时的情况下工作,所以我确定这只是一个超时问题。

我如何设置集群:

profile = ExecutionProfile(request_timeout=100000)
self.cluster = Cluster([os.getenv('CASSANDRA_NODES', None)], auth_provider=auth_provider,
                       execution_profiles={EXEC_PROFILE_DEFAULT: profile})
connection.setup(hosts=[os.getenv('CASSANDRA_SEED', None)],
                 default_keyspace=os.getenv('KEYSPACE', None),
                 consistency=int(os.getenv('CASSANDRA_SESSION_CONSISTENCY', 1)), auth_provider=auth_provider,
                 connect_timeout=200)

session = self.cluster.connect()

我正在尝试执行的查询:

    model = Model.create(buffer=_buffer, lock=False, version=self.version)

13..': '客户端请求超时。请参阅 Session.execute_async'},last_host=54.213..

我插入的记录是 11mb,所以我可以理解有延迟,只是增加超时就可以了,但我似乎无法弄清楚。

【问题讨论】:

    标签: python-2.7 cassandra datastax


    【解决方案1】:

    您可以在集群构造函数中设置 request_timeout:

    self.cluster = Cluster([os.getenv('CASSANDRA_NODES', None)], 
                           auth_provider=auth_provider,
                           execution_profiles={EXEC_PROFILE_DEFAULT: profile},
                           request_timeout=10)
    

    参考:https://datastax.github.io/python-driver/api/cassandra/cluster.html

    【讨论】:

    • 你不能,这是一个意外的参数,它会出错。
    • @MarkJones 可能您正在旧版本上尝试它?它对我来说很好,我什至在源代码中看到了这个论点。
    【解决方案2】:

    根据文档,request_timeoutExecutionProfile class 的一个属性,您可以给集群构造函数(this is an example)一个执行配置文件。

    所以,你可以这样做:

    from cassandra.cluster import Cluster
    from cassandra.cluster import ExecutionProfile
    
    execution_profil = ExecutionProfile(request_timeout=600)
    profiles = {'node1': execution_profil}
    cluster = Cluster([os.getenv('CASSANDRA_NODES', None)], execution_profiles=profiles)
    session = cluster.connect()
    
    session.execute('SELECT * FROM test', execution_profile='node1')
    

    重要提示:当您使用executeèxecute_async 时,您必须指定execution_profile 名称。

    【讨论】:

      【解决方案3】:

      默认请求超时是 Session 对象的一个​​属性(驱动程序版本 2.0.0 及更高版本)。

      session = cluster.connect(keyspace)
      session.default_timeout = 60
      

      这是最简单的答案(无需搞乱执行配置文件),我已经确认它有效。

      https://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Session

      【讨论】:

        猜你喜欢
        • 2018-11-05
        • 2017-02-18
        • 2015-11-16
        • 1970-01-01
        • 1970-01-01
        • 2017-04-05
        • 2017-11-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多