Added cli to benchmark_utils

This commit is contained in:
Rodolphe Marques 2016-05-10 11:47:49 +02:00
parent 6e285c9510
commit e2fd574c6e
3 changed files with 54 additions and 7 deletions

View File

@ -1,8 +1,13 @@
import sys
import multiprocessing as mp
import uuid
import json
import argparse
from os.path import expanduser
from bigchaindb import Bigchain
from bigchaindb.util import ProcessGroup
from bigchaindb.commands import utils
def create_write_transaction(tx_left):
@ -15,12 +20,40 @@ def create_write_transaction(tx_left):
tx_left -= 1
def add_to_backlog(num_transactions=10000):
tx_left = num_transactions // mp.cpu_count()
def run_add_backlog(args):
tx_left = args.num_transactions // mp.cpu_count()
workers = ProcessGroup(target=create_write_transaction, args=(tx_left,))
workers.start()
if __name__ == '__main__':
add_to_backlog(int(sys.argv[1]))
def run_update_statsd(args):
with open(expanduser('~') + '/.bigchaindb', 'r') as f:
conf = json.load(f)
conf['statsd']['host'] = args.statsd_host
with open(expanduser('~') + '/.bigchaindb', 'w') as f:
json.dump(conf, f)
def main():
parser = argparse.ArgumentParser(description='BigchainDB benchmarking utils')
subparsers = parser.add_subparsers(title='Commands', dest='command')
# add transactions to backlog
backlog_parser = subparsers.add_parser('add-backlog',
help='Add transactions to the backlog')
backlog_parser.add_argument('num_transactions', metavar='num_transactions', type=int, default=0,
help='Number of transactions to add to the backlog')
# update statsd configuration
statsd_parser = subparsers.add_parser('update-statsd',
help='Update statsd host')
statsd_parser.add_argument('statsd_host', metavar='statsd_host', default='localhost',
help='Hostname of the statsd server')
utils.start(parser, globals())
if __name__ == '__main__':
main()

View File

@ -27,13 +27,27 @@ def prepare_test():
put('benchmark_utils.py')
@task
@parallel
def update_statsd_conf(statsd_host='localhost'):
run('python3 benchmark_utils.py update-statsd {}'.format(statsd_host))
print('update configuration')
run('bigchaindb show-config')
@task
@parallel
def prepare_backlog(num_transactions=10000):
run('python3 benchmark_utils.py {}'.format(num_transactions))
run('python3 benchmark_utils.py add-backlog {}'.format(num_transactions))
@task
@parallel
def start_bigchaindb():
run('screen -d -m bigchaindb start &', pty=False)
@task
@parallel
def kill_bigchaindb():
run('killall bigchaindb')

View File

@ -5,4 +5,4 @@ BigchainDB cluster/federation.
from __future__ import unicode_literals
public_dns_names = ['ec2-52-58-162-146.eu-central-1.compute.amazonaws.com', 'ec2-52-58-15-239.eu-central-1.compute.amazonaws.com', 'ec2-52-58-160-205.eu-central-1.compute.amazonaws.com']
public_dns_names = ['ec2-52-58-110-9.eu-central-1.compute.amazonaws.com', 'ec2-52-58-154-94.eu-central-1.compute.amazonaws.com', 'ec2-52-58-166-93.eu-central-1.compute.amazonaws.com']