def load_it(fd, fname): logger.debug("Reading: %s" % os.path.split(fname)[1]) d = load_dict(fname) lock.acquire() logger.debug("Loading into shared memory: %s" % os.path.split(fname)[1]) for key, value in d.items(): shmht.setval(fd, key, value) logger.debug("Loaded: %s" % os.path.split(fname)[1]) lock.release()
def __setitem__(self, key, value): return shmht.setval(self.fd, key, value)
def set(self, key, value): return shmht.setval(self.fd, key, value)
#!/usr/bin/python #coding: utf-8 import shmht import time capacity = 300000 fd = shmht.open('/dev/shm/test.performance', capacity, 1) begin_time = time.time() for i in range(capacity): s = '%064d' % i shmht.setval(fd, s, s) end_time = time.time() print(capacity / (end_time - begin_time), 'iops @ set') begin_timend_time = time.time() for i in range(capacity): s = '%064d' % i if s != shmht.getval(fd, s): raise Exception(s) end_time = time.time() print(capacity / (end_time - begin_time), 'iops @ get') shmht.close(fd)
try: ident = shmht.open(testfile) except shmht.error as e: pass else: assert False, 'should have raised an exception' with pycode.test('open-init'): ident = shmht.open(testfile, 10) with pycode.test('insert-lookup'): shmht.setval(ident, 'arf', 'data for arf') assert shmht.getval(ident, 'arf') == 'data for arf' shmht.setval(ident, 'narf', 'data for narf') assert shmht.getval(ident, 'narf') == 'data for narf' assert shmht.getval(ident, 'arf') == 'data for arf' assert shmht.getval(ident, 'narf') == 'data for narf' with pycode.test('iter-small'): d = {} def collect(key, value): d[key] = value shmht.foreach(ident, collect)
#!/usr/bin/python #coding: utf-8 import shmht import time capacity = 300000 fd = shmht.open('/dev/shm/test.performance', capacity, 1) begin_time = time.time() for i in range(capacity): s = bytes('%064d' % i, 'ascii') shmht.setval(fd, s, s) end_time = time.time() print(capacity / (end_time - begin_time), 'iops @ set') begin_timend_time = time.time() for i in range(capacity): s = bytes('%064d' % i, 'ascii') if s != shmht.getval(fd, s): raise Exception(s) end_time = time.time() print(capacity / (end_time - begin_time), 'iops @ get') shmht.close(fd)
def __setitem__(self, key, value): return shmht.setval(self.fd, key, value)
def set(self, key, value): return shmht.setval(self.fd, key, value)