Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional MurmurHash support #142

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

kusalk
Copy link
Contributor

@kusalk kusalk commented Dec 24, 2024

The changes encompassed in this PR were originally included with those in #134. I extracted these change into this separate PR following a discussion in the former PR.


This PR introduces support for MurmurHash as an alternative to the default MD5. In my experience it is over 4x faster at hashing (rough benchmarks below).

MurmurHash can be activated by providing the following argument to the agent -Dhash.algorithm=murmur. The argument must be supplied to the collector instead if using the legacy agent.

Benchmark: MethodRegistry#getHash

Scenario: ConcurrentHashMap cache disabled

Before PR (ns/op) After PR (ns/op)
581.834 ± 46.560 139.283 ± 6.211

@kusalk kusalk force-pushed the murmur-hash-alg branch 5 times, most recently from 1a11e95 to a5747d2 Compare December 24, 2024 07:12
private static final String SELECTED_ALGORITHM_PROP = "hash.algorithm";
private static final HashAlgorithm DEFAULT_ALGORITHM = HashAlgorithm.MD5;
private static final HashAlgorithm SELECTED_ALGORITHM =
HashAlgorithm.valueOf(System.getProperty(SELECTED_ALGORITHM_PROP, DEFAULT_ALGORITHM.name()).toUpperCase());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We read the chosen hashing algorithm from the system property here

@kusalk kusalk changed the title [WIP] Add optional MurmurHash support Add optional MurmurHash support Feb 17, 2025
Copy link

github-actions bot commented Feb 17, 2025

Scavenger Test Results

166 files  166 suites   1m 31s ⏱️
277 tests 271 ✅ 6 💤 0 ❌
299 runs  293 ✅ 6 💤 0 ❌

Results for commit 7554c09.

♻️ This comment has been updated with latest results.

private static String from(String signature) {
MessageDigest md = callWithCheckedExceptionWrapping(() -> MessageDigest.getInstance("MD5"));
md.update(signature.getBytes(StandardCharsets.UTF_8));
// Ideally should be "%032x" to avoid confusion from leading zeros being dropped, do not change now, avoid compat issues
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 noticed this peculiarity whilst testing - the returned String won't always be 32 characters. This shouldn't cause issues but noted it in a comment. We obviously can't change it now anyway as it would cause backwards compatibility issues.

@@ -17,12 +22,19 @@ dependencies {
implementation("io.grpc:grpc-kotlin-stub:${property("grpcKotlinVersion")}")
implementation("io.grpc:grpc-protobuf:${property("grpcVersion")}")
implementation("javax.annotation:javax.annotation-api:1.3.2")
implementation("commons-codec:commons-codec:1.18.0")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use the MurmurHash implementation from the commons-codec library dependency - it will increase the size of the agent JAR slightly (~300 kB)

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.

1 participant