From a38865682b3b92fd33bc8b7aff36d88360c7928c Mon Sep 17 00:00:00 2001 From: Holger <holger@nahrstaedt.de> Date: Sat, 23 Jun 2018 16:04:10 +0200 Subject: [PATCH] Use thread_num - 1 instances for blocks with threading --- beem/blockchain.py | 4 +-- examples/stream_threading_performance.py | 32 +++++++++++++----------- tests/beem/test_account.py | 4 +-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/beem/blockchain.py b/beem/blockchain.py index 9c35a6a3..60b96199 100644 --- a/beem/blockchain.py +++ b/beem/blockchain.py @@ -397,9 +397,9 @@ class Blockchain(object): elif threading: pool = Pool(thread_num, batch_mode=True) if threading: - steem_instance = [] + steem_instance = [self.steem] nodelist = self.steem.rpc.nodes.export_working_nodes() - for i in range(thread_num): + for i in range(thread_num - 1): steem_instance.append(stm.Steem(node=nodelist, num_retries=self.steem.rpc.num_retries, num_retries_call=self.steem.rpc.num_retries_call, diff --git a/examples/stream_threading_performance.py b/examples/stream_threading_performance.py index 6ede2a88..bdf170c6 100644 --- a/examples/stream_threading_performance.py +++ b/examples/stream_threading_performance.py @@ -37,26 +37,28 @@ if __name__ == "__main__": thread_num = 8 timeout = 10 nodes = NodeList() - nodes.update_nodes() - node_list = nodes.get_nodes() + nodes.update_nodes(weights={"block": 1}) + node_list_wss = nodes.get_nodes(wss=False)[:5] + node_list_https = nodes.get_nodes(https=False)[:5] vote_result = [] duration = [] - stm = Steem(node=node_list, timeout=timeout) - print("Without threading") - stream_votes(stm, False, 8) + stm_wss = Steem(node=node_list_wss, timeout=timeout) + stm_https = Steem(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 wss") + 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) - for n in range(len(node_list)): - print("\n Round %d / %d" % (n, len(node_list))) - stm = Steem(node=node_list, timeout=timeout) - print(stm) - opcount, total_duration = stream_votes(stm, threading, thread_num) - vote_result.append(opcount) - duration.append(total_duration) - node_list = node_list[1:] + [node_list[0]] + stm = Steem(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!") - for n in range(len(node_list)): - print(" votes: %d, time %.2f" % (vote_result[n], duration[n])) + print("Results:") + print("No Threads with wss duration: %.2f s - votes: %d" % (total_duration_wot_wss, opcount_wot_wss)) + print("No Threads with https duration: %.2f s - votes: %d" % (total_duration_wot_https, opcount_wot_https)) + print("%d Threads with wss duration: %.2f s - votes: %d" % (thread_num, total_duration_wss, opcount_wss)) + print("%d Threads with https duration: %.2f s - votes: %d" % (thread_num, total_duration_https, opcount_https)) diff --git a/tests/beem/test_account.py b/tests/beem/test_account.py index 6045aef2..17965d59 100644 --- a/tests/beem/test_account.py +++ b/tests/beem/test_account.py @@ -207,7 +207,7 @@ class Testcases(unittest.TestCase): stm = self.appbase account = Account("gtg", steem_instance=stm) h_list = [] - max_index = account.virtual_op_count() - 1 + max_index = account.virtual_op_count() - 100 for h in account.history(start=max_index - 4, stop=max_index, use_block_num=False, batch_size=2, raw_output=False): h_list.append(h) self.assertEqual(len(h_list), 5) @@ -246,7 +246,7 @@ class Testcases(unittest.TestCase): stm = self.appbase account = Account("gtg", steem_instance=stm) h_list = [] - max_index = account.virtual_op_count() - 1 + max_index = account.virtual_op_count() - 100 for h in account.history_reverse(start=max_index, stop=max_index - 4, use_block_num=False, batch_size=2, raw_output=False): h_list.append(h) self.assertEqual(len(h_list), 5) -- GitLab