本文整理汇总了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
示例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