Skip to content

Commit

Permalink
[Profiling] Speed up processing of stacktraces
Browse files Browse the repository at this point in the history
So far we kept track of stack frame and executable ids that are
associated to stack traces in a sorted collection. The rationale behind
this was that the mget should be faster. However, we have seen in
benchmarks that the contrary is the case: Not the mgets are the
bottleneck but rather insertion is so slow that it defers further
processing internally by several hundred milliseconds. When we change to
an unsorted (and pre-sized) collection we reduce median response time
from ~ 1200ms to 1000ms (or 17%).
  • Loading branch information
danielmitterdorfer committed Jan 24, 2024
1 parent d6f900c commit 203af37
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,8 @@ private class StackTraceHandler {
private final GetStackTracesResponseBuilder responseBuilder;
private final ActionListener<GetStackTracesResponse> submitListener;
private final Map<String, StackTrace> stackTracePerId;
// sort items lexicographically to access Lucene's term dictionary more efficiently when issuing an mget request.
// The term dictionary is lexicographically sorted and using the same order reduces the number of page faults
// needed to load it.
private final Set<String> stackFrameIds = new ConcurrentSkipListSet<>();
private final Set<String> executableIds = new ConcurrentSkipListSet<>();
private final Set<String> stackFrameIds;
private final Set<String> executableIds;
private final AtomicInteger totalFrames = new AtomicInteger();
private final StopWatch watch = new StopWatch("retrieveStackTraces");
private final StopWatch hostsWatch = new StopWatch("retrieveHostMetadata");
Expand All @@ -506,6 +503,9 @@ private StackTraceHandler(
this.submitTask = submitTask;
this.clusterState = clusterState;
this.stackTracePerId = new ConcurrentHashMap<>(stackTraceCount);
// pre-size with a bit of headroom so the collection isn't resized too often
this.stackFrameIds = Collections.newSetFromMap(new ConcurrentHashMap<>(stackTraceCount * 5));
this.executableIds = Collections.newSetFromMap(new ConcurrentHashMap<>(stackTraceCount));
this.expectedResponses = new AtomicInteger(expectedResponses);
this.client = client;
this.responseBuilder = responseBuilder;
Expand Down

0 comments on commit 203af37

Please sign in to comment.