Skip to content

examples/vsock-latency: reproducer for first-connection vsock delay#683

Draft
smoser wants to merge 2 commits into
containers:mainfrom
smoser:vsock-delay-debug
Draft

examples/vsock-latency: reproducer for first-connection vsock delay#683
smoser wants to merge 2 commits into
containers:mainfrom
smoser:vsock-delay-debug

Conversation

@smoser
Copy link
Copy Markdown

@smoser smoser commented May 18, 2026

This was opened to share a reproducer for #684

The first host-to-guest vsock round trip after VM start blocks until
libkrun's vsock reaper TTL fires (src/devices/src/virtio/vsock/reaper.rs:10,
currently 5 s). The first host connect() succeeds at the unix layer
immediately, but the first read() blocks for the full reaper window
before libkrun closes the unix socket with EOF. A second connect()
immediately afterwards uses a fresh proxy and completes in <1 ms.

The reproducer is ~400 lines of C in a new examples/vsock-latency/
subdirectory:

  * guest.c   tiny static AF_VSOCK listener; one ack byte per connect
  * host.c    libkrun setup + a timing thread that prints
                phase: socket-created     +<t>
                phase: first-roundtrip-ok +<t>  (attempts=<n>)
                warm-roundtrip[0..3]:     +<t>
  * Makefile  builds both; "make rootfs" pulls a busybox image
              into ./rootfs/ via docker (a one-file rootfs is not
              enough for libkrunfw's init)
  * README.md what it measures, expected output, root cause

The host.c timing loop also honours PROBE_TIMEOUT_MS to apply
SO_RCVTIMEO per attempt (simulates a caller that wraps each probe
in a deadline). Measured trade-off on libkrunfw 5.4.0 / bundled
kernel 6.12.87:

  PROBE_TIMEOUT_MS  first-roundtrip-ok  attempts
  unset             ~5340 ms            2
  2000              ~2355 ms            2
  100                ~425 ms            2
  10                 ~373 ms            3

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant