def profiling(name_list): stm = DPay() set_shared_dpay_instance(stm) del stm print("start") for name in name_list: print("account: %s" % (name)) acc = Account(name) max_index = acc.virtual_op_count() print(max_index) stopTime = datetime(2018, 4, 22, 0, 0, 0) hist_elem = None for h in acc.history_reverse(stop=stopTime): hist_elem = h print(hist_elem) print("blockchain") blockchain_object = Blockchain() current_num = blockchain_object.get_current_block_num() startBlockNumber = current_num - 20 endBlockNumber = current_num block_elem = None for o in blockchain_object.stream(start=startBlockNumber, stop=endBlockNumber): print("block %d" % (o["block_num"])) block_elem = o print(block_elem)
def setup(self): self.prefix = u"BEX" self.default_prefix = u"DWB" self.wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" self.ref_block_num = 34294 self.ref_block_prefix = 3707022213 self.expiration = "2016-04-06T08:29:27" self.stm = DPay(offline=True)
def profiling(node, name_list, shared_instance=True, clear_acc_cache=False, clear_all_cache=True): print("shared_instance %d clear_acc_cache %d clear_all_cache %d" % (shared_instance, clear_acc_cache, clear_all_cache)) if not shared_instance: stm = DPay(node=node) print(str(stm)) else: stm = None acc_dict = {} for name in name_list: acc = Account(name, dpay_instance=stm) acc_dict[name] = acc if clear_acc_cache: acc.clear_cache() acc_dict = {} if clear_all_cache: clear_cache() if not shared_instance: del stm.rpc
return opcount, total_duration if __name__ == "__main__": node_setup = 1 threading = True thread_num = 8 timeout = 10 nodes = NodeList() nodes.update_nodes(weights={"block": 1}) node_list = nodes.get_nodes()[:5] vote_result = [] duration = [] stm = DPay(node=node_list, timeout=timeout) b = Blockchain(dpay_instance=stm) block = b.get_current_block() block.set_cache_auto_clean(False) opcount, total_duration = stream_votes(stm, threading, thread_num) print("Finished!") block.set_cache_auto_clean(True) cache_len = len(list(block._cache)) start_time = time.time() block.clear_cache_from_expired_items() clear_duration = time.time() - start_time time.sleep(5) cache_len_after = len(list(block._cache)) start_time = time.time() print(str(block._cache)) clear_duration2 = time.time() - start_time
if __name__ == "__main__": how_many_minutes = 10 how_many_virtual_op = 10000 max_batch_size = None threading = False thread_num = 16 nodelist = NodeList() nodes = nodelist.get_nodes(normal=True, appbase=True, dev=True) t = PrettyTable([ "node", "10 blockchain minutes", "10000 virtual account op", "version" ]) t.align = "l" for node in nodes: print("Current node:", node) try: stm = DPay(node=node, num_retries=3) blockchain = Blockchain(dpay_instance=stm) account = Account("gtg", dpay_instance=stm) virtual_op_count = account.virtual_op_count() blockchain_version = stm.get_blockchain_version() last_block_id = 19273700 last_block = Block(last_block_id, dpay_instance=stm) startTime = datetime.now() stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60) ltime = time.time() cnt = 0 total_transaction = 0
stm = None acc_dict = {} for name in name_list: acc = Account(name, dpay_instance=stm) acc_dict[name] = acc if clear_acc_cache: acc.clear_cache() acc_dict = {} if clear_all_cache: clear_cache() if not shared_instance: del stm.rpc if __name__ == "__main__": stm = DPay() print("Shared instance: " + str(stm)) set_shared_dpay_instance(stm) b = Blockchain() account_list = [] for a in b.get_all_accounts(limit=500): account_list.append(a) shared_instance = False clear_acc_cache = False clear_all_cache = False node = "wss://dpayd.dpays.io" n = 3 for i in range(1, n + 1): print("%d of %d" % (i, n)) profiling(node, account_list,
def benchmark_node(node, how_many_minutes=10, how_many_seconds=30): block_count = 0 history_count = 0 access_time = 0 follow_time = 0 blockchain_version = u'0.0.0' successful = True error_msg = None start_total = timer() max_batch_size = None threading = False thread_num = 16 authorpermvoter = u"@jared/dpay-pressure-4-need-for-speed|nomoreheroes" [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter) authorperm = construct_authorperm(author, permlink) last_block_id = 19273700 try: stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30) blockchain = Blockchain(dpay_instance=stm) blockchain_version = stm.get_blockchain_version() last_block = Block(last_block_id, dpay_instance=stm) stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60) total_transaction = 0 start = timer() for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num): block_no = entry.identifier block_count += 1 if "block" in entry: trxs = entry["block"]["transactions"] else: trxs = entry["transactions"] for tx in trxs: for op in tx["operations"]: total_transaction += 1 if "block" in entry: block_time = parse_time(entry["block"]["timestamp"]) else: block_time = parse_time(entry["timestamp"]) if block_time > stopTime: last_block_id = block_no break if timer() - start > how_many_seconds or quit_thread: break except NumRetriesReached: error_msg = 'NumRetriesReached' block_count = -1 except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' # quit = True except Exception as e: error_msg = str(e) block_count = -1 try: stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30) account = Account("gtg", dpay_instance=stm) blockchain_version = stm.get_blockchain_version() start = timer() for acc_op in account.history_reverse(batch_size=100): history_count += 1 if timer() - start > how_many_seconds or quit_thread: break except NumRetriesReached: error_msg = 'NumRetriesReached' history_count = -1 successful = False except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' history_count = -1 successful = False # quit = True except Exception as e: error_msg = str(e) history_count = -1 successful = False try: stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30) account = Account("gtg", dpay_instance=stm) blockchain_version = stm.get_blockchain_version() start = timer() Vote(authorpermvoter, dpay_instance=stm) stop = timer() vote_time = stop - start start = timer() Comment(authorperm, dpay_instance=stm) stop = timer() comment_time = stop - start start = timer() Account(author, dpay_instance=stm) stop = timer() account_time = stop - start start = timer() account.get_followers() stop = timer() follow_time = stop - start access_time = (vote_time + comment_time + account_time + follow_time) / 4.0 except NumRetriesReached: error_msg = 'NumRetriesReached' access_time = -1 except KeyboardInterrupt: error_msg = 'KeyboardInterrupt' # quit = True except Exception as e: error_msg = str(e) access_time = -1 return { 'successful': successful, 'node': node, 'error': error_msg, 'total_duration': timer() - start_total, 'block_count': block_count, 'history_count': history_count, 'access_time': access_time, 'follow_time': follow_time, 'version': blockchain_version }
quit_thread = True print("benchmark aborted.") else: for node in nodes: print("Current node:", node) result = benchmark_node(node, how_many_minutes, how_many_seconds) results.append(result) for result in results: t2.add_row([result["node"], result["version"]]) print(t2) print("\n") sortedList = sorted(results, key=lambda self: self["history_count"], reverse=True) for result in sortedList: if result["successful"]: t.add_row([ result["node"], result["block_count"], result["history_count"], ("%.2f" % (result["access_time"])) ]) working_nodes.append(result["node"]) print(t) print("\n") print("Total benchmark time: %.2f s\n" % (timer() - benchmark_time)) if set_default_nodes: stm = DPay(offline=True) stm.set_default_nodes(working_nodes) else: print("dpay set nodes " + str(working_nodes))
return opcount, total_duration if __name__ == "__main__": node_setup = 1 threading = True thread_num = 8 timeout = 10 nodes = NodeList() nodes.update_nodes(weights={"block": 1}) node_list_wss = nodes.get_nodes(https=False)[:5] node_list_https = nodes.get_nodes(wss=False)[:5] vote_result = [] duration = [] stm_wss = DPay(node=node_list_wss, timeout=timeout) stm_https = DPay(node=node_list_https, timeout=timeout) print("Without threading wss") opcount_wot_wss, total_duration_wot_wss = stream_votes(stm_wss, False, 8) print("Without threading https") opcount_wot_https, total_duration_wot_https = stream_votes( stm_https, False, 8) if threading: print("\n Threading with %d threads is activated now." % thread_num) stm = DPay(node=node_list_wss, timeout=timeout) opcount_wss, total_duration_wss = stream_votes(stm, threading, thread_num) opcount_https, total_duration_https = stream_votes(stm, threading, thread_num) print("Finished!")
from __future__ import division from __future__ import print_function from __future__ import unicode_literals from builtins import int, str import sys from datetime import timedelta import time import io from dpaygo.dpay import DPay import logging from prettytable import PrettyTable log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) if __name__ == "__main__": stm = DPay(node="wss://dpayd.dpays.io") # stm = DPay(node="wss://appbasetest.timcliff.com") # stm = DPay(node="https://api.dpays.io") # stm = DPay(node="wss://dpayd.dpays.io") all_calls = stm.rpc.get_methods(api="jsonrpc") t = PrettyTable(["method", "args", "ret"]) t.align = "l" t_condenser = PrettyTable(["method", "args", "ret"]) t_condenser.align = "l" for call in all_calls: if "condenser" not in call: ret = stm.rpc.get_signature({'method': call}, api="jsonrpc") t.add_row([call, ret['args'], ret['ret']]) else: ret = stm.rpc.get_signature({'method': call}, api="jsonrpc") t_condenser.add_row([call, ret['args'], ret['ret']])
dpaygo_times = [] loops = 50 for i in range(0, loops): print(i) opDPay = dpayOperations.Transfer(**{ "from": "foo", "to": "baar", "amount": "111.110 BEX", "memo": "Fooo" }) opDPayGo = operations.Transfer( **{ "from": "foo", "to": "baar", "amount": Amount("111.110 BEX", dpay_instance=DPay(offline=True)), "memo": "Fooo" }) t_s, t_v = dpay_test.doit(ops=opDPay) dpay_times.append([t_s, t_v]) t_s, t_v = dpaygo_test.doit(ops=opDPayGo) dpaygo_times.append([t_s, t_v]) dpay_dt = [0, 0] dpaygo_dt = [0, 0] for i in range(0, loops): dpay_dt[0] += dpay_times[i][0] dpay_dt[1] += dpay_times[i][1] dpaygo_dt[0] += dpaygo_times[i][0]
import logging from dpaygo.blockchain import Blockchain from dpaygo.block import Block from dpaygo.dpay import DPay from dpaygo.utils import parse_time, formatTimedelta from dpaygo.nodelist import NodeList log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) if __name__ == "__main__": node_setup = 1 how_many_hours = 1 nodes = NodeList() if node_setup == 0: stm = DPay(node=nodes.get_nodes(normal=True, wss=True), num_retries=10) max_batch_size = None threading = False thread_num = 8 elif node_setup == 1: stm = DPay(node=nodes.get_nodes(normal=True, wss=True), num_retries=10) max_batch_size = None threading = True thread_num = 16 elif node_setup == 2: stm = DPay(node=nodes.get_nodes(appbase=False, https=False), num_retries=10) max_batch_size = None threading = True thread_num = 16 blockchain = Blockchain(dpay_instance=stm)
import io import logging from dpaygo.blockchain import Blockchain from dpaygo.block import Block from dpaygo.account import Account from dpaygo.amount import Amount from dpaygographenebase.account import PasswordKey, PrivateKey, PublicKey from dpaygo.dpay import DPay from dpaygo.utils import parse_time, formatTimedelta from dpaygoapi.exceptions import NumRetriesReached from dpaygo.nodelist import NodeList log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) if __name__ == "__main__": stm = DPay(node=["https://testnet.dpays.io"], custom_chains={"TESTNETHF20": {'chain_assets': [ {"asset": "@@000000013", "symbol": "BBD", "precision": 3, "id": 0}, {"asset": "@@000000021", "symbol": "BET", "precision": 3, "id": 1}, {"asset": "@@000000037", "symbol": "VESTS", "precision": 6, "id": 2} ], 'chain_id': '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32', 'min_version': '0.20.0', 'prefix': 'DWT'}}) print(stm.get_blockchain_version()) print(stm.get_config()["DPAY_CHAIN_ID"])
from dpaygo.amount import Amount from dpaygographenebase.account import PasswordKey, PrivateKey, PublicKey from dpaygo.dpay import DPay from dpaygo.utils import parse_time, formatTimedelta from dpaygoapi.exceptions import NumRetriesReached from dpaygo.nodelist import NodeList log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) password = "******" username = "******" useWallet = False if __name__ == "__main__": nodelist = NodeList() stm = DPay(node=nodelist.get_nodes(normal=False, appbase=False, testnet=True)) prefix = stm.prefix # curl --data "username=username&password=secretPassword" https://testnet.dpay.vc/create stm.wallet.wipe(True) if useWallet: stm.wallet.create("123") stm.wallet.unlock("123") active_key = PasswordKey(username, password, role="active", prefix=prefix) owner_key = PasswordKey(username, password, role="owner", prefix=prefix) posting_key = PasswordKey(username, password, role="posting", prefix=prefix) memo_key = PasswordKey(username, password, role="memo", prefix=prefix) active_pubkey = active_key.get_public_key() owner_pubkey = owner_key.get_public_key() posting_pubkey = posting_key.get_public_key() memo_pubkey = memo_key.get_public_key() active_privkey = active_key.get_private_key()