示例#1
0
def worker(i):
    print "worker", i

    server_pool = pools.Pool(create=lambda: couchdb.Server(options.COUCHDB_URI), max_size=15)

    with server_pool.item() as server:
        while True:
            db = common.get_db(server, "app2")
            uuids = common.UUIDsIterator(server)

            print "worker", i, "create"
            common.create_docs(db, options.NUM_DOCS, uuids)
            eventlet.sleep(random.uniform(0.1, 3))

            # Delete some random docs
            common.delete_random(db, common.random_rows(db, 10), i)
            eventlet.sleep(random.uniform(0.1, 3))
示例#2
0
def main():
    # wait for couchdb to start
    time.sleep(2)

    couch = couchdb.Server(options.COUCHDB_URI)
    db = common.get_db(couch, 'app1')

    uuids = common.UUIDsIterator(couch)

    while True:
        # Create docs until there are options.NUM_DOCS docs in the DB
        print 'Create docs'
        common.create_docs(db, options.NUM_DOCS, uuids)
        time.sleep(2)

        # Delete some random docs
        common.delete_random(db, common.random_rows(db, 10), 1)
        time.sleep(2)
示例#3
0
def main():
    # wait for couchdb to start
    time.sleep(2)

    server_pool = pools.Pool(create=lambda: couchdb.Server(options.COUCHDB_URI), max_size=15)

    print 'create db'
    with server_pool.item() as server:
        db = common.get_db(server, 'app3')

        ctx = zmq.Context()

        skt = ctx.socket(zmq.XREP)
        skt.bind("inproc://#1")

        for i in range(10):
            eventlet.spawn_n(worker, ctx, i)

        while True:
            msg = skt.recv_multipart()
            addrs, bodies = split_multipart(msg)
            rows = map(json.loads, bodies)
            common.delete_random(db, rows, 0)