Skip to content
Snippets Groups Projects
Commit 582f3414 authored by Holger Nahrstaedt's avatar Holger Nahrstaedt
Browse files

Improvements for blockchain parameter reading and nodes benchmark

steem
* Robustify reading of blockchain parameters
utils
* improve formatTimedelta output
Examples
* improve benchmark_nodes by added account history
parent 988ff029
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,8 @@ class Blockchain(object): ...@@ -89,7 +89,8 @@ class Blockchain(object):
.. note:: The block number returned depends on the ``mode`` used .. note:: The block number returned depends on the ``mode`` used
when instanciating from this class. when instanciating from this class.
""" """
return int(self.steem.get_dynamic_global_properties(False).get(self.mode)) props = self.steem.get_dynamic_global_properties(False)
return int(props.get(self.mode))
def get_current_block(self): def get_current_block(self):
""" This call returns the current block """ This call returns the current block
......
...@@ -220,13 +220,15 @@ class Steem(object): ...@@ -220,13 +220,15 @@ class Steem(object):
return self.data['dynamic_global_properties'] return self.data['dynamic_global_properties']
if self.rpc is None: if self.rpc is None:
return None return None
try: count = 0
if self.rpc.get_use_appbase(): ret = None
return self.rpc.get_dynamic_global_properties(api="database") while ret is None and count < 2:
else: try:
return self.rpc.get_dynamic_global_properties() ret = self.rpc.get_dynamic_global_properties(api="database")
except: except:
return None ret = None
count += 1
return ret
def get_reserve_ratio(self, use_stored_data=True): def get_reserve_ratio(self, use_stored_data=True):
""" This call returns the *dynamic global properties* """ This call returns the *dynamic global properties*
...@@ -239,16 +241,21 @@ class Steem(object): ...@@ -239,16 +241,21 @@ class Steem(object):
if self.rpc is None: if self.rpc is None:
return None return None
try: count = 0
if self.rpc.get_use_appbase(): ret = None
return self.rpc.get_reserve_ratio(api="witness") while ret is None and count < 2:
else: try:
props = self.get_dynamic_global_properties() if self.rpc.get_use_appbase():
return {'id': 0, 'average_block_size': props['average_block_size'], return self.rpc.get_reserve_ratio(api="witness")
'current_reserve_ratio': props['current_reserve_ratio'], else:
'max_virtual_bandwidth': props['max_virtual_bandwidth']} props = self.get_dynamic_global_properties()
except: return {'id': 0, 'average_block_size': props['average_block_size'],
return None 'current_reserve_ratio': props['current_reserve_ratio'],
'max_virtual_bandwidth': props['max_virtual_bandwidth']}
except:
ret = None
count += 1
return ret
def get_feed_history(self, use_stored_data=True): def get_feed_history(self, use_stored_data=True):
""" Returns the feed_history """ Returns the feed_history
...@@ -258,15 +265,17 @@ class Steem(object): ...@@ -258,15 +265,17 @@ class Steem(object):
if use_stored_data: if use_stored_data:
self.refresh_data() self.refresh_data()
return self.data['feed_history'] return self.data['feed_history']
try: if self.rpc is None:
if self.rpc is None:
return None
if self.rpc.get_use_appbase():
return self.rpc.get_feed_history(api="database")
else:
return self.rpc.get_feed_history()
except:
return None return None
count = 0
ret = None
while ret is None and count < 2:
try:
ret = self.rpc.get_feed_history(api="database")
except:
ret = None
count += 1
return ret
def get_reward_funds(self, use_stored_data=True): def get_reward_funds(self, use_stored_data=True):
""" Get details for a reward fund. """ Get details for a reward fund.
...@@ -279,16 +288,21 @@ class Steem(object): ...@@ -279,16 +288,21 @@ class Steem(object):
if self.rpc is None: if self.rpc is None:
return None return None
try: count = 0
if self.rpc.get_use_appbase(): ret = None
funds = self.rpc.get_reward_funds(api="database")['funds'] while ret is None and count < 2:
if len(funds) > 0: try:
funds = funds[0] if self.rpc.get_use_appbase():
return funds funds = self.rpc.get_reward_funds(api="database")['funds']
else: if len(funds) > 0:
return self.rpc.get_reward_fund("post") funds = funds[0]
except: ret = funds
return None else:
ret = self.rpc.get_reward_fund("post")
except:
ret = None
count += 1
return ret
def get_current_median_history(self, use_stored_data=True): def get_current_median_history(self, use_stored_data=True):
""" Returns the current median price """ Returns the current median price
...@@ -303,13 +317,18 @@ class Steem(object): ...@@ -303,13 +317,18 @@ class Steem(object):
return None return None
if self.rpc is None: if self.rpc is None:
return None return None
try: count = 0
if self.rpc.get_use_appbase(): ret = None
return self.rpc.get_feed_history(api="database")['current_median_history'] while ret is None and count < 2:
else: try:
return self.rpc.get_current_median_history_price(api="database") if self.rpc.get_use_appbase():
except: ret = self.rpc.get_feed_history(api="database")['current_median_history']
return None else:
ret = self.rpc.get_current_median_history_price(api="database")
except:
ret = None
count += 1
return ret
def get_hardfork_properties(self, use_stored_data=True): def get_hardfork_properties(self, use_stored_data=True):
""" Returns Hardfork and live_time of the hardfork """ Returns Hardfork and live_time of the hardfork
...@@ -321,13 +340,18 @@ class Steem(object): ...@@ -321,13 +340,18 @@ class Steem(object):
return self.data['hardfork_properties'] return self.data['hardfork_properties']
if self.rpc is None: if self.rpc is None:
return None return None
try: count = 0
if self.rpc.get_use_appbase(): ret = None
return self.rpc.get_hardfork_properties(api="database") while ret is None and count < 2:
else: try:
return self.rpc.get_next_scheduled_hardfork(api="database") if self.rpc.get_use_appbase():
except: ret = self.rpc.get_hardfork_properties(api="database")
return None else:
ret = self.rpc.get_next_scheduled_hardfork(api="database")
except:
ret = None
count += 1
return ret
def get_network(self, use_stored_data=True): def get_network(self, use_stored_data=True):
""" Identify the network """ Identify the network
...@@ -484,13 +508,15 @@ class Steem(object): ...@@ -484,13 +508,15 @@ class Steem(object):
if self.rpc is None: if self.rpc is None:
return None return None
try: count = 0
if self.rpc.get_use_appbase(): ret = None
return self.rpc.get_witness_schedule(api="database") while ret is None and count < 2:
else: try:
return self.rpc.get_witness_schedule() ret = self.rpc.get_witness_schedule(api="database")
except: except:
return None ret = None
count += 1
return ret
def get_config(self, use_stored_data=True): def get_config(self, use_stored_data=True):
""" Returns internal chain configuration. """ Returns internal chain configuration.
...@@ -500,13 +526,15 @@ class Steem(object): ...@@ -500,13 +526,15 @@ class Steem(object):
return self.data['config'] return self.data['config']
if self.rpc is None: if self.rpc is None:
return None return None
try: count = 0
if self.rpc.get_use_appbase(): ret = None
return self.rpc.get_config(api="database") while ret is None and count < 2:
else: try:
return self.rpc.get_config() ret = self.rpc.get_config(api="database")
except: except:
return None ret = None
count += 1
return ret
@property @property
def chain_params(self): def chain_params(self):
......
...@@ -54,7 +54,7 @@ def formatTimedelta(td): ...@@ -54,7 +54,7 @@ def formatTimedelta(td):
hours = days * 24 + seconds // 3600 hours = days * 24 + seconds // 3600
minutes = (seconds % 3600) // 60 minutes = (seconds % 3600) // 60
seconds = (seconds % 60) seconds = (seconds % 60)
return "%d:%s.%s" % (hours, str(minutes).zfill(2), str(seconds).zfill(2)) return "%d:%s:%s" % (hours, str(minutes).zfill(2), str(seconds).zfill(2))
def parse_time(block_time): def parse_time(block_time):
......
...@@ -9,6 +9,7 @@ import io ...@@ -9,6 +9,7 @@ import io
import logging import logging
from prettytable import PrettyTable from prettytable import PrettyTable
from beem.blockchain import Blockchain from beem.blockchain import Blockchain
from beem.account import Account
from beem.block import Block from beem.block import Block
from beem.steem import Steem from beem.steem import Steem
from beem.utils import parse_time, formatTimedelta from beem.utils import parse_time, formatTimedelta
...@@ -25,16 +26,19 @@ nodes = ["wss://steemd.pevo.science", "wss://gtg.steem.house:8090", "wss://rpc.s ...@@ -25,16 +26,19 @@ nodes = ["wss://steemd.pevo.science", "wss://gtg.steem.house:8090", "wss://rpc.s
if __name__ == "__main__": if __name__ == "__main__":
how_many_minutes = 10 how_many_minutes = 10
how_many_virtual_op = 10000
max_batch_size = None max_batch_size = None
threading = False threading = False
thread_num = 16 thread_num = 16
t = PrettyTable(["node", "10 blockchain minutes", "version"]) t = PrettyTable(["node", "10 blockchain minutes", "10000 virtual account op", "version"])
t.align = "l" t.align = "l"
for node in nodes: for node in nodes:
print("Current node:", node) print("Current node:", node)
try: try:
stm = Steem(node=node, num_retries=2) stm = Steem(node=node, num_retries=3)
blockchain = Blockchain(steem_instance=stm) blockchain = Blockchain(steem_instance=stm)
account = Account("gtg", steem_instance=stm)
virtual_op_count = account.virtual_op_count()
blockchain_version = stm.get_blockchain_version() blockchain_version = stm.get_blockchain_version()
last_block_id = 19273700 last_block_id = 19273700
...@@ -68,14 +72,24 @@ if __name__ == "__main__": ...@@ -68,14 +72,24 @@ if __name__ == "__main__":
total_duration = formatTimedelta(datetime.now() - startTime) total_duration = formatTimedelta(datetime.now() - startTime)
last_block_id = block_no last_block_id = block_no
avtran = total_transaction / (last_block_id - 19273700) avtran = total_transaction / (last_block_id - 19273700)
print("* Processed %d blockchain minutes in %s" % (how_many_minutes, total_duration))
print("* blockchain version: %s" % (blockchain_version))
t.add_row([
node,
total_duration,
blockchain_version
])
break break
start_time = time.time()
stopOP = virtual_op_count - how_many_virtual_op + 1
i = 0
for acc_op in account.history_reverse(stop=stopOP):
i += 1
total_duration_acc = formatTimedelta(datetime.now() - startTime)
print("* Processed %d blockchain minutes in %s" % (how_many_minutes, total_duration))
print("* Processed %d account ops in %s" % (i, total_duration_acc))
print("* blockchain version: %s" % (blockchain_version))
t.add_row([
node,
total_duration,
total_duration_acc,
blockchain_version
])
except NumRetriesReached: except NumRetriesReached:
print("NumRetriesReached") print("NumRetriesReached")
continue continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment