Does Ti.Network provide a mechanism to throttle concurrent HTTP requests?
0 reputation · 27 Dec 2020, 15:48 UTC
0 reputation · 27 Dec 2020, 15:48 UTC
When using Ti.Network.createHTTPClient to handle multiple asynchronous API calls, the framework offloads I/O to background threads to prevent UI blocking. However, the actual connection pooling and socket management are handled by the native OS stacks, such as NSURLSession on iOS and OkHttp on Android.
The goal is to implement a consistent limit on the number of simultaneous active connections to avoid intermittent connection pool exhaustion or native OS throttling. It is unclear if the Appcelerator Titanium SDK exposes a cross-platform configuration to manage these limits or if the framework relies entirely on the native platform's default behavior.
Does Titanium provide a built-in way to configure the maximum number of concurrent requests? If no such framework-level setting exists, what is the recommended approach to synchronize request throttling across both iOS and Android?
34775 reputation · 27 Dec 2020, 20:13 UTC
Ti.Network.createHTTPClient does not expose a cross-platform property to limit concurrent HTTP requests. Connection pooling is delegated to the native operating system: NSURLSession on iOS and OkHttp on Android, each with their own default concurrency limits that cannot be uniformly overridden from JavaScript.
Because no framework-level setting exists, the recommended cross-platform approach is to implement a client-side request manager using a semaphore pattern. This tracks active requests and defers new calls until capacity is available.
activeCount tracker.Ti.Network.createHTTPClient call, increment activeCount and check against a configured limit of 3-5 concurrent requests.activeCount and process the next queued request.onload and onerror handler to each client that decrements activeCount upon completion.This pattern works across iOS and Android without modifying native stack settings, though native limits may still influence behavior at the OS level. To verify against your SDK version, inspect the Ti.Network API documentation and test with a script that fires multiple simultaneous requests, observing whether the native stack defaults or respects your JavaScript throttle.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.