Beispiel #1
0
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"@gtg/crea-pressure-4-need-for-speed|gandalf"
    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)
    last_block_id = 19273700
    try:
        stm = Crea(node=node, num_retries=3, num_retries_call=3, timeout=30)
        blockchain = Blockchain(crea_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        last_block = Block(last_block_id, crea_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 = Crea(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", crea_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 = Crea(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", crea_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        Vote(authorpermvoter, crea_instance=stm)
        stop = timer()
        vote_time = stop - start
        start = timer()
        Comment(authorperm, crea_instance=stm)
        stop = timer()
        comment_time = stop - start
        start = timer()
        Account(author, crea_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}
 print("crea_acc.rep {}".format(crea_acc.rep))
 # balances
 print("crea_acc.balances  {}".format(crea_acc.balances))
 print("crea_acc.balances {}".format(crea_acc.balances))
 # get_balances()
 print("crea_acc.get_balances()  {}".format(crea_acc.get_balances()))
 print("crea_acc.get_balances() {}".format(crea_acc.get_balances()))
 # reputation()
 print("crea_acc.get_reputation()  {}".format(crea_acc.get_reputation()))
 print("crea_acc.reputation() {}".format(crea_acc.reputation()))
 # voting_power()
 print("crea_acc.get_voting_power()  {}".format(
     crea_acc.get_voting_power()))
 print("crea_acc.voting_power() {}".format(crea_acc.voting_power()))
 # get_followers()
 print("crea_acc.get_followers()  {}".format(crea_acc.get_followers()))
 print("crea_acc.get_followers() {}".format(crea_acc.get_followers()))
 # get_following()
 print("crea_acc.get_following()  {}".format(crea_acc.get_following()))
 print("crea_acc.get_following() {}".format(crea_acc.get_following()))
 # has_voted()
 print("crea_acc.has_voted()  {}".format(
     crea_acc.has_voted("@holger80/api-methods-list-for-appbase")))
 print("crea_acc.has_voted() {}".format(
     crea_acc.has_voted(
         creaPost("@holger80/api-methods-list-for-appbase"))))
 # curation_stats()
 print("crea_acc.curation_stats()  {}".format(crea_acc.curation_stats()))
 print("crea_acc.curation_stats() {}".format(crea_acc.curation_stats()))
 # virtual_op_count
 print("crea_acc.virtual_op_count()  {}".format(