Skip to content

Commit 96539e9

Browse files
committed
Also send a real request
1 parent fb400e7 commit 96539e9

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

bittensor_cli/cli.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6343,7 +6343,7 @@ def best_connection(
63436343
f"""
63446344
This command will give you the latency of all finney-like network in additional to any additional networks you specify via the {arg__("--network")} flag
63456345
6346-
The results are two-fold. One column is the overall time to initialise a connection, send a request, and wait for the result. The second column measures single ping-pong speed once connected.
6346+
The results are three-fold. One column is the overall time to initialise a connection, send the requests, and wait for the results. The second column measures single ping-pong speed once connected. The third makes a real world call to fetch the chain head.
63476347
63486348
EXAMPLE
63496349
@@ -6366,11 +6366,18 @@ def best_connection(
63666366
Column("Network"),
63676367
Column("End to End Latency", style="cyan"),
63686368
Column("Single Request Ping", style="cyan"),
6369+
Column("Chain Head Request Latency", style="cyan"),
63696370
title="Connection Latencies (seconds)",
63706371
caption="lower value is faster",
63716372
)
6372-
for n_name, (overall_latency, single_request) in sorted_results.items():
6373-
table.add_row(n_name, str(overall_latency), str(single_request))
6373+
for n_name, (
6374+
overall_latency,
6375+
single_request,
6376+
chain_head,
6377+
) in sorted_results.items():
6378+
table.add_row(
6379+
n_name, str(overall_latency), str(single_request), str(chain_head)
6380+
)
63746381
console.print(table)
63756382
fastest = next(iter(sorted_results.keys()))
63766383
if conf_net := self.config.get("network", ""):

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,15 +1664,20 @@ async def best_connection(networks: list[str]):
16641664
networks: list of network URIs
16651665
16661666
Returns:
1667-
{network_name: [end_to_end_latency, single_request_latency]}
1667+
{network_name: [end_to_end_latency, single_request_latency, chain_head_request_latency]}
16681668
16691669
"""
1670-
results = {n: [0.0, 0.0] for n in networks}
1670+
results = {}
16711671
for network in networks:
16721672
t1 = time.monotonic()
16731673
async with websockets.connect(network) as websocket:
16741674
pong = await websocket.ping()
16751675
latency = await pong
1676+
pt1 = time.monotonic()
1677+
await websocket.send(
1678+
"{'jsonrpc': '2.0', 'method': 'chain_getHead', 'params': [], 'id': '82'}"
1679+
)
1680+
await websocket.recv()
16761681
t2 = time.monotonic()
1677-
results[network] = [t2 - t1, latency]
1682+
results[network] = [t2 - t1, latency, t2 - pt1]
16781683
return results

0 commit comments

Comments
 (0)