Skip to content

Commit

Permalink
Switch to proper histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Dec 23, 2021
1 parent 96c4422 commit 6ff4d64
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions misc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "tdigest";
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-hotkeys": "^1.1.4",
"replicache": "file:replicache-8.0.0.tgz",
"replicache-react": "^2.4.0",
"tdigest": "^0.1.1",
"ws": "^8.2.3",
"zod": "^3.11.6"
},
Expand Down
12 changes: 9 additions & 3 deletions pages/d/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { randomShape } from "../../frontend/shape";
import { PushMessage, PushBody } from "../../protocol/push";
import { resolver } from "frontend/resolver";
import { pokeMessageSchema } from "protocol/poke";
import { JSONType } from "protocol/json";
import { NullableVersion, nullableVersionSchema } from "backend/types/version";
import { sleep } from "backend/util/test-utils";
import { TDigest } from "tdigest";

export default function Home() {
const [rep, setRep] = useState<Replicache<M> | null>(null);
Expand Down Expand Up @@ -94,6 +94,8 @@ export default function Home() {
ws.addEventListener("open", () => {
resolve(ws);
});
const updateDelayDigest = new TDigest({ mode: "disc" });
const timestampDelayDigest = new TDigest({ mode: "disc" });
let lastrecv = performance.now();
let lastts = 0;
ws.addEventListener("message", (e) => {
Expand All @@ -103,8 +105,12 @@ export default function Home() {

const now = performance.now();
const ts = pokeBody.timestamp;
console.log("time since lastrecv", now - lastrecv);
console.log("time since lastts", ts - lastts);
updateDelayDigest.push(now - lastrecv);
timestampDelayDigest.push(ts - lastts);
if (Math.random() < 0.1) {
console.log("lastrecv summary", updateDelayDigest.summary());
console.log("time since lastts", timestampDelayDigest.summary());
}
lastrecv = now;
lastts = ts;

Expand Down

0 comments on commit 6ff4d64

Please sign in to comment.