Line-length changes, many suggested by @amirelemam in #762

This commit is contained in:
Troy McConaghy 2017-01-22 13:45:17 +01:00
parent e7ffcf5705
commit e253ca015f

View File

@ -31,8 +31,9 @@ def create_write_transaction(tx_left, payload_filler):
if payload_filler:
payload_dict['filler'] = payload_filler
while tx_left > 0:
# Include a random uuid string in the payload to prevent duplicate
# transactions (i.e. transactions with the same hash)
# Include a random uuid string in the payload
# to prevent duplicate transactions
# (i.e. transactions with the same hash)
payload_dict['msg'] = str(uuid.uuid4())
tx = Transaction.create([b.me], [b.me], payload=payload_dict)
tx = tx.sign([b.me_private])
@ -69,22 +70,31 @@ def run_gather_metrics(args):
num_transactions = r.table('backlog').count().run(conn)
num_transactions_received = 0
initial_time = None
logger.info('Starting gathering metrics. {} transasctions in the backlog'.format(num_transactions))
logger.info('Starting gathering metrics.')
logger.info('{} transasctions in the backlog'.format(num_transactions))
logger.info('This process should exit automatically. '
'If this does not happen you can exit at any time using Ctrl-C '
'saving all the metrics gathered up to this point.')
logger.info('\t{:<20} {:<20} {:<20} {:<20}'.format('timestamp', 'tx in block',
'tx/s', '% complete'))
logger.info('\t{:<20} {:<20} {:<20} {:<20}'.format(
'timestamp',
'tx in block',
'tx/s',
'% complete'
))
# listen to the changefeed
try:
for change in r.table('bigchain').changes().run(conn):
# check only for new blocks
if change['old_val'] is None:
block_num_transactions = len(change['new_val']['block']['transactions'])
block_num_transactions = len(
change['new_val']['block']['transactions']
)
time_now = time.time()
csv_writer.writerow([str(time_now), str(block_num_transactions)])
csv_writer.writerow(
[str(time_now), str(block_num_transactions)]
)
# log statistics
if initial_time is None:
@ -92,15 +102,23 @@ def run_gather_metrics(args):
num_transactions_received += block_num_transactions
elapsed_time = time_now - initial_time
percent_complete = round((num_transactions_received / num_transactions) * 100)
percent_complete = round(
(num_transactions_received / num_transactions) * 100
)
if elapsed_time != 0:
transactions_per_second = round(num_transactions_received / elapsed_time)
transactions_per_second = round(
num_transactions_received / elapsed_time
)
else:
transactions_per_second = float('nan')
logger.info('\t{:<20} {:<20} {:<20} {:<20}'.format(time_now, block_num_transactions,
transactions_per_second, percent_complete))
logger.info('\t{:<20} {:<20} {:<20} {:<20}'.format(
time_now,
block_num_transactions,
transactions_per_second,
percent_complete
))
if (num_transactions - num_transactions_received) == 0:
break
@ -118,7 +136,8 @@ def main():
# 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',
backlog_parser.add_argument('num_transactions',
metavar='num_transactions',
type=int, default=0,
help='Number of transactions to add to the backlog')
backlog_parser.add_argument('-s', '--payload-size',
@ -129,7 +148,9 @@ def main():
# set statsd host
statsd_parser = subparsers.add_parser('set-statsd-host',
help='Set statsd host')
statsd_parser.add_argument('statsd_host', metavar='statsd_host', default='localhost',
statsd_parser.add_argument('statsd_host',
metavar='statsd_host',
default='localhost',
help='Hostname of the statsd server')
# metrics
@ -138,7 +159,8 @@ def main():
metrics_parser.add_argument('-b', '--bigchaindb-host',
required=True,
help='Bigchaindb node hostname to connect to gather cluster metrics')
help=('Bigchaindb node hostname to connect '
'to gather cluster metrics'))
metrics_parser.add_argument('-c', '--csvfile',
required=True,
@ -149,4 +171,3 @@ def main():
if __name__ == '__main__':
main()