예제 #1
0
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()
예제 #2
0
 def __setitem__(self, key, value):
     return shmht.setval(self.fd, key, value)
예제 #3
0
 def set(self, key, value):
     return shmht.setval(self.fd, key, value)
예제 #4
0
#!/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)
예제 #5
0
    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)
예제 #6
0
#!/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)
예제 #7
0
 def __setitem__(self, key, value):
     return shmht.setval(self.fd, key, value)
예제 #8
0
 def set(self, key, value):
     return shmht.setval(self.fd, key, value)