Skip to content

Commit ee18665

Browse files
committed
Merge branch 'remove-via-slowdown' into v2
2 parents 4c36d4e + adc10bc commit ee18665

4 files changed

Lines changed: 49 additions & 19 deletions

File tree

application/src/main/java/org/opentripplanner/framework/application/OTPFeature.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public enum OTPFeature {
2727
false,
2828
"Enable limiting transfers so that there is only a single transfer to each pattern."
2929
),
30+
CostlyAssertions(
31+
true,
32+
false,
33+
true,
34+
"Enable some resource consuming assertions which are typically not meant to be run in production."
35+
),
3036
DebugUi(
3137
true,
3238
false,
@@ -166,14 +172,19 @@ public enum OTPFeature {
166172

167173
private final boolean enabledByDefault;
168174
private final boolean sandbox;
169-
175+
private final boolean severeWarningWhenOn;
170176
private boolean enabled;
171177
private final String doc;
172178

173179
OTPFeature(boolean defaultEnabled, boolean sandbox, String doc) {
180+
this(defaultEnabled, sandbox, false, doc);
181+
}
182+
183+
OTPFeature(boolean defaultEnabled, boolean sandbox, boolean severeWarningWhenOn, String doc) {
174184
this.enabledByDefault = defaultEnabled;
175185
this.enabled = defaultEnabled;
176186
this.sandbox = sandbox;
187+
this.severeWarningWhenOn = severeWarningWhenOn;
177188
this.doc = doc;
178189
}
179190

@@ -190,6 +201,10 @@ public static void enableFeatures(Map<OTPFeature, Boolean> map) {
190201
public static void logFeatureSetup() {
191202
LOG.info("Features turned on: \n\t{}", valuesAsString(true));
192203
LOG.info("Features turned off: \n\t{}", valuesAsString(false));
204+
var featureWarnings = enabledValuesWithSevereWarningAsString();
205+
if (!featureWarnings.isBlank()) {
206+
LOG.warn("FEATURES THAT SHOULD BE TURNED OFF IN PRODUCTION: \n\t{}", featureWarnings);
207+
}
193208
}
194209

195210
/**
@@ -282,4 +297,11 @@ private static String valuesAsString(boolean enabled) {
282297
.map(Enum::name)
283298
.collect(Collectors.joining("\n\t"));
284299
}
300+
301+
private static String enabledValuesWithSevereWarningAsString() {
302+
return Arrays.stream(values())
303+
.filter(it -> it.enabled && it.severeWarningWhenOn)
304+
.map(Enum::name)
305+
.collect(Collectors.joining("\n\t"));
306+
}
285307
}

application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/mappers/RaptorRequestMapper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ private RaptorViaLocation mapViaLocation(ViaLocation input) {
271271
}
272272
}
273273
}
274-
return builder.build();
274+
var viaLocation = builder.build();
275+
if (OTPFeature.CostlyAssertions.isOn()) {
276+
// This check can have a bad performance if there are a lot of connections
277+
viaLocation.validateDuplicateConnections();
278+
}
279+
return viaLocation;
275280
}
276281
}
277282

doc/user/Configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Here is a list of all features which can be toggled on/off and their default val
228228
| `APIServerInfo` | Enable the server info endpoint. | ✓️ | |
229229
| `APIUpdaterStatus` | Enable endpoint for graph updaters status. | ✓️ | |
230230
| `ConsiderPatternsForDirectTransfers` | Enable limiting transfers so that there is only a single transfer to each pattern. | ✓️ | |
231+
| `CostlyAssertions` | Enable some resource consuming assertions which are typically not meant to be run in production. | ✓️ | |
231232
| `DebugUi` | Enable the debug GraphQL client and web UI and located at the root of the web server as well as the debug map tiles it uses. Be aware that the map tiles are not a stable API and can change without notice. Use the [vector tiles feature](sandbox/MapboxVectorTilesApi.md) if you want a stable map tiles API. | ✓️ | |
232233
| `ExtraTransferLegOnSameStop` | Should there be a transfer leg when transferring on the very same stop. Note that for in-seat/interlined transfers no transfer leg will be generated. | | |
233234
| `FloatingBike` | Enable floating bike routing. | ✓️ | |

raptor/src/main/java/org/opentripplanner/raptor/api/request/RaptorViaLocation.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private RaptorViaLocation(
4242
(int) MAX_WAIT_TIME.toSeconds(),
4343
"minimumWaitTime"
4444
);
45-
this.connections = validateConnections(connections);
45+
this.connections = mapConnections(connections);
4646
}
4747

4848
/**
@@ -98,6 +98,22 @@ public BitSet asBitSet() {
9898
.collect(BitSet::new, BitSet::set, BitSet::or);
9999
}
100100

101+
/// Compare all pairs to check for duplicates and non-optimal connections
102+
/// Avoid usage of this method because it can have a really bad performance.
103+
public void validateDuplicateConnections() {
104+
for (int i = 0; i < connections.size(); ++i) {
105+
var a = connections.get(i);
106+
for (int j = i + 1; j < connections.size(); ++j) {
107+
var b = connections.get(j);
108+
if (a.isBetterOrEqual(b) || b.isBetterOrEqual(a)) {
109+
throw new IllegalArgumentException(
110+
"All connection need to be pareto-optimal: (" + a + ") <-> (" + b + ")"
111+
);
112+
}
113+
}
114+
}
115+
}
116+
101117
@Override
102118
public boolean equals(Object o) {
103119
throw new UnsupportedOperationException("No need to compare " + getClass());
@@ -134,28 +150,14 @@ public String toString(RaptorStopNameResolver stopNameResolver) {
134150
return buf.append("}").toString();
135151
}
136152

137-
private List<RaptorViaConnection> validateConnections(List<BuilderStopAndTransfer> connections) {
153+
private List<RaptorViaConnection> mapConnections(List<BuilderStopAndTransfer> connections) {
138154
if (connections.isEmpty()) {
139155
throw new IllegalArgumentException("At least one connection is required.");
140156
}
141-
var list = connections
157+
return connections
142158
.stream()
143159
.map(it -> RaptorViaConnection.of(this, it.fromStop, it.transfer))
144160
.toList();
145-
146-
// Compare all pairs to check for duplicates and non-optimal connections
147-
for (int i = 0; i < list.size(); ++i) {
148-
var a = list.get(i);
149-
for (int j = i + 1; j < list.size(); ++j) {
150-
var b = list.get(j);
151-
if (a.isBetterOrEqual(b) || b.isBetterOrEqual(a)) {
152-
throw new IllegalArgumentException(
153-
"All connection need to be pareto-optimal: (" + a + ") <-> (" + b + ")"
154-
);
155-
}
156-
}
157-
}
158-
return list;
159161
}
160162

161163
public abstract static sealed class AbstractBuilder<T extends AbstractBuilder> {

0 commit comments

Comments
 (0)