Esempio n. 1
0
        def runtime_space():
            db = bigdick.DB(db_direction=tmp_dir,
                            cache_size=cache_sizes[i],
                            cache_duration=10.0)
            tmp_dict = dict()

            def update():
                before = time.time()
                for _ in range(ops_write):
                    key, value = random.randrange(0xFF), random.randrange(
                        0xFFFF_FFFF)
                    tmp_dict[key] = value
                    db.update(key, value)
                after = time.time()
                print('cache_size: {}, Update QPS: {:.2f}'.format(
                    cache_sizes[i], ops_write / (after - before + 1e-3)))

            update()

            def get():
                keys = [random.randrange(0xFF) for _ in range(ops_read)]
                before = time.time()
                for key in keys:
                    value_1 = tmp_dict[key]
                    value_2 = db.get(key)
                    assert value_1 == value_2
                after = time.time()
                print('cache_size: {}, Get QPS: {:.2f}'.format(
                    cache_sizes[i], ops_read / (after - before + 1e-3)))

            get()
            db.stop()
Esempio n. 2
0
    def runtime_space_1():
        db = bigdick.DB(db_direction=tmp_dir,
                        cache_size=cache_size,
                        cache_duration=10.0)

        def update():
            for _ in range(ops_write):
                key, value = random.randrange(0xFF), random.randrange(
                    0xFFFF_FFFF)
                tmp_dict[key] = value
                db.update(key, value)
            print('{} write options finished'.format(ops_write))

        update()

        def get():
            keys = [random.randrange(0xFF) for _ in range(ops_read)]
            for key in keys:
                value_1 = tmp_dict[key]
                value_2 = db.get(key)
                assert value_1 == value_2
            print('{} read options finished'.format(ops_read))

        get()
        db.stop()
Esempio n. 3
0
    def runtime_space():
        db = bigdick.DB(db_direction=tmp_dir,
                        cache_size=cache_size,
                        cache_duration=10.0)

        def update():
            for _ in range(ops_write):
                key, value = random.randrange(0xFF), random.randrange(
                    0xFFFF_FFFF)
                db.update(key, value)

        ts = [threading.Thread(target=update) for _ in range(n_threads)]
        before = time.time()
        _, _ = [t.start() for t in ts], [t.join() for t in ts]
        after = time.time()
        print('cache_size: {}, Update QPS: {:.2f}'.format(
            cache_size, n_threads * ops_write / (after - before + 1e-3)))

        def get():
            for _ in range(ops_read):
                key = random.randrange(0xFF)
                db.get(key)

        ts = [threading.Thread(target=get) for _ in range(n_threads)]
        before = time.time()
        _, _ = [t.start() for t in ts], [t.join() for t in ts]
        after = time.time()
        print('cache_size: {}, Get QPS: {:.2f}'.format(
            cache_size, n_threads * ops_read / (after - before + 1e-3)))
        db.stop()
Esempio n. 4
0
    def runtime_space():
        db = bigdick.DB(db_direction=tmp_dir,
                        cache_size=cache_size,
                        cache_duration=2.5)

        def update():
            before = time.time()
            for _ in range(ops_write):
                key = random.randrange(0xFF)
                db.update(key, value)
            after = time.time()
            print('cache_size: {}, Update QPS: {:.2f}'.format(
                cache_size, ops_write / (after - before + 1e-3)))

        update()
        time.sleep(5.0)  # wait cache freed

        def get():
            keys = [
                random.randrange(0x33)
                if random.random() < 0.8 else random.randrange(0x33, 0xFF)
                for _ in range(ops_read)
            ]
            before = time.time()
            for key in keys:
                db.get(key)
            after = time.time()
            print('cache_size: {}, Get QPS: {:.2f}'.format(
                cache_size, ops_read / (after - before + 1e-3)))

        get()
        db.stop()