-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6222f05
Add speed test for cache creation
leonardehrenfried d3e67b0
Run speed test on branch
leonardehrenfried e3044e6
Improve recording
leonardehrenfried e429a2d
Reverse order of measurements
leonardehrenfried e1167a9
Remove log
leonardehrenfried 9232f2d
Remove unused field
leonardehrenfried 6f02877
Small clean up in timer code
leonardehrenfried cc4f438
Remove branch name
leonardehrenfried 041d1bb
Add Javadoc
leonardehrenfried 25ffb73
Extract separate test for transfer cache
leonardehrenfried 8dde5b0
Update CI config
leonardehrenfried 3a8faa0
Run test on branch
leonardehrenfried 1bcdf11
Create transit layer first
leonardehrenfried 96a0fcc
Initialize before adding any data
leonardehrenfried 5c97749
Re-use setup logic
leonardehrenfried 179592c
Don't run on branch anymore
leonardehrenfried cda87ff
Incorporate review feedback
leonardehrenfried 4d50bdc
Combine catch blocks
leonardehrenfried File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
package org.opentripplanner.transit.speed_test; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
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, 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(); | ||
} | ||
|
||
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
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
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 (OtpAppException ae) { | ||
leonardehrenfried marked this conversation as resolved.
Show resolved
Hide resolved
|
||
System.err.println(ae.getMessage()); | ||
System.exit(1); | ||
} 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path
should be@Nullable
here