Skip to content

Conversation

@erikdubbelboer
Copy link
Member

This time we have a big csv with country/region to country/region latencies we use to lookup average latencies between peers. I'm going to do some experiments to see how accurate these results are in real lobbies.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a country/region-based latency estimation experiment, wiring a large CSV of inter-region latencies into the signaling service so that lobby listings can include an estimated latency from the requesting peer to each lobby.

Changes:

  • Add schema and data loading for latency metadata and per-country/region latency values, plus a SQL function (lobby_latency_estimate) to compute average lobby latency.
  • Plumb country/region from the HTTP connection into Peer, persist it for peers, and use it when listing lobbies to compute and return a latency field in the lobby list API (and client types/UI).
  • Extend test and example code to pass geolocation via query params, verify latency behavior via new Cucumber scenarios, and display the estimated latency in the example frontend.

Reviewed changes

Copilot reviewed 13 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
migrations/latest.lock Points the migration system at the new 1770020948_latency3 migration.
migrations/1770020948_latency3.up.sql Adds country/region columns to peers, creates latency_meta/latencies tables and index, and defines lobby_latency_estimate for average per-lobby latency calculation.
migrations/1770020948_latency3.down.sql Drops the latency-related tables, columns, index, and function to roll back the migration.
internal/signaling/latencydata/latencies.go Embeds latencies.csv, loads it into the latencies table when the data version changes, and tracks version in latency_meta.
internal/signaling/latencydata/latencies.csv Provides the large country/region latency dataset consumed by the loader and SQL function.
internal/signaling/stores/setup.go Ensures EnsureLatencyData is run after DB migrations in both production and test/local setups so the latencies table is populated.
internal/signaling/stores/shared.go Extends the Store interface with UpdatePeerGeo and updates ListLobbies signature; adds a Latency field to the Lobby DTO for JSON responses.
internal/signaling/stores/postgres.go Implements geolocation-aware ListLobbies using lobby_latency_estimate, exposes latency on lobbies, and wires the filter converter to include latency; adds UpdatePeerGeo (currently with a parameter/placeholder bug).
internal/signaling/handler.go Captures country/region from Cloudflare headers or URL query parameters and attaches them to the Peer for later use.
internal/signaling/peer.go On hello, persists a peer’s country/region via UpdatePeerGeo and passes those values into ListLobbies when handling lobby list requests.
lib/types.ts Extends LobbyListEntry with an optional latency?: number so clients can consume the new latency estimate.
features/support/world.ts Allows test players to be created with optional country/region, passing them as query parameters to the signaling server.
features/support/steps/network.ts Adds a step to connect players with explicit country/region, wires those into createPlayer, and uses them when requesting lobbies in tests.
features/latency3.feature Adds scenarios that assert the computed lobby latency from requester to lobby peers, including default behavior when data is missing.
example/main.ts Updates the demo UI to display player count along with the estimated lobby latency (or <unknown> when unavailable).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This time we have a big csv with country/region to country/region
latencies we use to lookup average latencies between peers. I'm going to
do some experiments to see how accurate these results are in real
lobbies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants