You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Confirm (or add) the noop action on the counter actor.
Either register pingPongCounter or clarify its purpose.
Address the any types in the actor file.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: