-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add utility for computing 64-bit hash (#1058)
Currently based on XXH64. Allows for data to be incrementally fed to the hash accumulator to make it more convenient to use and avoid allocations creating the structure needed to pass into the hash. Though in some cases the incremental processing is slower than just passing in something like a precomputed string.
- Loading branch information
1 parent
e796bbc
commit 1d750ea
Showing
10 changed files
with
884 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
|
||
<!DOCTYPE suppressions PUBLIC | ||
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" | ||
"https://checkstyle.org/dtds/suppressions_1_2.dtd"> | ||
|
||
<suppressions> | ||
<suppress checks="IllegalImport" files="UnsafeUtils.java"/> | ||
</suppressions> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
78 changes: 78 additions & 0 deletions
78
spectator-api/src/jmh/java/com/netflix/spectator/perf/IdHash.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2014-2023 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.spectator.perf; | ||
|
||
import com.netflix.spectator.api.Id; | ||
import com.netflix.spectator.impl.Hash64; | ||
import net.openhft.hashing.LongHashFunction; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
/** | ||
* Benchmark Mode Cnt Score Error Units | ||
* IdHash.hash64 thrpt 5 2379245.474 ± 7379.034 ops/s | ||
* IdHash.hash64_2 thrpt 5 4817014.307 ± 5704.027 ops/s | ||
* IdHash.openhft thrpt 5 4910133.221 ± 100296.076 ops/s | ||
* | ||
* Benchmark Mode Cnt Score Error Units | ||
* IdHash.hash64:·gc.alloc.rate.norm thrpt 5 0.188 ± 0.002 B/op | ||
* IdHash.hash64_2:·gc.alloc.rate.norm thrpt 5 1152.095 ± 0.001 B/op | ||
* IdHash.openhft:·gc.alloc.rate.norm thrpt 5 1128.095 ± 0.002 B/op | ||
*/ | ||
@State(Scope.Thread) | ||
public class IdHash { | ||
|
||
private final Id id = Id.create("http.req.complete") | ||
.withTag( "nf.app", "test_app") | ||
.withTag("nf.cluster", "test_app-main") | ||
.withTag( "nf.asg", "test_app-main-v042") | ||
.withTag( "nf.stack", "main") | ||
.withTag( "nf.ami", "ami-0987654321") | ||
.withTag( "nf.region", "us-east-1") | ||
.withTag( "nf.zone", "us-east-1e") | ||
.withTag( "nf.node", "i-1234567890") | ||
.withTag( "country", "US") | ||
.withTag( "device", "xbox") | ||
.withTag( "status", "200") | ||
.withTag( "client", "ab"); | ||
|
||
private final Hash64 h64 = new Hash64(); | ||
private final LongHashFunction xx = LongHashFunction.xx(); | ||
|
||
@Benchmark | ||
public void hash64(Blackhole bh) { | ||
h64.updateString(id.name()); | ||
for (int i = 1; i < id.size(); ++i) { | ||
h64.updateChar(':'); | ||
h64.updateString(id.getKey(i)); | ||
h64.updateChar('='); | ||
h64.updateString(id.getValue(i)); | ||
} | ||
bh.consume(h64.computeAndReset()); | ||
} | ||
|
||
@Benchmark | ||
public void hash64_2(Blackhole bh) { | ||
bh.consume(h64.updateString(id.toString()).computeAndReset()); | ||
} | ||
|
||
@Benchmark | ||
public void openhft(Blackhole bh) { | ||
bh.consume(xx.hashChars(id.toString())); | ||
} | ||
} |
Oops, something went wrong.