| 1 |
|
|---|
| 2 |
from time import time |
|---|
| 3 |
import sys |
|---|
| 4 |
from os.path import realpath, pardir, dirname, join |
|---|
| 5 |
sys.path.insert(0, realpath(join(dirname(__file__), '..', '..'))) |
|---|
| 6 |
|
|---|
| 7 |
import lightcloud |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
LIGHT_CLOUD = { |
|---|
| 11 |
'lookup1_A': [ '127.0.0.1:10000' ], |
|---|
| 12 |
'storage1_A': [ '127.0.0.1:12000'] |
|---|
| 13 |
} |
|---|
| 14 |
lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD) |
|---|
| 15 |
lightcloud.init(lookup_nodes, storage_nodes, node_type=lightcloud.RedisNode, system='redis') |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
LIGHT_CLOUD = { |
|---|
| 19 |
'lookup1_A': [ '127.0.0.1:41201', '127.0.0.1:51201' ], |
|---|
| 20 |
'storage1_A': [ '127.0.0.1:44201', '127.0.0.1:54201' ] |
|---|
| 21 |
} |
|---|
| 22 |
lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD) |
|---|
| 23 |
lightcloud.init(lookup_nodes, storage_nodes, node_type=lightcloud.TyrantNode, system='tyrant') |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
def generic_bench(name, times_run, fn): |
|---|
| 28 |
start = time() |
|---|
| 29 |
for i in range(0, times_run): |
|---|
| 30 |
fn() |
|---|
| 31 |
end = time()-start |
|---|
| 32 |
pr_sec = float(times_run)/end |
|---|
| 33 |
print 'Finished "%s" %s times in %0.2f sec [%0.1f operations pr.sec]' %\ |
|---|
| 34 |
(name, times_run, end, pr_sec) |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
generic_bench('Tyrant set', 10000, |
|---|
| 39 |
lambda: lightcloud.set('hello', 'world', system='tyrant')) |
|---|
| 40 |
generic_bench('Redis set', 10000, |
|---|
| 41 |
lambda: lightcloud.set('hello', 'world', system='redis')) |
|---|
| 42 |
|
|---|
| 43 |
print '------' |
|---|
| 44 |
|
|---|
| 45 |
generic_bench('Tyrant get', 10000, |
|---|
| 46 |
lambda: lightcloud.get('hello', system='tyrant')) |
|---|
| 47 |
generic_bench('Redis get', 10000, |
|---|
| 48 |
lambda: lightcloud.get('hello', system='redis')) |
|---|
| 49 |
|
|---|
| 50 |
print '------' |
|---|
| 51 |
|
|---|
| 52 |
generic_bench('Tyrant list_add', 10000, |
|---|
| 53 |
lambda: lightcloud.list_add('hello_l', ['1'], system='tyrant')) |
|---|
| 54 |
generic_bench('Redis list_add', 10000, |
|---|
| 55 |
lambda: lightcloud.list_add('hello_l', ['1'], system='redis')) |
|---|
| 56 |
|
|---|
| 57 |
print '------' |
|---|
| 58 |
|
|---|
| 59 |
generic_bench('Tyrant delete', 10000, |
|---|
| 60 |
lambda: lightcloud.delete('hello', system='tyrant')) |
|---|
| 61 |
generic_bench('Redis delete', 10000, |
|---|
| 62 |
lambda: lightcloud.delete('hello', system='redis')) |
|---|