calling AGSRouteTask.solve in Parallel (IOS)

386
1
09-19-2019 10:45 AM
RAMESHBACHIRAJU
New Contributor II

We are using Online services to fetch routes. We have an application where we find etas and routes in parallel for multiple locations. Some of the locations are far off, and we see that Route comes after a long time.

When we are trying to solve many routes in parallel, we find that RouteTask is taking time (especially with far away locations)

Set of Questions

  • Is there away to execute RoueTasks in parallel?
  • Is it possible to prioritise among the parallel RouteTasks? Is there a way to run them in separate AGSOperationQueue?
  • For some routes we only want ETAs, what should be the default params for only fetching ETAs without directions and rest of the details?
  • We have created separate RouteTasks for etas and calculation of detail routes - This is not helping our case. What could be the reason?
0 Kudos
1 Reply
Nicholas-Furness
Esri Regular Contributor

Hi Ramesh,

Some answers for you:

  1. Is there a way to execute RoueTasks in parallel?
    A: This should be the default behavior. Create a single AGSRouteTask, and call solve() multiple times. These operations will be run on the shared AGSOperationQueue which is by default configured to allow unlimited concurrent operations (see maxConcurrentOperationCount). Correction: We use an internal queue per host that is configured to allow as many concurrent sessions as NSURLSessionConfiguration allows (we set this to 6). This enables us to avoid triggering timeouts at the NSURLSession level if a lot of requests are sent at once.
  2. Is it possible to prioritise among the parallel RouteTasks? Is there a way to run them in separate AGSOperationQueue?
    A: The prioritization for parallel requests would need to be on the service side, and that behavior is not exposed. But in terms of the requests you make, they are queued up and kicked off in the order they are submitted.
  3. For some routes we only want ETAs, what should be the default params for only fetching ETAs without directions and rest of the details?
    A: Get the default parameters as usual, and then you should set returnDirections to false, and routeShapeType to .none. Note that defaultRouteParametersWithCompletion() caches results for a given route service, so is very fast to run once the service has been loaded (either explicitly with load() or on first use).
  4. We have created separate RouteTasks for etas and calculation of detail routes - This is not helping our case. What could be the reason?
    A: The NSURLSessionConfiguration per host constraint is the limiting factor here. If you create multiple RouteTasks pointing to the same URL, NSURLSession will still limit the total number of concurrent requests to that service. So from an implementation perspective, assuming you're using the World Routing Service, a single AGSRouteTask should suffice. What's important is the AGSRouteParameters you pass in when you call solve(). You could create two separate template parameters (one for ETA and one for detailed directions) and use copies of those with appropriate stops assigned. But as mentioned above, getting the default parameters is a very lightweight operation.

Also, I recommend you take a moment to read this page: https://community.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-ios/blo... - it will give you a good idea of how the iOS Runtime handles threading (by default it will generally do what you want it to and get out of your way, performing things in the background).

Does that help?

0 Kudos