-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: testground block stats don't calculate tps directly (#1586)
* Problem: testground block stats don't calculate tps directly Solution: - add tps calculation, extract from #1575 * cleanup * Update testground/benchmark/benchmark/stats.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: yihuang <[email protected]> * skip block 1 --------- Signed-off-by: yihuang <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: mmsqe <[email protected]>
- Loading branch information
1 parent
dad299e
commit e0d64e9
Showing
3 changed files
with
56 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from datetime import datetime | ||
|
||
from .utils import block, block_height | ||
|
||
# the tps calculation use the average of the last 10 blocks | ||
TPS_WINDOW = 10 | ||
|
||
|
||
def calculate_tps(blocks): | ||
if len(blocks) < 2: | ||
return 0 | ||
|
||
txs = sum(n for n, _ in blocks) | ||
_, t1 = blocks[0] | ||
_, t2 = blocks[-1] | ||
time_diff = (t2 - t1).total_seconds() | ||
if time_diff == 0: | ||
return 0 | ||
return txs / time_diff | ||
|
||
|
||
def dump_block_stats(fp): | ||
""" | ||
dump simple statistics for blocks for analysis | ||
""" | ||
tps_list = [] | ||
current = block_height() | ||
blocks = [] | ||
# skip block 1 whose timestamp is not accurate | ||
for i in range(2, current + 1): | ||
blk = block(i) | ||
timestamp = datetime.fromisoformat(blk["result"]["block"]["header"]["time"]) | ||
txs = len(blk["result"]["block"]["data"]["txs"]) | ||
blocks.append((txs, timestamp)) | ||
tps = calculate_tps(blocks[-TPS_WINDOW:]) | ||
tps_list.append(tps) | ||
print("block", i, txs, timestamp, tps, file=fp) | ||
tps_list.sort(reverse=True) | ||
print("top_tps", tps_list[:5], file=fp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters