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


Python Cluster.connection_class方法代码示例

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


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

示例1: cassandra_connect

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [as 别名]
def cassandra_connect(seed, keyspace=None):
    from cassandra.cluster import Cluster
    from cassandra.io.libevreactor import LibevConnection

    cluster = Cluster()
    cluster.connection_class = LibevConnection
    return cluster, cluster.connect(keyspace)
开发者ID:mstump,项目名称:hub_and_spoke,代码行数:9,代码来源:replicate.py

示例2: benchmark

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [as 别名]
def benchmark(run_fn):
    for conn_class in supported_reactors:
        setup()
        log.info("==== %s ====" % (conn_class.__name__,))

        cluster = Cluster(['127.0.0.1'])
        cluster.connection_class = conn_class
        session = cluster.connect(KEYSPACE)

        log.debug("Sleeping for two seconds...")
        time.sleep(2.0)

        query = SimpleStatement("""
            INSERT INTO {table} (thekey, col1, col2)
            VALUES (%(key)s, %(a)s, %(b)s)
            """.format(table=TABLE))
        values = {'key': 'key', 'a': 'a', 'b': 'b'}

        log.debug("Beginning inserts...")
        start = time.time()
        try:
            run_fn(session, query, values, NUM_QUERIES)
            end = time.time()
        finally:
            teardown()

        total = end - start
        log.info("Total time: %0.2fs" % total)
        log.info("Average throughput: %0.2f/sec" % (NUM_QUERIES / total))
开发者ID:Kami,项目名称:python-driver,代码行数:31,代码来源:base.py

示例3: get_cluster

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [as 别名]
def get_cluster():
    cluster = Cluster(*Connection.cluster_args, **Connection.cluster_kwargs)
    try:
        from cassandra.io.libevreactor import LibevConnection
        cluster.connection_class = LibevConnection
    except ImportError:
        pass
    return cluster
开发者ID:KrisLee,项目名称:Feedly,代码行数:10,代码来源:connection.py

示例4: get_cluster

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [as 别名]
def get_cluster():
    cluster = Cluster(*Connection.cluster_args, **Connection.cluster_kwargs)
    cluster.default_retry_policy = FeedlyRetryPolicy(
        max_read_retries=settings.FEEDLY_CASSANDRA_READ_RETRY_ATTEMPTS,
        max_write_retries=settings.FEEDLY_CASSANDRA_WRITE_RETRY_ATTEMPTS
    )
    try:
        from cassandra.io.libevreactor import LibevConnection
        cluster.connection_class = LibevConnection
    except ImportError:
        pass
    return cluster
开发者ID:mojaray2k,项目名称:Feedly,代码行数:14,代码来源:connection.py

示例5: cassandra_connect

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [as 别名]
def cassandra_connect(seed=None, keyspace=None):
    from cassandra.cluster import Cluster

    if seed is None:
        args = ()
    else:
        args = ([seed],)

    cluster = Cluster(*args)
    try:
        from cassandra.io.libevreactor import LibevConnection
        cluster.connection_class = LibevConnection
    except ImportError:
        pass

    return cluster, cluster.connect(keyspace)
开发者ID:pmcnett,项目名称:hub_and_spoke,代码行数:18,代码来源:replicate.py

示例6: connect

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [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,
                      default_retry_policy=CustomRetryPolicy(),
                      reconnection_policy=ExponentialReconnectionPolicy(1, 60),
                      load_balancing_policy=load_balancing_policy,
                      protocol_version=3)

    cluster.connection_class = LibevConnection
    cluster.connection_class = LibevConnection
    cluster.control_connection_timeout = 10.0
    cluster.compression = False
    session = cluster.connect(keyspace)
    print 'Connection established with seed(s): %s at port: %s and keyspace: %s' %(seeds,port,keyspace)
    return session
开发者ID:Marcinthecloud,项目名称:DSESearchCount,代码行数:42,代码来源:dsecount_demo.py

