Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel fetch requests in react native

I am developing a new app in React native and I need to make 20 fetches to my API in parallel. When I developed in phone gap, I could create 20 web workers for the AJAX calls to happen parallel. When I am executing 20 fetches in parallel in React native it looks like every fetch is taking longer than the one before. Like it has a queue of fetches and it won't run them together.

Is there any way to solve this? Now it takes like 1 minute to finish the fetches when in my Phonegap app it takes like 10 secs?

like image 635
DorR Avatar asked Nov 24 '17 18:11

DorR


1 Answers

The number of connections per host is limited to four in iOS. You need to increase HTTPMaximumConnectionsPerHost in NSURLSession.

The ugly way to test this is to directly add the following line to node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.m: NSURLSessionConfiguration

[configuration setHTTPMaximumConnectionsPerHost:25];

Read more: https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1407597-httpmaximumconnectionsperhost?language=objc

like image 56
Rikard Wissing Avatar answered Oct 26 '22 09:10

Rikard Wissing