Skip to content

Commit 86f23fa

Browse files
emmaling27Convex, Inc.
authored andcommitted
Add client and server ts information to websocket messages to surface websocket latency issues (#40827)
This PR adds the `clientTs` to the initial websocket connect message, which the sync worker uses to calculate the `client_clock_skew`, which is the difference between the client clock and server clock, plus whatever latency between client sending and server receiving the message. We send the latest possible `serverTs` before the server `Transition` message gets sent down to the client. On the client, we can then understand how long it took for the `Transition` message to download by comparing the current client time with the `serverTs` and subtracting the `clientClockSkew`. GitOrigin-RevId: 9b8d2693a40196a78ee08aa3e2f49c695d0172d0
1 parent 4f9a639 commit 86f23fa

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/browser/sync/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ export class BaseConvexClient {
396396
type: "Connect",
397397
sessionId: this._sessionId,
398398
maxObservedTimestamp: this.maxObservedTimestamp,
399+
clientTs: Date.now(),
399400
});
400401

401402
// Throw out our remote query, reissue queries

src/browser/sync/protocol.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ type Connect = {
121121
connectionCount: number;
122122
lastCloseReason: string | null;
123123
maxObservedTimestamp?: TS;
124+
clientTs: number;
124125
};
125126

126127
export type AddQuery = {
@@ -254,6 +255,8 @@ export type Transition = {
254255
startVersion: StateVersion;
255256
endVersion: StateVersion;
256257
modifications: StateModification[];
258+
clientClockSkew?: number;
259+
serverTs?: number;
257260
};
258261

259262
type MutationSuccess = {

0 commit comments

Comments
 (0)