Last active
April 23, 2016 07:27
-
-
Save krazybean/8790a2acf68e1480e1d7b639e0b382ca to your computer and use it in GitHub Desktop.
rethinkdb benchmark test
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
| # -*- coding: utf-8 -*- | |
| import rethinkdb as r | |
| from time import sleep | |
| from threading import Thread | |
| import prctl | |
| import datetime | |
| import commands | |
| RETHINK_HOST = 'rethink_vm_host' | |
| # Create db | |
| # r.db("test").table_create("bench_testing").run() | |
| MAX_THREADS = 20 | |
| CON_INSERTS_MAX = 100 | |
| SLEEP = 5 | |
| def is_running(process='rethink_benchtest.py'): | |
| """ check if process still running """ | |
| cmd = "ps -eLF | grep {0} | grep -v grep | wc -l ".format(process) | |
| out = commands.getoutput(cmd) | |
| if int(out) > 1: | |
| return True | |
| return False | |
| def inserts(count=0): | |
| """ handles x volume of inserts """ | |
| prctl.set_name("rethinkdb thread") | |
| example = [{"name": "William Adama", | |
| "tv_show": "Battlestar Galactica", | |
| "posts": [{"title": "Decommissioning speech", | |
| "content": "The Cylon War is long over..."}, | |
| {"title": "We are at war", | |
| "content": "Moments ago, this ship received..."}, | |
| {"title": "The new Earth", | |
| "content": "The discoveries of the past few days..."} | |
| ]}, | |
| {"name": "Laura Roslin", | |
| "tv_show": "Battlestar Galactica", | |
| "posts": [{"title": "The oath of office", | |
| "content": "I, Laura Roslin, ..."}, | |
| {"title": "They look like us", | |
| "content": "The Cylons have the ability..."}]}, | |
| {"name": "Jean-Luc Picard", | |
| "tv_show": "Star Trek TNG", | |
| "posts": [{"title": "Civil rights", | |
| "content": "There are some words I've known..."}]}] | |
| for x in xrange(count): | |
| if count == 0: | |
| continue | |
| r.connect(RETHINK_HOST, 28015).repl() | |
| r.table("bench_testing").insert(example).run() | |
| def spawn(threads=0): | |
| """ initiate inserts """ | |
| count = CON_INSERTS_MAX | |
| print "[Spawning] => {0} threads".format(threads) | |
| for thread in xrange(threads): | |
| print "[Insert] => {0} concurrent inserts started.".format(count) | |
| t = Thread(target=inserts, args=(count,)) | |
| t.start() | |
| for thread in xrange(MAX_THREADS): | |
| if is_running(): | |
| print "[Sleeping] => {0} seconds (waiting for threads...)".format(SLEEP) | |
| sleep(SLEEP) | |
| else: | |
| start_time = datetime.datetime.now() | |
| spawn(thread) | |
| stop_time = datetime.datetime.now() | |
| diff_time = stop_time - start_time | |
| print "[Results] => [{0}s] - [{1}ns]".format(diff_time.seconds, | |
| diff_time.microseconds) |
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
| $ python rethink_benchtest.py | |
| [Spawning] => 0 threads | |
| [Results] => [0s] - [374µs] | |
| [Spawning] => 1 threads | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [2516µs] | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Spawning] => 3 threads | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [8832µs] | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| 5 threads | |
| ts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [19318µs] | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Spawning] => 7 threads | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [36749µs] | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Spawning] => 10 threads | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [47613µs] | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Spawning] => 13 threads | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [76909µs] | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Spawning] => 16 threads | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [200911µs] | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Sleeping] => 5 seconds (waiting for threads...) | |
| [Spawning] => 19 threads | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Insert] => 100 concurrent inserts started. | |
| [Results] => [0s] - [199696µs] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment