Skip to content

Commit

Permalink
Merge branch 'dev' into speed-shapefile-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
ansoncfit committed Feb 22, 2024
2 parents e611e93 + d12f763 commit 90bfe97
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
23 changes: 9 additions & 14 deletions src/main/java/com/conveyal/analysis/components/broker/Broker.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ public interface Config {
boolean testTaskRedelivery ();
}

private Config config;
private final Config config;

// Component Dependencies
private final FileStorage fileStorage;
private final EventBus eventBus;
private final WorkerLauncher workerLauncher;

private final ListMultimap<WorkerCategory, Job> jobs =
MultimapBuilder.hashKeys().arrayListValues().build();
private final ListMultimap<WorkerCategory, Job> jobs = MultimapBuilder.hashKeys().arrayListValues().build();

/**
* The most tasks to deliver to a worker at a time. Workers may request less tasks than this, and the broker should
Expand All @@ -114,40 +113,36 @@ public interface Config {
* The value should eventually be tuned. The current value of 16 is just the value used by the previous sporadic
* polling system (WorkerStatus.LEGACY_WORKER_MAX_TASKS) which may not be ideal but is known to work.
*/
public final int MAX_TASKS_PER_WORKER = 16;
public static final int MAX_TASKS_PER_WORKER = 16;

/**
* Used when auto-starting spot instances. Set to a smaller value to increase the number of
* workers requested automatically
*/
public final int TARGET_TASKS_PER_WORKER_TRANSIT = 800;
public final int TARGET_TASKS_PER_WORKER_NONTRANSIT = 4_000;
public static final int TARGET_TASKS_PER_WORKER_TRANSIT = 800;
public static final int TARGET_TASKS_PER_WORKER_NONTRANSIT = 4_000;

/**
* We want to request spot instances to "boost" regional analyses after a few regional task
* results are received for a given workerCategory. Do so after receiving results for an
* arbitrary task toward the beginning of the job
*/
public final int AUTO_START_SPOT_INSTANCES_AT_TASK = 42;
public static final int AUTO_START_SPOT_INSTANCES_AT_TASK = 42;

/** The maximum number of spot instances allowable in an automatic request */
public final int MAX_WORKERS_PER_CATEGORY = 250;
public static final int MAX_WORKERS_PER_CATEGORY = 250;

/**
* How long to give workers to start up (in ms) before assuming that they have started (and
* starting more on a given graph if they haven't.
*/
public static final long WORKER_STARTUP_TIME = 60 * 60 * 1000;


/** Keeps track of all the workers that have contacted this broker recently asking for work. */
private WorkerCatalog workerCatalog = new WorkerCatalog();

/**
* These objects piece together results received from workers into one regional analysis result
* file per job.
*/
private static Map<String, MultiOriginAssembler> resultAssemblers = new HashMap<>();
/** These objects piece together results received from workers into one regional analysis result file per job. */
private Map<String, MultiOriginAssembler> resultAssemblers = new HashMap<>();

/**
* keep track of which graphs we have launched workers on and how long ago we launched them, so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,11 @@ private RegionalAnalysis updateRegionalAnalysis (Request request, Response respo
* the given regional analysis.
*/
private JsonNode getScenarioJsonUrl (Request request, Response response) {
RegionalAnalysis regionalAnalysis = Persistence.regionalAnalyses
.findByIdIfPermitted(request.params("_id"), UserPermissions.from(request));
RegionalAnalysis regionalAnalysis = Persistence.regionalAnalyses.findByIdIfPermitted(
request.params("_id"),
DBProjection.exclude("request.scenario.modifications"),
UserPermissions.from(request)
);
// In the persisted objects, regionalAnalysis.scenarioId seems to be null. Get it from the embedded request.
final String networkId = regionalAnalysis.bundleId;
final String scenarioId = regionalAnalysis.request.scenarioId;
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/conveyal/analysis/persistence/MongoMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ public int size() {
return (int) wrappedCollection.getCount();
}

public V findByIdFromRequestIfPermitted(Request request) {
return findByIdIfPermitted(request.params("_id"), UserPermissions.from(request));
}

public V findByIdIfPermitted(String id, UserPermissions userPermissions) {
V result = wrappedCollection.findOneById(id);
/**
* `fields` is nullable.
*/
public V findByIdIfPermitted(String id, DBObject fields, UserPermissions userPermissions) {
V result = wrappedCollection.findOneById(id, fields);

if (result == null) {
throw AnalysisServerException.notFound(String.format(
Expand All @@ -61,6 +60,14 @@ public V findByIdIfPermitted(String id, UserPermissions userPermissions) {
}
}

public V findByIdIfPermitted(String id, UserPermissions userPermissions) {
return findByIdIfPermitted(id, null, userPermissions);
}

public V findByIdFromRequestIfPermitted(Request request) {
return findByIdIfPermitted(request.params("_id"), UserPermissions.from(request));
}

public V get(String key) {
return wrappedCollection.findOneById(key);
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/conveyal/r5/analyst/TravelTimeComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@ public OneOriginResult computeTravelTimes() {
// The generalized cost calculations currently increment time and weight by the same amount.
sr.quantityToMinimize = StreetRouter.State.RoutingVariable.DURATION_SECONDS;
sr.route();
// Change to walking in order to reach transit stops in pedestrian-only areas like train stations.
// This implies you are dropped off or have a very easy parking spot for your vehicle.
// This kind of multi-stage search should also be used when building egress distance cost tables.
if (accessMode != StreetMode.WALK) {
sr.keepRoutingOnFoot();
}

if (request.hasTransit()) {
// Change to walking in order to reach transit stops in pedestrian-only areas like train stations.
// This implies you are dropped off or have a very easy parking spot for your vehicle.
// This kind of multi-stage search should also be used when building egress distance cost tables.
// Note that this can take up to twice as long as the initial car/bike search. Do it only when the
// walking is necessary, and when the radius of the car/bike search is limited, as for transit access.
if (accessMode != StreetMode.WALK) {
sr.keepRoutingOnFoot();
}
// Find access times to transit stops, keeping the minimum across all access street modes.
// Note that getReachedStops() returns the routing variable units, not necessarily seconds.
// TODO add logic here if linkedStops are specified in pickupDelay?
Expand Down

0 comments on commit 90bfe97

Please sign in to comment.