Deduplicate UserAgent other-info entries - #939
Closed
vuanhphung wants to merge 2 commits into
Closed
vuanhphung wants to merge 2 commits into
vuanhphung wants to merge 2 commits into
Conversation
UserAgent.withOtherInfo appended to a static list on every call, and asString formatted the whole list under a lock on every request. Callers that register entries per connection, such as the JDBC driver, made request latency and lock contention grow with every connection a JVM had opened. Entries are now stored once in a CopyOnWriteArrayList, so repeated registrations are no-ops and asString reads without locking. The rendered header is unchanged. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
ConcurrentHashMap.newKeySet() is the standard concurrent set and adds new entries in constant time, which matters for callers that register many distinct values. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Contributor
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Author
|
Closing: the Java SDK source now lives in the monorepo, so this fix is moving there. |
This branch was successfully 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.
Summary
Deduplicates
UserAgent.withOtherInfoentries and reads them inasString()without a lock, so registering the same entry repeatedly no longer grows User-Agent state or per-request cost.Why
withOtherInfoappended to a static list on every call, andasString()formatted the whole list under a lock on every request. The Databricks JDBC driver registers its entries on everyDriver.connect(), so in a long-running JVM that opens a connection per query, request latency and lock contention grew with every connection the JVM had opened. In a reproduction against a SQL warehouse (databricks/databricks-jdbc#1714), the list reached 7,280 entries after ~3.7k connections, and 70% of worker CPU samples were inUserAgent.asString. Fixing it in the SDK covers every caller, not just JDBC.What changed
Interface changes
None.
Behavioral changes
Repeated
withOtherInfo/withPartnercalls with the same key and value are no-ops. The rendered User-Agent is unchanged, sinceasString()already removed duplicates.Internal changes
otherInfois aConcurrentHashMap.newKeySet(), andInfoimplementsequals/hashCode. The field is package-private so tests can check its size.How is this tested?
UserAgentTest.testUserAgentWithOtherInfoDeduplicated: 1,000 identical registrations add one entry; the same key with a new value adds another.UserAgentLoadTestnow asserts that 200 concurrent registrations of one entry add it once.Info.equalsis made identity-only.databricks-sdk-javaunit suite passes locally (1,502 tests).This pull request and its description were written by Isaac.