Skip to content

Commit d0adbfc

Browse files
committed
Defer GtfsRealtime performance issue
1 parent 7cf32a0 commit d0adbfc

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

reader-gtfs/src/main/java/com/graphhopper/gtfs/dropwizard/RealtimeBundle.java

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
package com.graphhopper.gtfs.dropwizard;
2020

21+
import com.graphhopper.reader.gtfs.GtfsStorage;
2122
import com.graphhopper.reader.gtfs.RealtimeFeed;
2223
import io.dropwizard.ConfiguredBundle;
2324
import io.dropwizard.client.HttpClientBuilder;
2425
import io.dropwizard.setup.Bootstrap;
2526
import io.dropwizard.setup.Environment;
2627
import org.apache.http.client.HttpClient;
28+
import org.glassfish.hk2.api.Factory;
2729
import org.glassfish.hk2.utilities.binding.AbstractBinder;
2830

31+
import javax.inject.Inject;
2932
import javax.inject.Singleton;
3033

3134
public class RealtimeBundle implements ConfiguredBundle<RealtimeBundleConfiguration> {
@@ -36,17 +39,45 @@ public void initialize(Bootstrap<?> bootstrap) {
3639

3740
@Override
3841
public void run(RealtimeBundleConfiguration configuration, Environment environment) {
39-
final HttpClient httpClient = new HttpClientBuilder(environment)
40-
.using(configuration.gtfsrealtime().getHttpClientConfiguration())
41-
.build("gtfs-realtime-feed-loader");
42-
environment.jersey().register(new AbstractBinder() {
43-
@Override
44-
protected void configure() {
45-
bind(httpClient).to(HttpClient.class);
46-
bind(configuration).to(RealtimeBundleConfiguration.class);
47-
bindFactory(RealtimeFeedLoadingCache.class, Singleton.class).to(RealtimeFeed.class);
48-
}
49-
});
42+
if (configuration.gtfsrealtime().getFeeds().isEmpty()) {
43+
environment.jersey().register(new AbstractBinder() {
44+
@Override
45+
protected void configure() {
46+
bindFactory(EmptyRealtimeFeedFactory.class).to(RealtimeFeed.class).in(Singleton.class);
47+
}
48+
});
49+
} else {
50+
final HttpClient httpClient = new HttpClientBuilder(environment)
51+
.using(configuration.gtfsrealtime().getHttpClientConfiguration())
52+
.build("gtfs-realtime-feed-loader");
53+
environment.jersey().register(new AbstractBinder() {
54+
@Override
55+
protected void configure() {
56+
bind(httpClient).to(HttpClient.class);
57+
bind(configuration).to(RealtimeBundleConfiguration.class);
58+
bindFactory(RealtimeFeedLoadingCache.class, Singleton.class).to(RealtimeFeed.class);
59+
}
60+
});
61+
}
5062
}
5163

64+
private static class EmptyRealtimeFeedFactory implements Factory<RealtimeFeed> {
65+
66+
private final GtfsStorage staticGtfs;
67+
68+
@Inject
69+
EmptyRealtimeFeedFactory(GtfsStorage staticGtfs) {
70+
this.staticGtfs = staticGtfs;
71+
}
72+
73+
@Override
74+
public RealtimeFeed provide() {
75+
return RealtimeFeed.empty(staticGtfs);
76+
}
77+
78+
@Override
79+
public void dispose(RealtimeFeed realtimeFeed) {
80+
81+
}
82+
}
5283
}

reader-gtfs/src/main/java/com/graphhopper/reader/gtfs/RealtimeFeed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public boolean isAdjacentToNode(int edge, int node) {
268268
Map<String, int[]> boardEdgesForTrip = new HashMap<>();
269269
Map<String, int[]> alightEdgesForTrip = new HashMap<>();
270270
Map<GtfsStorage.FeedIdWithTimezone, Integer> writableTimeZones = new HashMap<>(staticGtfs.getWritableTimeZones());
271-
Map<Integer, GtfsStorageI.PlatformDescriptor> platformDescriptorByEdge = new HashMap<>(staticGtfs.getPlatformDescriptorByEdge());
271+
Map<Integer, GtfsStorageI.PlatformDescriptor> platformDescriptorByEdge = new HashMap<>(staticGtfs.getPlatformDescriptorByEdge()); // FIXME: Too slow for production
272272

273273
feedMessages.forEach((feedKey, feedMessage) -> {
274274
GTFSFeed feed = staticGtfs.getGtfsFeeds().get(feedKey);

0 commit comments

Comments
 (0)