Skip to content

Commit

Permalink
Always parallelize cache building during server startup
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Dec 12, 2024
1 parent 1bf3f65 commit cded867
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ public RaptorTransferIndex(
this.reversedTransfers = reversedTransfers.stream().map(List::copyOf).toArray(List[]::new);
}

/**
* Create an index to be put into the transfer cache
*
* @param isRuntimeRequest true if the request originates from the client during the runtime,
* false if the request comes from transferCacheRequests in router-config.json
*/
public static RaptorTransferIndex create(
List<List<Transfer>> transfersByStopIndex,
StreetSearchRequest request
StreetSearchRequest request,
boolean isRuntimeRequest
) {
var forwardTransfers = new ArrayList<List<RaptorTransfer>>(transfersByStopIndex.size());
var reversedTransfers = new ArrayList<List<RaptorTransfer>>(transfersByStopIndex.size());
Expand All @@ -38,7 +45,9 @@ public static RaptorTransferIndex create(
}

var stopIndices = IntStream.range(0, transfersByStopIndex.size());
if (OTPFeature.ParallelRouting.isOn()) {
// we want to always parallelize the cache building during the startup
// and only parallelize during runtime requests if the feature flag is on
if (!isRuntimeRequest || OTPFeature.ParallelRouting.isOn()) {
stopIndices = stopIndices.parallel();
}
stopIndices.forEach(fromStop -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void put(List<List<Transfer>> transfersByStopIndex, RouteRequest request)
final CacheKey cacheKey = new CacheKey(transfersByStopIndex, request);
final RaptorTransferIndex raptorTransferIndex = RaptorTransferIndex.create(
transfersByStopIndex,
cacheKey.request
cacheKey.request,
false
);

LOG.info("Initializing cache with request: {}", cacheKey.options);
Expand All @@ -58,7 +59,7 @@ private CacheLoader<CacheKey, RaptorTransferIndex> cacheLoader() {
@Override
public RaptorTransferIndex load(CacheKey cacheKey) {
LOG.info("Adding runtime request to cache: {}", cacheKey.options);
return RaptorTransferIndex.create(cacheKey.transfersByStopIndex, cacheKey.request);
return RaptorTransferIndex.create(cacheKey.transfersByStopIndex, cacheKey.request, true);
}
};
}
Expand Down

0 comments on commit cded867

Please sign in to comment.