-
Notifications
You must be signed in to change notification settings - Fork 264
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
It is slow when generate correlation Id #198
Comments
It would be also interesting to see if it is a problem with java 8 - |
Maybe this is the problem:
|
If there is no requirement for it to be in form of UUID, something like this could be suitable: diff --git logbook-core/src/main/java/org/zalando/logbook/DefaultLogbook.java logbook-core/src/main/java/org/zalando/logbook/DefaultLogbook.java
index 65f43d8..adff12f 100644
--- logbook-core/src/main/java/org/zalando/logbook/DefaultLogbook.java
+++ logbook-core/src/main/java/org/zalando/logbook/DefaultLogbook.java
@@ -1,11 +1,12 @@
package org.zalando.logbook;
import java.io.IOException;
+import java.security.SecureRandom;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
-import java.util.UUID;
+import java.util.Random;
import java.util.function.Predicate;
final class DefaultLogbook implements Logbook {
@@ -40,7 +41,7 @@ final class DefaultLogbook implements Logbook {
public Optional<Correlator> write(final RawHttpRequest rawHttpRequest) throws IOException {
final Instant start = Instant.now(clock);
if (writer.isActive(rawHttpRequest) && predicate.test(rawHttpRequest)) {
- final String correlationId = UUID.randomUUID().toString();
+ final String correlationId = generateCorrelationId();
final RawHttpRequest filteredRawHttpRequest = rawRequestFilter.filter(rawHttpRequest);
final HttpRequest request = requestFilter.filter(filteredRawHttpRequest.withBody());
@@ -64,6 +65,12 @@ final class DefaultLogbook implements Logbook {
}
}
+ private static final Random RANDOM = new Random(new SecureRandom().nextLong());
+
+ private static String generateCorrelationId() {
+ return Long.toString(RANDOM.nextLong());
+ }
+
static class SimplePrecorrelation<I> implements Precorrelation<I> {
private final String id; |
If someone is initializing the |
The random number could be negative, but I don't think that's a problem. |
return Long.toHexString(RANDOM.nextLong()); It could be even faster |
GH-198 Uses pseudo-random generator to create correlation ids
This is a picture profiled on my production server.
It stuck at UUID.randomUUID(),
UUID performance is very slow,could logbook use random instead of uuid?
https://stackoverflow.com/questions/14532976/performance-of-random-uuid-generation-with-java-7-or-java-6
The text was updated successfully, but these errors were encountered: