Skip to content

WIP: counter latency monitor#5011

Draft
NathanFlurry wants to merge 1 commit into
mainfrom
05-09-wip_counter_latency_monitor
Draft

WIP: counter latency monitor#5011
NathanFlurry wants to merge 1 commit into
mainfrom
05-09-wip_counter_latency_monitor

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 10, 2026

🚅 Deployed to the rivet-pr-5011 environment in rivet-frontend

Service Status Web Updated (UTC)
kitchen-sink ❌ Build Failed (View Logs) Web May 14, 2026 at 5:27 pm
website 😴 Sleeping (View Logs) Web May 13, 2026 at 6:35 am
frontend-cloud ❌ Build Failed (View Logs) Web May 10, 2026 at 2:12 am
ladle ❌ Build Failed (View Logs) Web May 10, 2026 at 2:12 am
frontend-inspector ❌ Build Failed (View Logs) Web May 10, 2026 at 2:12 am
mcp-hub ✅ Success (View Logs) Web May 10, 2026 at 2:11 am

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 10, 2026

Code Review: WIP Counter Latency Monitor

Note: This is a draft PR — review is for early feedback only.

Overview

Adds two files to the kitchen-sink example:

  • scripts/counter-latency.ts — a CLI load-test / latency monitor with rtt and concurrent modes
  • src/actors/counter/ping-pong-counter.ts — a raw-WebSocket ping-pong actor

scripts/counter-latency.ts

Good

  • Clear, thorough header comment with usage examples
  • Solid arg parsing with validation and meaningful error messages
  • Gradient color-coding by latency makes the output easy to scan at a glance
  • Best-effort dispose() pattern (void connection.dispose().catch(() => {})) is correct for cleanup paths

Issues

  • connection.noop() may not exist. The script calls await connection.noop() to probe WebSocket open time, but there is no noop action visible in the counter actor. If the counter actor does not expose a noop action this will throw on every worker and produce zero useful samples. Confirm the action exists or add it to the counter actor in this PR.

  • Unbounded inflight array in runRttMode. In non-serial infinite mode (BATCHES=0, SERIAL=false), resolved promises are pushed into inflight but never drained. Over a long run this is a gradual memory leak. Consider splicing out settled promises or using a fixed-size worker pool.

  • runConcurrentMode never returns. Every worker runs while(true), so await Promise.all(workers) blocks indefinitely. That is probably the intended UX, but there is no SIGINT/SIGTERM handler to call dispose() on open connections before exit. Under heavy load this can leave actors in a half-open state on the server side.

  • Credential exposure in process listing. The endpoint is parsed as a URL where the token lives in the username field. The header log omits the password but the full URL with token is visible in ps output. Low-severity for a dev script, but worth a note in the usage comment.

  • Non-null assertion on ARGS.concurrency!. The runtime validation already guarantees this in concurrent mode. A small improvement would be to narrow the type (e.g. concurrency: number on a ConcurrentArgs subtype) instead of relying on !.

Minor / style

  • The header comment says < 800 green, 800-1500 orange, > 1500 red but the gradient goes green to yellow to red. Docs and implementation are inconsistent.
  • logConnect, logIncrement, logDisconnect, logConnectError all duplicate the same ts/prefix construction. A tiny makePrefix(worker) helper would remove the repetition.

src/actors/counter/ping-pong-counter.ts

Issues

  • any types. Both event: any and parsed: any should be typed. The WebSocket MessageEvent type is available; parsed can be typed as unknown with a type-guard or a simple discriminated-union check instead of optional-chaining on any.

  • Not registered. The diff adds the file but does not wire pingPongCounter into the registry (src/index.ts or equivalent). The script in this PR also does not use it. Is it intended for a future ping-pong latency mode?

  • State mutation style. ctx.state.pingCount = ctx.state.pingCount + 1 works but ctx.state.pingCount += 1 is more idiomatic.

  • No error handling on websocket.send. If the send throws (e.g. connection already closed) the error is unhandled. A try/catch or a ready-state check would be safer.


Summary

The latency script is useful tooling but has a few items worth addressing before merge:

  1. Confirm (or add) the noop action on the counter actor.
  2. Either register pingPongCounter or clarify its purpose.
  3. Address the any types in the actor file.
  4. Consider a SIGINT handler for clean shutdown in concurrent mode.

Everything else is minor polish. Happy to re-review once the WIP items are resolved.

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