Skip to content

Commit

Permalink
Remove statistics dependency, format benchmark output as RST
Browse files Browse the repository at this point in the history
  • Loading branch information
grantjenks committed Feb 25, 2016
1 parent 4b4b7fb commit 43f3613
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 72 deletions.
8 changes: 3 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,16 @@ TODO
TODO
----

0. Remove statistics dependency
Add new column "total" for each action in benchmarks
Output in RST format
Fanout should record count of timeouts
0. Move db.sqlite3
Publish benchmark results
procs, range, limit, warmup options
publish procs=1, procs=8
publish Cache and FanoutCache
Move db.sqlite3
Add FanoutCache / CacheShard
Support TIMEOUT = 1 and have `set` and `delete` return True/False on success/failure
Add try/except to `get`, `set`, `delete`
Fanout should record count of timeouts

1. Create and test CLI interface.

- get, set, store, delete, expire, clear, evict, path, check, stats, show
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mock==1.3.0
nose==1.3.7
statistics==1.0.3.5
django==1.9.2
36 changes: 5 additions & 31 deletions tests/benchmark_test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
else:
import pickle

from utils import percentile, secs
from utils import display

PROCS = 1
RANGE = 100
Expand Down Expand Up @@ -100,7 +100,7 @@ def worker(num, kind, args, kwargs):

obj = kind(*args, **kwargs)

timings = {'get': [], 'set': [], 'del': []}
timings = {'get': [], 'set': [], 'delete': []}

for count in range(LIMIT):
key = str(random.randrange(RANGE)).encode('utf-8')
Expand All @@ -121,7 +121,7 @@ def worker(num, kind, args, kwargs):
start = time.time()
obj.delete(key)
end = time.time()
action = 'del'
action = 'delete'

if count > WARMUP:
timings[action].append(end - start)
Expand Down Expand Up @@ -156,7 +156,7 @@ def dispatch():
for process in processes:
process.join()

timings = {'get': [], 'set': [], 'del': []}
timings = {'get': [], 'set': [], 'delete': []}

for num in range(PROCS):
filename = 'output-%d.pkl' % num
Expand All @@ -169,33 +169,7 @@ def dispatch():

os.remove(filename)

template = '%10s,%10s,%10s,%10s,%10s,%10s,%10s,%10s'

print('Timings results for', name)

print(template % ('op', 'count', 'min', 'p50', 'p90', 'p99', 'p999', 'max'))

total = 0

for action in ['get', 'set', 'del']:
values = timings[action]
total += sum(values)

if len(values) == 0:
values = (0,)

print(template % (
action,
len(values),
secs(percentile(values, 0.0)),
secs(percentile(values, 0.5)),
secs(percentile(values, 0.9)),
secs(percentile(values, 0.99)),
secs(percentile(values, 0.999)),
secs(percentile(values, 1.0)),
))

print('Total operations time: %.3f seconds' % total)
display(name, timings)
print()
time.sleep(1)

Expand Down
41 changes: 7 additions & 34 deletions tests/stress_test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import random
import shutil
import statistics
import sys
import threading
import time
Expand All @@ -28,7 +27,7 @@
else:
import pickle

from utils import percentile, secs
from utils import display

OPERATIONS = int(1e4)
GET_AVERAGE = 100
Expand Down Expand Up @@ -118,7 +117,7 @@ def key_ops():
for _ in range(int(random.expovariate(1.0 / GET_AVERAGE))):
yield 'get', key, value
if random.random() < DEL_CHANCE:
yield 'del', key, None
yield 'delete', key, None


def all_ops():
Expand All @@ -130,7 +129,7 @@ def all_ops():


def worker(queue, eviction_policy):
timings = {'get': [], 'set': [], 'del': []}
timings = {'get': [], 'set': [], 'delete': []}
cache = Cache('tmp', eviction_policy=eviction_policy)

for index, (action, key, value) in enumerate(iter(queue.get, None)):
Expand All @@ -141,7 +140,7 @@ def worker(queue, eviction_policy):
elif action == 'get':
result = cache.get(key)
else:
assert action == 'del'
assert action == 'delete'
cache.delete(key)

stop = time.time()
Expand Down Expand Up @@ -185,7 +184,7 @@ def dispatch(num, eviction_policy):

stop = time.time()

timings = {'get': [], 'set': [], 'del': [], 'self': (stop - start)}
timings = {'get': [], 'set': [], 'delete': [], 'self': (stop - start)}

for thread_queue in thread_queues:
data = thread_queue.get()
Expand Down Expand Up @@ -244,7 +243,7 @@ def stress_test(create=True, delete=True, eviction_policy=u'least-recently-store
with Cache('tmp') as cache:
cache.check()

timings = {'get': [], 'set': [], 'del': [], 'self': 0.0}
timings = {'get': [], 'set': [], 'delete': [], 'self': 0.0}

for num in range(PROCESSES):
with open('output-%s.pkl' % num, 'rb') as reader:
Expand All @@ -257,33 +256,7 @@ def stress_test(create=True, delete=True, eviction_policy=u'least-recently-store
os.remove('input-%s.pkl' % num)
os.remove('output-%s.pkl' % num)

template = '%10s,%10s,%10s,%10s,%10s,%10s,%10s,%10s,%10s'

print(template % ('op', 'count', 'mean', 'std', 'min', 'p50', 'p90', 'p99', 'max'))

total = 0

for action in ['get', 'set', 'del']:
values = timings[action]
total += sum(values)

if len(values) == 0:
values = (0,)

print(template % (
action,
len(values),
secs(statistics.mean(values)),
secs(statistics.pstdev(values)),
secs(percentile(values, 0.0)),
secs(percentile(values, 0.5)),
secs(percentile(values, 0.9)),
secs(percentile(values, 0.99)),
secs(percentile(values, 1.0)),
))

print('Total operations time: %.3f seconds' % total)
print('Total process time: %.3f seconds' % timings['self'])
display(eviction_policy, timings)

shutil.rmtree('tmp', ignore_errors=True)

Expand Down
34 changes: 34 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,37 @@ def retry(sql, query):

del error


def display(name, timings):
cols = ('Action', 'Count', 'Min', 'P50', 'P90', 'P99', 'P999', 'Max', 'Total')
template = ' '.join(['%10s'] * len(cols))

print()
print(' '.join(['=' * 10] * len(cols)))
print('Timings for %s' % name)
print('--'.join(['-' * 10] * len(cols)))
print(template % cols)
print(' '.join(['=' * 10] * len(cols)))

len_total = sum_total = 0

for action in ['get', 'set', 'delete']:
values = timings[action]
len_total += len(values)
sum_total += sum(values)

print(template % (
action,
len(values),
secs(percentile(values, 0.0)),
secs(percentile(values, 0.5)),
secs(percentile(values, 0.9)),
secs(percentile(values, 0.99)),
secs(percentile(values, 0.999)),
secs(percentile(values, 1.0)),
secs(sum(values)),
))

totals = ('Total', len_total, '', '', '', '', '', '', secs(sum_total))
print(template % totals)
print()
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ envlist=py27,py34,py35
[testenv]
deps=nose
mock
statistics
django
commands=nosetests

0 comments on commit 43f3613

Please sign in to comment.