Last active
March 5, 2017 02:42
-
-
Save jtallieu/736a9bf709a51444c26fbc620ef51a4d to your computer and use it in GitHub Desktop.
Gevent scheduling script to determine scheduling algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import gevent | |
import timeit | |
from gevent.event import Event | |
from plotter import graph_latency, graph_ops | |
RUNS = [100, 500, 1000, 5000, 10000, 20000, 30000, 100000] | |
SLEEP_TIME = float(sys.argv[1]) | |
LOAD_TIME = 3 | |
start_event = Event() | |
greenlets = [] | |
counts = [] | |
delays = [] | |
def counter(id): | |
global counts | |
global delays | |
start_event.wait() | |
kick_off = timeit.default_timer() | |
while True: | |
counts[id] += 1 | |
start = timeit.default_timer() | |
gevent.sleep(SLEEP_TIME) | |
end = timeit.default_timer() | |
delay = SLEEP_TIME - (start-end) | |
delays.append(delay) | |
if timeit.default_timer() - kick_off >= LOAD_TIME: | |
return | |
def print_stats(): | |
global counts | |
sums = {} | |
for incs in counts: | |
if incs not in sums: | |
sums[incs] = 0 | |
sums[incs] += 1 | |
from pprint import pprint | |
for ops, green_count in sums.iteritems(): | |
print "{} greenlets -> {} ops".format(green_count, ops) | |
print "Total ops:", sum(counts) | |
def run(threads): | |
print "Running {} threads with {} delay".format(threads, SLEEP_TIME) | |
print "----------------------------------------" | |
start_event.clear() | |
for x in range(0, threads): | |
greenlets.append(gevent.spawn(counter, x)) | |
counts.append(0) | |
start_event.set() | |
gevent.wait(greenlets) | |
if __name__ == "__main__": | |
series = [] | |
for threads in RUNS: | |
run(threads) | |
print_stats() | |
series.append({ | |
'name': "{}".format(threads), | |
'data': delays, | |
'counts': counts, | |
'total_ops': sum(counts) | |
}) | |
greenlets = [] | |
counts = [] | |
delays = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Running 100 threads with 0.0 delay | |
---------------------------------------- | |
70 greenlets -> 6285 ops | |
30 greenlets -> 6286 ops | |
Total ops: 628530 | |
Running 500 threads with 0.0 delay | |
---------------------------------------- | |
201 greenlets -> 1256 ops | |
129 greenlets -> 1257 ops | |
107 greenlets -> 1252 ops | |
63 greenlets -> 1253 ops | |
Total ops: 627512 | |
Running 1000 threads with 0.0 delay | |
---------------------------------------- | |
541 greenlets -> 521 ops | |
459 greenlets -> 522 ops | |
Total ops: 521459 | |
Running 5000 threads with 0.0 delay | |
---------------------------------------- | |
1673 greenlets -> 85 ops | |
3327 greenlets -> 86 ops | |
Total ops: 428327 | |
Running 10000 threads with 0.0 delay | |
---------------------------------------- | |
842 greenlets -> 40 ops | |
1391 greenlets -> 41 ops | |
7767 greenlets -> 39 ops | |
Total ops: 393624 | |
Running 20000 threads with 0.0 delay | |
---------------------------------------- | |
3541 greenlets -> 17 ops | |
7352 greenlets -> 18 ops | |
9107 greenlets -> 19 ops | |
Total ops: 365566 | |
Running 30000 threads with 0.0 delay | |
---------------------------------------- | |
15746 greenlets -> 10 ops | |
14254 greenlets -> 11 ops | |
Total ops: 314254 | |
Running 100000 threads with 0.0 delay | |
---------------------------------------- | |
7733 greenlets -> 2 ops | |
75467 greenlets -> 3 ops | |
16800 greenlets -> 4 ops | |
Total ops: 309067 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment