コード例 #1
0
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
コード例 #2
0
ファイル: connection.py プロジェクト: mojaray2k/Feedly
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
コード例 #3
0
def insert_data(arguments, rw):

    cluster = Cluster([arguments.host])
    cluster.default_retry_policy = AlwaysRetryPolicy()
    session = cluster.connect()
    session.execute("USE %s;" % arguments.keyspace)

    color_list = [
        'red', 'green', 'blue', 'yellow', 'purple', 'pink', 'grey', 'black',
        'white', 'brown'
    ]
    size_list = ['P', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL']
    qty_list = xrange(500)
    elements = cycle(product(color_list, size_list, qty_list))

    row_count = arguments.start_key
    while True:
        if row_count >= arguments.num_keys:
            break
        row_count += 1

        color, size, qty = elements.next()
        key = "key_%d" % row_count

        query = '''INSERT INTO {columnfamily} (
                   key,
                   color,
                   size,
                   qty)
                   VALUES (%s,%s,%s,%s)'''.format(
            columnfamily=arguments.columnfamily)
        params = [
            key,
            color,
            size,
            qty,
        ]

        error = None
        latency = 0.0
        try:
            start_time = time.time()
            session.execute(query, params)
        except Exception as e:
            error = str(e)
            print error
        finally:
            latency = time.time() - start_time
            rw.writerow(['insert', key, latency, str(error)])
コード例 #4
0
def create_cluster():
    user = conf.cassandra.user
    if user:
        auth_provider = PlainTextAuthProvider(username=user,
                                              password=conf.cassandra.password)
    else:
        auth_provider = None

    cluster = Cluster(
        conf.cassandra.contact_points,
        port=conf.cassandra.port,
        auth_provider=auth_provider,
        connect_timeout=conf.cassandra.connection_timeout,
        load_balancing_policy=TokenAwarePolicy(
            DCAwareRoundRobinPolicy(
                local_dc=conf.cassandra.local_data_center)),
    )
    cluster.default_retry_policy = MonascaRetryPolicy(
        1, conf.cassandra.max_write_retries, conf.cassandra.max_write_retries)
    return cluster