Docs

How do I measure the link between my robot and my GPU?

Run one file where the GPU is and one where the robot is. The client prints how many round trips an upload takes after a pause, with a ping through the pause, back to back, and as a camera stream. That tells you which network components help on your link and which do not.

shell
git clone https://github.com/General-Sequences/sequence-ai && cd sequence-ai     # on both machines
python3 bench/server.py --port 9000                        # where the GPU is
python3 bench/client.py --host GPU_ADDRESS --port 9000     # where the robot is

Both files are standard library only and run on Linux and macOS. Nothing needs installing, and no model is involved. With the defaults a run takes about 100 seconds plus the time the uploads take on your link.

What it prints

This is a run of the defaults with both ends on one machine. Loopback involves no network, so these numbers indicate nothing about any link. They are here to show the table’s format.

output
host 127.0.0.1  handshake 0.2 ms  baseline rtt min 0.1 / p50 0.2 ms  congestion None
mode            size    p50 ms    p95 ms    p99 ms   x rtt
idle          100000       0.3       0.5         -    1.54
ping          100000       0.2       0.3         -    1.04
continuous    100000       0.0       0.1         -    0.20
idle          500000       0.2       0.4         -    1.14
ping          500000       0.3       0.4         -    1.29
continuous    500000       0.1       0.1         -    0.55
idle         1000000       0.4       0.7         -    2.09
ping         1000000       0.3       0.6         -    1.69
continuous   1000000       0.2       0.3         -    1.14
30Hz           50000       0.2       0.3       0.3    1.00
10Hz          100000       0.2       0.3       0.3    1.19
10Hz          500000       0.3       0.5       0.6    1.29
  • The first line is the link itself: how long the TCP handshake took, the round-trip time (RTT) with no data on it (baseline), and the congestion control the connection uses (None where the system does not report it, as on macOS).
  • mode is what was sent, and size how many bytes each upload had.
  • p50, p95, p99 are how long an upload took to be acknowledged. p99 is given for streams only, which have enough frames for it.
  • x rtt is the median over the baseline RTT: how many round trips an upload took. This is the column to read.

It also writes result.json with every sample and the kernel’s state of the connection around each upload.

What each block sends

BlockWhat it sendsWhat it tells you
baselinean empty frame and its ackthe RTT with no data on it
idlea frame, then a pause, then the nextwhat a pause between uploads costs
pingas idle, the server pinging through the pausewhether a ping from the server side keeps the window
keepwarmas idle, the robot sending a byte through the pausethe same, done from the client side
continuousthe next frame as soon as the last is acknowledgedthe upload with a warm window
streamframes at a fixed rate, acks not waited forwhat each frame of a camera stream costs
twowritea frame in two writes with Nagle onwhat a header and a body written apart cost

The defaults run idle, ping, continuous and stream, with uploads of 100 KB, 500 KB and 1 MB, 500 ms of silence, a ping every 100 ms, and 20 samples of each.

How to read your result

You seeIt meansWhat to add
idle near 2 or 3, continuous near 1A pause costs your uploads extra round tripsA ping or BBR: the next two rows show which
ping or keepwarm near 1A ping through the pause keeps the windowconnect() on the robot, or ping on a WebSocket server
ping no better than idleA ping does not help on this linkRun again with --bbr; if that is near 1, use window
idle and continuous both near 1The pause costs nothing hereNothing for the pause
stream rows well above 1Frames wait on the link: loss, or the last hopLook at the last hop first: wifi_power.check() on the robot
A large baselineThe GPU is far awayA GPU nearer the robot

Match the run to your robot

The defaults measure large uploads after half a second of silence. To measure what your robot sends, give its sizes and its pace:

shell
# a robot that acts every 0.53 s with 24 KB of frames: the pause, a ping from each side, then BBR
python3 bench/client.py --host HOST --sizes 24k --idle-ms 530 --samples 40 --modes idle,ping,keepwarm --warm 1m
python3 bench/client.py --host HOST --sizes 24k --idle-ms 530 --samples 40 --modes idle --warm 1m --bbr
FlagWhat it setsDefault
--sizesframe sizes for idle, ping, keepwarm and continuous100k,500k,1m
--idle-msthe silence after each ack500
--ping-msthe interval of the pings and of the robot’s bytes100
--streamcamera streams, as HZxSIZE30x50k,10x100k,10x500k
--secondshow long each stream runs10
--samplessamples for each block and size20
--modesthe blocks to run, in orderidle,ping,continuous,stream
--bbrrequest BBR on this connection’s socketoff
--warmupload one frame of this size before measuringnone
--outwhere the samples are writtenresult.json

Try other distances from one pair of machines

On Linux, as root, where the client sends from:

shell
sudo tc qdisc add dev eth0 root netem delay 80ms          # about 80 ms more on the round trip
sudo tc qdisc change dev eth0 root netem delay 80ms loss 1%
sudo tc qdisc del dev eth0 root

Reference measurements

LinkUploadAfter 500 ms of silenceServer pinging every 100 msOne after another
Three machines of one cloud provider, RTTs of 11.7 and 69.2 ms, 20 samples per cell100 KB3.0 round trips1.11.05
the same500 KB3.01.11.1
the same1 MB3.01.251.3

bench/README.md has these in full, and Why does my robot’s upload get slow after a pause? has the table for a robot that sends two requests per second.

Measure a server that is already running

The tool above measures the link with its own server. To see the link while your policy server runs, read it off the server’s kernel (Linux):

python
from sequence_ai.network import tcp_link

tcp_link.read(sock_user)             # any connected socket: rtt_ms, rttvar_ms, retrans, total_retrans, cwnd
tcp_link.of(scope_user["client"])    # in an ASGI app served with one_write_http(): this request's own connection

and on the robot, policy.stats()["latency_us"]["act_us"] gives each act’s p50, p95 and p99 as the robot saw them.