示例7: benchmark

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [as 别名]
def benchmark(thread_class):
    options, args = parse_options()
    for conn_class in options.supported_reactors:
        setup(options.hosts)
        log.info("==== %s ====" % (conn_class.__name__,))

        cluster = Cluster(options.hosts, metrics_enabled=options.enable_metrics)
        cluster.connection_class = conn_class
        session = cluster.connect(KEYSPACE)

        log.debug("Sleeping for two seconds...")
        time.sleep(2.0)

        query = SimpleStatement(
            """
            INSERT INTO {table} (thekey, col1, col2)
            VALUES (%(key)s, %(a)s, %(b)s)
            """.format(
                table=TABLE
            )
        )
        values = {"key": "key", "a": "a", "b": "b"}

        per_thread = options.num_ops / options.threads
        threads = []

        log.debug("Beginning inserts...")
        start = time.time()
        try:
            for i in range(options.threads):
                thread = thread_class(i, session, query, values, per_thread, options.profile)
                thread.daemon = True
                threads.append(thread)

            for thread in threads:
                thread.start()

            for thread in threads:
                while thread.is_alive():
                    thread.join(timeout=0.5)

            end = time.time()
        finally:
            teardown(options.hosts)

        total = end - start
        log.info("Total time: %0.2fs" % total)
        log.info("Average throughput: %0.2f/sec" % (options.num_ops / total))
        if options.enable_metrics:
            stats = scales.getStats()["cassandra"]
            log.info("Connection errors: %d", stats["connection_errors"])
            log.info("Write timeouts: %d", stats["write_timeouts"])
            log.info("Read timeouts: %d", stats["read_timeouts"])
            log.info("Unavailables: %d", stats["unavailables"])
            log.info("Other errors: %d", stats["other_errors"])
            log.info("Retries: %d", stats["retries"])

            request_timer = stats["request_timer"]
            log.info("Request latencies:")
            log.info("  min: %0.4fs", request_timer["min"])
            log.info("  max: %0.4fs", request_timer["max"])
            log.info("  mean: %0.4fs", request_timer["mean"])
            log.info("  stddev: %0.4fs", request_timer["stddev"])
            log.info("  median: %0.4fs", request_timer["median"])
            log.info("  75th: %0.4fs", request_timer["75percentile"])
            log.info("  95th: %0.4fs", request_timer["95percentile"])
            log.info("  98th: %0.4fs", request_timer["98percentile"])
            log.info("  99th: %0.4fs", request_timer["99percentile"])
            log.info("  99.9th: %0.4fs", request_timer["999percentile"])
开发者ID:kenatbasis,项目名称:python-driver,代码行数:71,代码来源:base.py

示例8: parse

# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import connection_class [as 别名]
"""

def parse(path):
    g = open(path, 'r')
    for l in g:
        yield eval(l)

if __name__ == '__main__':
    f = open('config.txt', 'r')
    contact_points = f.readline()
    meta_path = sys.argv[1]
    geo_path = sys.argv[2]
    input_path = sys.argv[1]
    cluster = Cluster([contact_points])
    cluster.connection_class = LibevConnection
    session = cluster.connect()
    # session.execute(META_CF_DROP_STATEMENT)
    # session.execute(RANK_CF_DROP_STATEMENT)
    session.execute(KS_CREATION_STATEMENT)
    session.execute(META_CF_CREATION_STATEMENT)
    session.execute(RANK_CF_CREATION_STATEMENT)

    meta_prepared = session.prepare(META_INSERT_STATEMENT)
    rank_prepared = session.prepare(RANK_INSERT_STATEMENT)

    for data in parse(input_path):
        asin = data['asin']
        title = data.get('title', "")
        imurl = data.get('imUrl', "")
        price = data.get('price', 0.0)
开发者ID:phact,项目名称:datastax-workshop,代码行数:32,代码来源:populate.py


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