Skip to content

[client-v2] Measure only the row writing in OP_SERIALIZATION - #3463

Open
kushagra0526 wants to merge 1 commit into
ClickHouse:mainfrom
kushagra0526:fix/insert-serialization-metric-narrow
Open

kushagra0526 wants to merge 1 commit into
ClickHouse:mainfrom
kushagra0526:fix/insert-serialization-metric-narrow

Conversation

@kushagra0526

@kushagra0526 kushagra0526 commented Nov 28, 2026 •

Copy link
Copy Markdown

Summary

Fixes #3198.

For a POJO insert, OP_SERIALIZATION started together with OP_DURATION and was only stopped by operationComplete(), after the response arrived. The two metrics were always equal, and clickhouse.client.operation.serialization.duration reported network and server time as serialization.

The stopwatch is now started at the top of the request body writer and stopped after the rows are written, so a retried insert reports the last attempt. operationComplete() stops every watch again, so the writer also calls a new StopWatch.freeze() to keep this value. Only OP_SERIALIZATION is frozen; stop() behaves as before for every other watch.

The measured time still includes any blocking on the socket while the body is streamed.

Test: testInsertSerializationDurationExcludesWaitingForTheServer delays the mock server by 2 s. On main it reports 2.02 s of serialization; with the change it is under 1 s. The client-v2 *UnitTest classes pass (112 tests).

Closes #3198

Compatibility

No public API change. clickhouse.client.operation.serialization.duration now reports only the time spent writing rows for POJO inserts, so dashboards will show much smaller values than before (previously it equalled the full operation duration).

Testing

  • Unit test with a mock server delaying 2 s (fails on main with 2.02 s, passes with the fix).
  • All 112 client-v2 unit tests pass.
  • Integration tests against a real ClickHouse server: the client-v2 insert tests (Insert*Tests) pass locally on ClickHouse 26.11.5.8 (126 run, 0 failures, 0 skipped). No new integration test added.

Checklist


Note

Low Risk
Observability-only timing change with localized StopWatch behavior; no insert protocol or auth changes.

Overview
Fixes misleading serialization duration on POJO inserts: OP_SERIALIZATION no longer starts with OP_DURATION at operation begin. It is started and stopped inside the HTTP request body callback, covering only writing the INSERT header and row binary for the POJOs.

Because each retry rewrites the body, the metric reflects the last attempt's write time. StopWatch gains freeze() so operationComplete()'s later stop() does not overwrite that value.

A WireMock test asserts OPERATION_SERIALIZATION_DURATION stays under 1s while the server adds a 2s delay, proving network/server wait is not counted as serialization (though time blocked on the socket while streaming the body still is).

Reviewed by Cursor Bugbot for commit 8e711cf. Bugbot is set up for automated code reviews on this repo. Configure here.

@kushagra0526
kushagra0526 requested review from a team and mzitnik as code owners November 28, 2026 17:46
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.

[client-v2] OP_SERIALIZATION metric reports the whole operation duration, not the serialization step

1 participant