Exemple #1
0
def main2(reactor):
    dbpath = '/tmp/zlmdb1'

    print('Using database directory {}'.format(dbpath))

    schema = UsersSchema()

    with zlmdb.Database(dbpath) as db:

        N = 1000
        with db.begin() as txn:
            cnt_begin = schema.tab_oid_fbs.count(txn)

        stats = zlmdb.TransactionStats()

        with db.begin(write=True, stats=stats) as txn:
            for i in range(N):
                user = UserFbs.create_test_user()
                schema.tab_oid_fbs[txn, user.oid] = user

        assert stats.puts == N
        assert stats.dels == 0
        stats.reset()

        with db.begin() as txn:
            cnt_end = schema.tab_oid_fbs.count(txn)

        cnt = cnt_end - cnt_begin
        assert cnt == N

        print('{} records written, {} records total'.format(cnt, cnt_end))

    yield util.sleep(1)
def test_pmap_flatbuffers_count():
    with TemporaryDirectory() as dbpath:
        print('Using temporary directory {} for database'.format(dbpath))

        schema = UsersSchema()

        # max DB size is 100 MB
        with zlmdb.Database(dbpath, maxsize=100 * (2**20)) as db:

            oids = set()
            oid_to_referred_by = {}

            stats = zlmdb.TransactionStats()

            # number of transactions
            M = 5

            # number of insert rows per transaction
            N = 10000
            for j in range(M):
                with db.begin(write=True, stats=stats) as txn:
                    for i in range(N):
                        user = User.create_test_user()
                        schema.tab_oid_fbs[txn, user.oid] = user
                        oids.add(user.oid)
                        oid_to_referred_by[user.oid] = user.referred_by

                assert stats.puts == N
                assert stats.dels == 0
                duration_ns = stats.duration
                duration_ms = int(duration_ns / 1000000.)
                rows_per_sec = int(round(float(stats.puts + stats.dels) * 1000. / float(duration_ms)))
                print('Transaction ended: puts={} / dels={} rows in {} ms, {} rows/sec'.format(
                    stats.puts, stats.dels, duration_ms, rows_per_sec))

                stats.reset()

            # count all rows
            with db.begin() as txn:
                cnt = schema.tab_oid_fbs.count(txn)

            assert cnt == N * M

            # retrieve
            with db.begin() as txn:
                for j in range(5):
                    started = zlmdb.walltime()
                    M = 100
                    for i in range(M):
                        for oid in random.sample(oids, N):
                            user = schema.tab_oid_fbs[txn, oid]
                            assert user
                            assert user.referred_by == oid_to_referred_by.get(oid, None)
                    duration_ns = zlmdb.walltime() - started
                    duration_ms = int(duration_ns / 1000000.)
                    rows_per_sec = int(round(float(M * N) * 1000. / float(duration_ms)))
                    print('Transaction ended: {} rows read in {} ms, {} rows/sec'.format(
                        M * N, duration_ms, rows_per_sec))
def test_pmap_flatbuffers_values():
    with TemporaryDirectory() as dbpath:
        print('Using temporary directory {} for database'.format(dbpath))

        schema = UsersSchema()

        with zlmdb.Database(dbpath) as db:

            N = 100
            stats = zlmdb.TransactionStats()

            with db.begin(write=True, stats=stats) as txn:
                for i in range(N):
                    user = User.create_test_user()
                    schema.tab_oid_fbs[txn, user.oid] = user

            assert stats.puts == N
            assert stats.dels == 0
            stats.reset()

            with db.begin() as txn:
                cnt = schema.tab_oid_fbs.count(txn)

            assert cnt == N
def _serializer_run_fbs():
    serialize = _TEST['serializer']._serialize_value
    user = UserFbs.create_test_user()
    data = serialize(user)
    _TEST['bytes'] += len(data)