def _split_batch_list(batch_list): new_list = [] for batch in batch_list.batches: new_list.append(batch) if len(new_list) == 100: yield batch_pb2.BatchList(batches=new_list) new_list = [] if len(new_list) > 0: yield batch_pb2.BatchList(batches=new_list)
def do_load(args): with open(args.filename) as fd: batches = batch_pb2.BatchList() batches.ParseFromString(fd.read()) stream = Stream(args.url) stream.connect() futures = [] start = time.time() for batch_list in _split_batch_list(batches): future = stream.send(message_type='system/load', content=batch_list.SerializeToString()) futures.append(future) for future in futures: result = future.result() assert result.message_type == 'system/load-response' stop = time.time() print "batches: {} batch/sec: {}".format( str(len(batches.batches)), len(batches.batches) / (stop - start)) stream.close()
def do_populate(args): private_key = bitcoin.random_key() public_key = bitcoin.encode_pubkey(bitcoin.privkey_to_pubkey(private_key), "hex") words = generate_word_list(args.pool_size) batches = [] total_txn_count = 0 txns = [] for i in range(0, len(words)): txn = create_intkey_transaction(verb='set', name=words[i], value=random.randint(9000, 100000), private_key=private_key, public_key=public_key) total_txn_count += 1 txns.append(txn) batch = create_batch(transactions=txns, private_key=private_key, public_key=public_key) batches.append(batch) batch_list = batch_pb2.BatchList(batches=batches) print("Writing to {}...".format(args.output)) with open(args.output, "wb") as fd: fd.write(batch_list.SerializeToString())
def do_generate(args): private_key = pybitcointools.random_key() public_key = pybitcointools.encode_pubkey( pybitcointools.privkey_to_pubkey(private_key), "hex") words = generate_word_list(args.pool_size) batches = [] start = time.time() total_txn_count = 0 for i in xrange(0, args.count): txns = [] for _ in xrange(0, random.randint(1, args.batch_max_size)): txn = create_intkey_transaction( verb=random.choice(['set', 'inc', 'dec']), name=random.choice(words), value=random.randint(0, 100000), private_key=private_key, public_key=public_key) total_txn_count += 1 txns.append(txn) batch = create_batch( transactions=txns, private_key=private_key, public_key=public_key) batches.append(batch) if i % 100 == 0 and i != 0: stop = time.time() txn_count = 0 for batch in batches[-100:]: txn_count += len(batch.transactions) fmt = 'batches {}, batch/sec: {:.2f}, txns: {}, txns/sec: {:.2f}' print fmt.format( str(i), 100 / (stop - start), str(total_txn_count), txn_count / (stop - start)) start = stop batch_list = batch_pb2.BatchList(batches=batches) print "Writing to {}...".format(args.output) with open(args.output, "w") as fd: fd.write(batch_list.SerializeToString())
def _make_inc_dec_file(verbs, words, values, file_name): private_key, public_key = _make_key_pair() txns = [ _create_intkey_transaction(verb=verb, name=word, value=value, private_key=private_key, public_key=public_key) for verb, word, value in zip(verbs, words, values) ] batch = _create_batch(transactions=txns, private_key=private_key, public_key=public_key) batch_list = batch_pb2.BatchList(batches=[batch]) _make_batch_file(batch_list, file_name)
def _make_populate_file(words, values, file_name): private_key, public_key = _make_key_pair() txns = [ _create_intkey_transaction(verb='set', name=word, value=val, private_key=private_key, public_key=public_key) for word, val in zip(words, values) ] batch = _create_batch(transactions=txns, private_key=private_key, public_key=public_key) batch_list = batch_pb2.BatchList(batches=[batch]) _make_batch_file(batch_list, file_name)
def do_load(args): with open(args.filename, mode='rb') as fd: batches = batch_pb2.BatchList() batches.ParseFromString(fd.read()) stream = Stream(args.url) futures = [] start = time.time() for batch_list in _split_batch_list(batches): future = stream.send(message_type=Message.CLIENT_BATCH_SUBMIT_REQUEST, content=batch_list.SerializeToString()) futures.append(future) for future in futures: result = future.result() assert result.message_type == Message.CLIENT_BATCH_SUBMIT_RESPONSE stop = time.time() print("batches: {} batch/sec: {}".format( str(len(batches.batches)), len(batches.batches) / (stop - start))) stream.close()
def do_generate(args): private_key = pybitcointools.random_key() public_key = pybitcointools.encode_pubkey( pybitcointools.privkey_to_pubkey(private_key), "hex") words = generate_word_list(args.pool_size) txns = [] batches = [] bytecode = "" with open(args.contract, "rb") as fd: byte = fd.readline() while byte != "": bytecode += byte byte = fd.readline() byte_addr = get_address("jvm_sc", bytecode) txn = create_jvm_sc_transaction(verb='store', private_key=private_key, public_key=public_key, bytecode=bytecode, methods=["set", "inc", "dec"]) txns.append(txn) keys = [] addresses = [] for i in range(20): if len(txns) < 10: key = random.choice(words) keys.append(key) value = str(random.randint(0, 1000)) key_addr = get_address("intkey", key) addresses.append(key_addr) txn = create_jvm_sc_transaction(verb='run', private_key=private_key, public_key=public_key, byte_addr=byte_addr, method="set", parameters=[ "key," + key, "value," + value, "&check," + key_addr ], addresses=addresses) txns.append(txn) addresses = [] else: batch = create_batch(txns, private_key, public_key) batches.append(batch) txns = [] for i in range(20): if len(txns) < 10: key = random.choice(keys) key_addr = get_address("intkey", key) addresses.append(key_addr) txn = create_jvm_sc_transaction( verb='run', private_key=private_key, public_key=public_key, byte_addr=byte_addr, method=random.choice(["inc", "dec"]), parameters=["key," + key, "&value," + key_addr, "diff,2"], addresses=addresses) txns.append(txn) addresses = [] else: batch = create_batch(txns, private_key, public_key) batches.append(batch) txns = [] batch_list = batch_pb2.BatchList(batches=batches) print "Writing to {}...".format(args.output) with open(args.output, "w") as fd: fd.write(batch_list.SerializeToString())
def write_batch_file(args, batches): batch_list = batch_pb2.BatchList(batches=batches) print("Writing to {}...".format(args.output)) with open(args.output, "wb") as fd: fd.write(batch_list.SerializeToString())