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

Transfer cache speed test #6362

Merged
merged 18 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.IntStream;
import org.opentripplanner.TestServerContext;
import org.opentripplanner.datastore.OtpDataStore;
import org.opentripplanner.framework.application.OtpAppException;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.raptor.configure.RaptorConfig;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.response.RoutingResponse;
import org.opentripplanner.routing.framework.DebugTimingAggregator;
import org.opentripplanner.routing.graph.Graph;
Expand Down Expand Up @@ -191,7 +193,12 @@ public void runTest() {
}
}

measureTransferCacheComputation();
leonardehrenfried marked this conversation as resolved.
Show resolved Hide resolved

updateTimersWithGlobalCounters();

timer.finishUp();

printProfileStatistics();
saveTestCasesToResultFile();
System.err.println("\nSpeedTest done! " + projectInfo().getVersionString());
Expand Down Expand Up @@ -335,6 +342,22 @@ private void saveTestCasesToResultFile() {
}
}

/**
* Measure how long it takes to compute the transfer cache.
*/
private void measureTransferCacheComputation() {
IntStream
.of(1, 2, 3, 4, 5, 6, 7)
.forEach(reluctance -> {
leonardehrenfried marked this conversation as resolved.
Show resolved Hide resolved
RouteRequest routeRequest = new RouteRequest();
routeRequest.withPreferences(b -> b.withWalk(c -> c.withReluctance(reluctance)));
timer.recordTimer(
"transfer_cache_computation",
() -> timetableRepository.getTransitLayer().initTransferCacheForRequest(routeRequest)
);
});
}

/**
* Add "static" transit statistics and JVM memory usages to the "timers" logging.
*/
Expand All @@ -352,7 +375,6 @@ private void updateTimersWithGlobalCounters() {
timer.globalCount("jvm_max_memory", runtime.maxMemory());
timer.globalCount("jvm_total_memory", runtime.totalMemory());
timer.globalCount("jvm_used_memory", runtime.totalMemory() - runtime.freeMemory());
timer.finishUp();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SpeedTestTimer {
List.of(loggerRegistry)
);
private final MeterRegistry uploadRegistry = MeterRegistrySetup.getRegistry().orElse(null);

private boolean groupResultByTestCaseCategory = false;

public static int nanosToMillisecond(long nanos) {
Expand Down Expand Up @@ -136,6 +137,18 @@ public void globalCount(String meterName, long count) {
}
}

/**
* Execute the runnable and record its runtime in the meter name passed in.
*/
public void recordTimer(String meterName, Runnable runnable) {
if (uploadRegistry != null) {
registry.add(uploadRegistry);
var timer = registry.timer(meterName);
timer.record(runnable);
registry.remove(uploadRegistry);
}
}

/**
* Calculate the total time mean for the given timer. If the timer is not
* found {@link #NOT_AVAILABLE} is returned. This can be the case in unit tests,
Expand Down Expand Up @@ -175,7 +188,7 @@ public String name(String name, Meter.Type type, String unit) {
}

private String capitalize(String name) {
if (name.length() != 0 && !Character.isUpperCase(name.charAt(0))) {
if (!name.isEmpty() && !Character.isUpperCase(name.charAt(0))) {
char[] chars = name.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
Expand Down Expand Up @@ -208,8 +221,8 @@ public static Result merge(Collection<Result> results) {

for (Result it : results) {
any = it;
min = it.min < min ? it.min : min;
max = it.max > max ? it.max : max;
min = Math.min(it.min, min);
max = Math.max(it.max, max);
totTime += it.totTime;
count += it.count;
}
Expand Down
Loading