Skip to content

Conversation

Tim-Brooks
Copy link
Contributor

@Tim-Brooks Tim-Brooks commented Sep 5, 2025

Currently translog operations are serialized in a way that is relatively
inefficient. This commit improves performance by re-ordering the
operations to allow most of the header to be serialized without bounds
checks. Additionally, instead of incrementally calculating the checksum
we do a single pass at the end. Finally, we no longer copy the source
twice. Instead serialize it directly into the translog writer.

@Tim-Brooks Tim-Brooks added >non-issue :Distributed Indexing/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. v9.2.0 labels Sep 5, 2025
Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, left more comments.


int variableLengthSize = (int) (buffer.position() - variableLengthStart);
int sizeOfOperation = FIXED_INDEX_HEADER_SIZE - Integer.BYTES + variableLengthSize + sourceLength + Integer.BYTES;
ByteUtils.writeIntBE(sizeOfOperation, bytes, off);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we assert that it is identical to a slow header, perhaps rarely?? You probably have tests for it though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have tests in TranslogHeaderWriterTests which runs 30 checks each run randomizing to one page and cross-page.

buffer.writeString(indexOperation.id());

int sourceLength = indexOperation.source().length();
buffer.writeVInt(indexOperation.source().length());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check but am guessing we may not need this. I am ok to keep it though, but think a comment on why we have it is appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'm not sure what you mean. We serialize it here to calculate the checksum. I actually don't love using a vInt here. It's more historical from how we serialize BytesReferences in stream outputs.

Fixed width values would be nicer but we already have variable length values for id and routing so I did not feel like it was worth it to change this.

out.writeLong(seqNo);
out.writeLong(primaryTerm);
} else {
out.writeLong(version);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this and writeSlowIndexHeader share code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I combined these.

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Can we run a relevant nightly test using the new buildkite ability to run nightly tests on PRs? Both to verify performance and ensure it does not expose anything.

@Tim-Brooks
Copy link
Contributor Author

Buildkite benchmark this with tsdb-metricsgen-270m please

@Tim-Brooks
Copy link
Contributor Author

Buildkite benchmark this with http_logs-1n-1g please

@Tim-Brooks
Copy link
Contributor Author

When I ran the http logs it deleted the tsdb metrics gen comment. I also ran that:

⏳ Build in-progress

Buildkite Build
Commit: 8c29c56
Baseline: f474779 (env ID 94ec114f-ce84-429a-80b5-cead24c90144)
Contender: 8c29c56 (env ID 785a0436-2ac1-405b-bc2f-f93b3cadc66e)
This build attempts two tsdb-metricsgen-270m benchmarks to evaluate performance impact of this PR. To estimate benchmark completion time inspect previous nightly runs here.

Result: https://esbench-metrics.kb.us-east-2.aws.elastic-cloud.com:9243/app/r/s/lwXvc

@Tim-Brooks
Copy link
Contributor Author

💚 Build Succeeded

This build ran two http_logs-1n-1g benchmarks to evaluate performance impact of this PR.

History

@Tim-Brooks
Copy link
Contributor Author

Buildkite benchmark this with nyc_taxis-1n-8g please

@Tim-Brooks
Copy link
Contributor Author

NYC Taxis

💚 Build Succeeded

This build ran two nyc_taxis-1n-8g benchmarks to evaluate performance impact of this PR.

History

@Tim-Brooks
Copy link
Contributor Author

Tim-Brooks commented Oct 8, 2025

TSDB Metricsgen p50
Vanilla - 77006 -> 78734 (2.2%)
Tweaked - 87086 doc/s -> 89415 doc/s (2.7%)

image

NYC Taxi
Less than 1% improvement but the CPUs are around 80% so it is not really saturated. In my own benchmark environment these as around 1-2% improvement with enough clients to saturate.

image

Http Logs are nearly identical between contender and main. CPUs pegged.

I'll run the standard logs overnight and as long as that looks fine I'll commit tomorrow morning for a full nightly run.

@Tim-Brooks
Copy link
Contributor Author

Buildkite benchmark this with elastic-logs please

@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 8, 2025

💚 Build Succeeded

This build ran two elastic-logs benchmarks to evaluate performance impact of this PR.

History

@Tim-Brooks
Copy link
Contributor Author

Logs
33438 dos/ -> 34392 doc/s (2.85%)

@Tim-Brooks Tim-Brooks merged commit 5ea2d96 into elastic:main Oct 8, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. >non-issue serverless-linked Added by automation, don't add manually Team:Distributed Indexing Meta label for Distributed Indexing team v9.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants