Skip to content

Commit

Permalink
Merge pull request opentripplanner#4027 from opentripplanner/otp2_mov…
Browse files Browse the repository at this point in the history
…e_speed_test_to_routing_worker

Use RoutingWorker in the speed test  [changelog skip]
  • Loading branch information
t2gran authored Mar 30, 2022
2 parents 7a7a88b + c7df91e commit 64e2495
Show file tree
Hide file tree
Showing 89 changed files with 1,878 additions and 2,596 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/performance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- dev-2.x
- otp2_move_speed_test_to_routing_worker

jobs:
perf-test:
Expand Down Expand Up @@ -61,7 +62,7 @@ jobs:
MEASUREMENT_ENVIRONMENT: CI
run: |
mv graph/graph.obj test/ci-performance-test/
mvn exec:java -Dexec.mainClass="org.opentripplanner.transit.raptor.speed_test.SpeedTest" -Dexec.classpathScope=test -Dexec.args="--dir=test/ci-performance-test/ -p md -n 4"
mvn exec:java -Dexec.mainClass="org.opentripplanner.transit.raptor.speed_test.SpeedTest" -Dexec.classpathScope=test -Dexec.args="--dir=test/ci-performance-test/ -p md -n 4 -i 3 -0"
- name: Archive travel results file
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</scm>

<properties>
<otp.serialization.version.id>21</otp.serialization.version.id>
<otp.serialization.version.id>22</otp.serialization.version.id>
<!-- Lib versions - keep list sorted on property name -->
<geotools.version>26.2</geotools.version>
<jackson.version>2.13.2</jackson.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.opentripplanner.routing.core.TraverseMode.BUS;
import static org.opentripplanner.routing.core.TraverseMode.WALK;

import io.micrometer.core.instrument.Metrics;
import java.io.File;
import java.net.URISyntaxException;
import java.time.Duration;
Expand Down Expand Up @@ -58,7 +59,7 @@ static void setup() {

graph = ConstantsForTests.buildOsmGraph(osmPath);
addGtfsToGraph(graph, List.of(cobblincGtfsPath, martaGtfsPath, flexGtfsPath));
router = new Router(graph, RouterConfig.DEFAULT);
router = new Router(graph, RouterConfig.DEFAULT, Metrics.globalRegistry);
router.startup();

service = new RoutingService(graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opentripplanner.PolylineAssert.assertThatPolylinesAreEqual;

import io.micrometer.core.instrument.Metrics;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
Expand Down Expand Up @@ -157,7 +158,7 @@ public void calculateDirectFare() {
public void flexTripInTransitMode() {
var feedId = graph.getFeedIds().iterator().next();

var router = new Router(graph, RouterConfig.DEFAULT);
var router = new Router(graph, RouterConfig.DEFAULT, Metrics.globalRegistry);
router.startup();

// from zone 3 to zone 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.opentripplanner.ext.dataoverlay.api.DataOverlayParameters;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.plan.pagecursor.PageCursor;
import org.opentripplanner.routing.api.request.DebugRaptor;
import org.opentripplanner.routing.api.request.RoutingRequest;
import org.opentripplanner.routing.core.BicycleOptimizeType;
import org.opentripplanner.standalone.server.OTPServer;
Expand All @@ -39,7 +38,7 @@
*
* @author abyrd
*/
@SuppressWarnings("FieldMayBeFinal")
@SuppressWarnings({"FieldMayBeFinal", "unused"})
public abstract class RoutingResource {

private static final Logger LOG = LoggerFactory.getLogger(RoutingResource.class);
Expand Down Expand Up @@ -946,11 +945,9 @@ protected RoutingRequest buildRequest(MultivaluedMap<String, String> queryParame
request.itineraryFilters.debug = debugItineraryFilter;
}

if(debugRaptorPath != null || debugRaptorStops != null) {
request.raptorDebuging = new DebugRaptor()
.withStops(debugRaptorStops)
.withPath(debugRaptorPath);
}
request.raptorDebugging
.withStops(debugRaptorStops)
.withPath(debugRaptorPath);

if (useVehicleParkingAvailabilityInformation != null) {
request.useVehicleParkingAvailabilityInformation = useVehicleParkingAvailabilityInformation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.api.parameter;

import com.beust.jcommander.internal.Sets;
import java.io.Serial;
import org.opentripplanner.model.modes.AllowedTransitMode;
import org.opentripplanner.routing.api.request.RequestModes;
import org.opentripplanner.routing.api.request.StreetMode;
Expand All @@ -22,16 +23,21 @@
* into more efficient and useful representation in the routing request.
*/
public class QualifiedModeSet implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

public Set<QualifiedMode> qModes = Sets.newHashSet();

public QualifiedModeSet(String s) {
for (String qMode : s.split(",")) {
public QualifiedModeSet(String[] modes) {
for (String qMode : modes) {
qModes.add(new QualifiedMode(qMode));
}
}

public QualifiedModeSet(String s) {
this(s.split(","));
}

public RequestModes getRequestModes() {
StreetMode accessMode = null;
StreetMode egressMode = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public class DebugOutput {
public final TransitTimingOutput transitRouterTimes;

public DebugOutput(
long precalculationTime, long directStreetRouterTime, long transitRouterTime,
long precalculationTime,
long directStreetRouterTime,
long transitRouterTime,
long filteringTime, long renderingTime, long totalTime,
TransitTimingOutput transitRouterTimes
) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/opentripplanner/model/FeedScopedId.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* This file is based on code copied from project OneBusAway, see the LICENSE file for further information. */
package org.opentripplanner.model;

import java.io.Serial;
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Arrays;
Expand All @@ -19,6 +21,7 @@ public final class FeedScopedId implements Serializable, Comparable<FeedScopedId
*/
private static final char ID_SEPARATOR = ':';

@Serial
private static final long serialVersionUID = 1L;

private final String feedId;
Expand All @@ -33,6 +36,14 @@ public FeedScopedId(@NotNull String feedId, @NotNull String id) {
this.id = id;
}

/**
* Return a new FeedId if the id is not {@code null}, an empty string or contains whitespace only.
*/
@Nullable
public static FeedScopedId ofNullable(@NotNull String feedId, @Nullable String id) {
return id == null || id.isBlank() ? null : new FeedScopedId(feedId, id);
}

public String getFeedId() {
return feedId;
}
Expand Down Expand Up @@ -66,9 +77,8 @@ public int hashCode() {
public boolean equals(Object obj) {
if (this == obj) { return true; }
if (obj == null) { return false; }
if (!(obj instanceof FeedScopedId)) { return false; }
if (!(obj instanceof FeedScopedId other)) { return false; }

FeedScopedId other = (FeedScopedId) obj;
return feedId.equals(other.feedId) && id.equals(other.id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public ToStringBuilder addEnum(String name, Enum<?> value, Enum<?> ignoreValue)
}

public ToStringBuilder addObj(String name, Object obj) {
return addIfNotNull(name, obj);
return addObj(name, obj, null);
}

public ToStringBuilder addObj(String name, Object value, Object ignoreValue) {
return addIfNotIgnored(name, value, ignoreValue, Object::toString);
}

public ToStringBuilder addEntityId(String name, TransitEntity entity) {
Expand All @@ -121,8 +125,9 @@ public ToStringBuilder addDoubles(String name, double[] value, double ignoreValu
return addIt(name, Arrays.toString(value));
}

/** Add collection if not null or not empty, all elements are added */
public ToStringBuilder addCol(String name, Collection<?> c) {
return addIfNotNull(name, c);
return addIfNotNull(name, c==null || c.isEmpty() ? null : c);
}

public ToStringBuilder addColSize(String name, Collection<?> c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class RoutingWorker {
private static final Logger LOG = LoggerFactory.getLogger(RoutingWorker.class);

/** An object that accumulates profiling and debugging info for inclusion in the response. */
public final DebugTimingAggregator debugTimingAggregator = new DebugTimingAggregator();
public final DebugTimingAggregator debugTimingAggregator;
public final PagingSearchWindowAdjuster pagingSearchWindowAdjuster;

private final RoutingRequest request;
Expand All @@ -67,6 +67,7 @@ public RoutingWorker(Router router, RoutingRequest request, ZoneId zoneId) {
request.applyPageCursor();
this.request = request;
this.router = router;
this.debugTimingAggregator = new DebugTimingAggregator(router.meterRegistry, request.tags.getTimingTags());
this.transitSearchTimeZero = DateMapper.asStartOfService(request.getDateTime(), zoneId);
this.pagingSearchWindowAdjuster = createPagingSearchWindowAdjuster(router.routerConfig);
this.additionalSearchDays = createAdditionalSearchDays(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private TransitRouterResult route() {
);

// Route transit
var transitResponse = new RaptorService<>(router.raptorConfig)
.route(raptorRequest, requestTransitDataProvider);
var raptorService = new RaptorService<>(router.raptorConfig);
var transitResponse = raptorService.route(raptorRequest, requestTransitDataProvider);

checkIfTransitConnectionExists(transitResponse);

Expand Down Expand Up @@ -294,6 +294,13 @@ public static TransitRouterResult route(
AdditionalSearchDays additionalSearchDays,
DebugTimingAggregator debugTimingAggregator
) {
return new TransitRouter(request, router, transitSearchTimeZero, additionalSearchDays, debugTimingAggregator).route();
var transitRouter = new TransitRouter(
request,
router,
transitSearchTimeZero,
additionalSearchDays,
debugTimingAggregator
);
return transitRouter.route();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opentripplanner.transit.raptor.api.request.RaptorProfile;
import org.opentripplanner.transit.raptor.api.request.RaptorRequest;
import org.opentripplanner.transit.raptor.api.request.RaptorRequestBuilder;
import org.opentripplanner.transit.raptor.api.request.SearchParams;
import org.opentripplanner.transit.raptor.api.transit.RaptorTransfer;
import org.opentripplanner.transit.raptor.rangeraptor.SystemErrDebugLogger;
import org.opentripplanner.util.OTPFeature;
Expand Down Expand Up @@ -53,11 +54,16 @@ private RaptorRequest<TripSchedule> doMap(

if(request.pageCursor == null) {
int time = relativeTime(request.getDateTime());

int timeLimit = relativeTime(request.raptorOptions.getTimeLimit());

if (request.arriveBy) {
searchParams.latestArrivalTime(time);
searchParams.earliestDepartureTime(timeLimit);
}
else {
searchParams.earliestDepartureTime(time);
searchParams.latestArrivalTime(timeLimit);
}
searchParams.searchWindow(request.searchWindow);
}
Expand All @@ -77,6 +83,10 @@ private RaptorRequest<TripSchedule> doMap(
searchParams.maxNumberOfTransfers(request.maxTransfers);
}

request.raptorOptions.getOptimizations().forEach(builder::enableOptimization);
builder.profile(request.raptorOptions.getProfile());
builder.searchDirection(request.raptorOptions.getSearchDirection());

builder
.profile(RaptorProfile.MULTI_CRITERIA)
.enableOptimization(Optimization.PARETO_CHECK_AGAINST_DESTINATION)
Expand All @@ -95,19 +105,21 @@ private RaptorRequest<TripSchedule> doMap(
.addAccessPaths(accessPaths)
.addEgressPaths(egressPaths);

if(request.raptorDebuging != null) {
if(request.raptorDebugging.isEnabled()) {
var debug = builder.debug();
var debugLogger = new SystemErrDebugLogger(true);

debug.addStops(request.raptorDebuging.stops())
.setPath(request.raptorDebuging.path())
.debugPathFromStopIndex(request.raptorDebuging.debugPathFromStopIndex())
debug.addStops(request.raptorDebugging.stops())
.setPath(request.raptorDebugging.path())
.debugPathFromStopIndex(request.raptorDebugging.debugPathFromStopIndex())
.stopArrivalListener(debugLogger::stopArrivalLister)
.patternRideDebugListener(debugLogger::patternRideLister)
.pathFilteringListener(debugLogger::pathFilteringListener)
.logger(debugLogger);
}

builder.addTimingTags(request.tags.getTimingTags());

if(!request.timetableView && request.arriveBy) {
builder.searchParams().preferLateArrival(true);
}
Expand All @@ -116,6 +128,7 @@ private RaptorRequest<TripSchedule> doMap(
}

private int relativeTime(Instant time) {
if(time == null) { return SearchParams.TIME_NOT_SET; }
return (int)(time.getEpochSecond() - transitSearchTimeZeroEpocSecond);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.opentripplanner.routing.api.request;

import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.opentripplanner.model.base.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -35,7 +35,10 @@
* research.
* </ol>
*/
public class DebugRaptor {
public class DebugRaptor implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private static final Logger LOG = LoggerFactory.getLogger(DebugRaptor.class);
private static final Pattern FIRST_STOP_PATTERN = Pattern.compile("(\\d+)\\*");
Expand All @@ -45,11 +48,26 @@ public class DebugRaptor {
private List<Integer> path = List.of();
private int debugPathFromStopIndex = 0;


public DebugRaptor() { }

/** Avoid using clone(), use copy-constructor instead(Josh Bloch). */
public DebugRaptor(DebugRaptor other) {
this.stops = List.copyOf(other.stops);
this.path = List.copyOf(other.path);
this.debugPathFromStopIndex = other.debugPathFromStopIndex;
}

public boolean isEnabled() {
return !stops.isEmpty() || !path.isEmpty();
}

public List<Integer> stops() {
return stops;
}

public DebugRaptor withStops(String stops) {
if(stops == null) { return this; }
this.stops = split(stops);
return this;
}
Expand All @@ -59,6 +77,8 @@ public List<Integer> path() {
}

public DebugRaptor withPath(String path) {
if(path == null) { return this; }

this.path = split(path);
this.debugPathFromStopIndex = firstStopIndexToDebug(this.path, path);
return this;
Expand All @@ -73,8 +93,7 @@ private static List<Integer> split(String stops) {
if(stops == null) { return List.of(); }

return Arrays.stream(stops.split("[\\s,;_*]+"))
.map(Integer::parseInt)
.collect(Collectors.toUnmodifiableList());
.map(Integer::parseInt).toList();
}
catch (NumberFormatException e) {
LOG.error(e.getMessage(), e);
Expand Down
Loading

0 comments on commit 64e2495

Please sign in to comment.