当前位置: 首页>>代码示例>>Python>>正文


Python Cluster.control_connection_timeout方法代码示例

本文整理汇总了Python中cassandra.cluster.Cluster.control_connection_timeout方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.control_connection_timeout方法的具体用法?Python Cluster.control_connection_timeout怎么用?Python Cluster.control_connection_timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cassandra.cluster.Cluster的用法示例。


在下文中一共展示了Cluster.control_connection_timeout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: connect

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import control_connection_timeout [as 别名]
def connect(seeds, keyspace, datacenter=None, port=9042):
    class CustomRetryPolicy(RetryPolicy):
        def on_write_timeout(self, query, consistency, write_type,
                             required_responses, received_responses, retry_num):
            # retry at most 5 times regardless of query type
            if retry_num >= 5:
                return (self.RETHROW, None)

            return (self.RETRY, consistency)

    load_balancing_policy = None
    if datacenter:
        # If you are using multiple datacenters it's important to use
        # the DCAwareRoundRobinPolicy. If not then the client will
        # make cross DC connections. This defaults to round robin
        # which means round robin across all nodes irrespective of
        # data center.
        load_balancing_policy = DCAwareRoundRobinPolicy(local_dc=DATACENTER)

    cluster = Cluster(contact_points=seeds,
                      port=port,
                      default_retry_policy=CustomRetryPolicy(),
                      reconnection_policy=ExponentialReconnectionPolicy(1, 60),
                      load_balancing_policy=load_balancing_policy,
                      protocol_version=3)

    cluster.control_connection_timeout = 10.0
    cluster.compression = False
    session = cluster.connect(keyspace)
    print 'Connection established with %s at port %s' % (seeds, port)
    return session
开发者ID:mitchell-h,项目名称:killrtickets,代码行数:33,代码来源:Generate_transactions.py

示例2: connect

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import control_connection_timeout [as 别名]
def connect(seeds, keyspace, datacenter=None, port=9042):
    from cassandra.io.libevreactor import LibevConnection
    from cassandra.cluster import Cluster
    from cassandra.policies import DCAwareRoundRobinPolicy, RetryPolicy, ExponentialReconnectionPolicy

    class CustomRetryPolicy(RetryPolicy):

        def on_write_timeout(self, query, consistency, write_type,
                             required_responses, received_responses, retry_num):

            # retry at most 5 times regardless of query type
            if retry_num >= 5:
                return (self.RETHROW, None)

            return (self.RETRY, consistency)


    load_balancing_policy = None
    if datacenter:
        # If you are using multiple datacenters it's important to use
        # the DCAwareRoundRobinPolicy. If not then the client will
        # make cross DC connections. This defaults to round robin
        # which means round robin across all nodes irrespective of
        # data center.
        load_balancing_policy = DCAwareRoundRobinPolicy(local_dc=datacenter)

    cluster = Cluster(contact_points=seeds,
                      port=port,
                      auth_provider=auth_provider,
                      default_retry_policy=CustomRetryPolicy(),
                      reconnection_policy=ExponentialReconnectionPolicy(1, 60),
                      load_balancing_policy=load_balancing_policy)

    cluster.connection_class = LibevConnection
    cluster.set_core_connections_per_host(0, 3) # local connections
    cluster.set_core_connections_per_host(1, 0) # remote connections
    cluster.control_connection_timeout = 10.0
    cluster.compression = False
    session = cluster.connect(keyspace)
    return session
开发者ID:manisrinivasan,项目名称:cisco,代码行数:42,代码来源:c_insert.py


注:本文中的cassandra.cluster.Cluster.control_connection_timeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。