-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6362 from opentripplanner/transfer-cache-speed-test
Transfer cache speed test
- Loading branch information
Showing
6 changed files
with
147 additions
and
33 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
7 changes: 7 additions & 0 deletions
7
application/src/test/java/org/opentripplanner/transit/speed_test/LoadModel.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,7 @@ | ||
package org.opentripplanner.transit.speed_test; | ||
|
||
import org.opentripplanner.routing.graph.Graph; | ||
import org.opentripplanner.standalone.config.BuildConfig; | ||
import org.opentripplanner.transit.service.TimetableRepository; | ||
|
||
record LoadModel(Graph graph, TimetableRepository timetableRepository, BuildConfig buildConfig) {} |
41 changes: 41 additions & 0 deletions
41
application/src/test/java/org/opentripplanner/transit/speed_test/SetupHelper.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,41 @@ | ||
package org.opentripplanner.transit.speed_test; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
import javax.annotation.Nullable; | ||
import org.opentripplanner.datastore.OtpDataStore; | ||
import org.opentripplanner.routing.graph.Graph; | ||
import org.opentripplanner.routing.graph.SerializedGraphObject; | ||
import org.opentripplanner.standalone.config.ConfigModel; | ||
import org.opentripplanner.standalone.config.OtpConfigLoader; | ||
import org.opentripplanner.transit.service.TimetableRepository; | ||
import org.opentripplanner.transit.speed_test.options.SpeedTestCmdLineOpts; | ||
|
||
/** | ||
* A package-private helper class for setting up speed tests. | ||
*/ | ||
class SetupHelper { | ||
|
||
static LoadModel loadGraph(File baseDir, @Nullable URI path) { | ||
File file = path == null | ||
? OtpDataStore.graphFile(baseDir) | ||
: path.isAbsolute() ? new File(path) : new File(baseDir, path.getPath()); | ||
SerializedGraphObject serializedGraphObject = SerializedGraphObject.load(file); | ||
Graph graph = serializedGraphObject.graph; | ||
|
||
if (graph == null) { | ||
throw new IllegalStateException( | ||
"Could not find graph at %s".formatted(file.getAbsolutePath()) | ||
); | ||
} | ||
|
||
TimetableRepository timetableRepository = serializedGraphObject.timetableRepository; | ||
timetableRepository.index(); | ||
graph.index(timetableRepository.getSiteRepository()); | ||
return new LoadModel(graph, timetableRepository, serializedGraphObject.buildConfig); | ||
} | ||
|
||
static void loadOtpFeatures(SpeedTestCmdLineOpts opts) { | ||
ConfigModel.initializeOtpFeatures(new OtpConfigLoader(opts.rootDir()).loadOtpConfig()); | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
application/src/test/java/org/opentripplanner/transit/speed_test/TransferCacheTest.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,68 @@ | ||
package org.opentripplanner.transit.speed_test; | ||
|
||
import static org.opentripplanner.standalone.configure.ConstructApplication.creatTransitLayerForRaptor; | ||
import static org.opentripplanner.transit.speed_test.support.AssertSpeedTestSetup.assertTestDateHasData; | ||
|
||
import java.util.stream.IntStream; | ||
import org.opentripplanner.framework.application.OtpAppException; | ||
import org.opentripplanner.routing.api.request.RouteRequest; | ||
import org.opentripplanner.standalone.OtpStartupInfo; | ||
import org.opentripplanner.transit.service.TimetableRepository; | ||
import org.opentripplanner.transit.speed_test.model.timer.SpeedTestTimer; | ||
import org.opentripplanner.transit.speed_test.options.SpeedTestCmdLineOpts; | ||
import org.opentripplanner.transit.speed_test.options.SpeedTestConfig; | ||
|
||
/** | ||
* Test how long it takes to compute the transfer cache. | ||
*/ | ||
public class TransferCacheTest { | ||
|
||
public static void main(String[] args) { | ||
try { | ||
OtpStartupInfo.logInfo("Run transfer cache test"); | ||
// Given the following setup | ||
SpeedTestCmdLineOpts opts = new SpeedTestCmdLineOpts(args); | ||
var config = SpeedTestConfig.config(opts.rootDir()); | ||
SetupHelper.loadOtpFeatures(opts); | ||
var model = SetupHelper.loadGraph(opts.rootDir(), config.graph); | ||
var timetableRepository = model.timetableRepository(); | ||
var buildConfig = model.buildConfig(); | ||
|
||
var timer = new SpeedTestTimer(); | ||
timer.setUp(false); | ||
|
||
// Creating transitLayerForRaptor should be integrated into the TimetableRepository, but for now | ||
// we do it manually here | ||
creatTransitLayerForRaptor(timetableRepository, config.transitRoutingParams); | ||
|
||
assertTestDateHasData(timetableRepository, config, buildConfig); | ||
|
||
measureTransferCacheComputation(timer, timetableRepository); | ||
|
||
timer.finishUp(); | ||
} catch (Exception e) { | ||
System.err.println(e.getMessage()); | ||
e.printStackTrace(System.err); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
/** | ||
* Measure how long it takes to compute the transfer cache. | ||
*/ | ||
private static void measureTransferCacheComputation( | ||
SpeedTestTimer timer, | ||
TimetableRepository timetableRepository | ||
) { | ||
IntStream | ||
.range(1, 7) | ||
.forEach(reluctance -> { | ||
RouteRequest routeRequest = new RouteRequest(); | ||
routeRequest.withPreferences(b -> b.withWalk(c -> c.withReluctance(reluctance))); | ||
timer.recordTimer( | ||
"transfer_cache_computation", | ||
() -> timetableRepository.getTransitLayer().initTransferCacheForRequest(routeRequest) | ||
); | ||
}); | ||
} | ||
} |
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