Repository navigation
Hold on to the bound configurations of the last few per-request configurations, not of every one - #309
Open
Mpdreamz wants to merge 2 commits into
Open
Hold on to the bound configurations of the last few per-request configurations, not of every one#309Mpdreamz wants to merge 2 commits into
Mpdreamz wants to merge 2 commits into
Conversation
…gurations, not of every one The bound configuration (and its pipeline) of a per-request RequestConfiguration was cached in a ConditionalWeakTable. A caller that builds a new RequestConfiguration for each request, as the Elasticsearch client does whenever a request has options, filled the heap with dead entries and their dependent handles: the table can only drop an entry the collector has found dead, and entries that lived through a few collections wait for a full one. At 16 threads and 48 million calls the heap held 1.2 GB (1.9 GB working set) before the first full collection freed it, and the table's lock made each call slow: 16 million calls took 246 s against 7.7 s now. RecentValues keeps the values of at most 32 keys, found by the reference of the key, a new key replacing the one that shares its slot. A configuration that is kept and passed again is still bound once; one that is new every time is not held on to. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
API changes in this pull request: suggested version change NoneCompared with the base branch
Since the last release: Major, 42 breaking changes; for information, it does not fail this checkElastic.Transport.dll: Major, 28 breaking changes
Elastic.Transport.VirtualizedCluster.dll: Major, 14 breaking changes
Public API files✅ The committed API files match the build (7 files). |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Found by the 30 minute soak (#308): the server of the harness grew by 25–30 MB a minute. It is the transport. The bound configuration and pipeline of a per-request
RequestConfigurationwere cached in aConditionalWeakTable, and a caller that passes a newRequestConfigurationon each request (the Elasticsearch client does so whenever a request has options) gives it one entry and one dependent handle per request. The table can only drop what the collector has found dead, and entries that lived through a few collections wait for a full collection, so the heap fills with them, and the table rebuilds a 512 KB array on the large object heap every ~20,000 requests.In-process, 16 threads, workstation non-concurrent GC, new configuration for every call:
A full collection frees all of it, so it is not a leak, but a service at a high request rate waits minutes for one. A configuration that is shared (the same instance for every call) was and is flat at ~71 MB.
What
RecentValues<TKey, TValue>keeps the values of at most 32 keys, found by the reference of the key (a key replaces whichever one shares its slot). A configuration that is kept and passed again is bound once, as before; one that is new every time is not held on to. The same cache replaces the table forBoundConfiguration→ pipeline.OnConfigurationBoundfires on every request as before.Tests
BoundConfigurationCacheTests: a configuration passed five times is bound once, and a configuration used once is collectable after 10,000 others. Both mutation-checked (a cache that holds everything fails the second, a cache that never hits fails the first). Transport, Properties and Integration suites pass on net10.0.🤖 Generated with Claude Code