Parallel fetch requests in react native(react native 中的并行获取请求)
问题描述
我正在 react native
中开发一个新应用程序,我需要将 20 次获取
并行到我的 api
中.当我在电话间隙中进行开发时,我可以创建 20 个 web workers
来让 Ajax
调用并行发生.当我在 react native
中并行执行 20 fetches
时,看起来每次获取都比以前花费更长的时间.就像它有一个提取队列并且它不会一起运行它们.
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.
有没有办法解决这个问题?现在,在我的 phonegap 应用程序
中完成提取需要 1 分钟
,它需要 10 秒
..非常感谢您的帮助
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
..
Help would be much appreciated
推荐答案
iOS 中每个主机的连接数限制为四个.您需要在 NSURLSession 中增加 HTTPMaximumConnectionsPerHost.
The number of connections per host is limited to four in iOS. You need to increase HTTPMaximumConnectionsPerHost in NSURLSession.
测试这个丑陋的方法是直接将以下行添加到 node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.m:NSURLSessionConfiguration
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];
阅读更多:https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1407597-httpmaximumconnectionsperhost?language=objc
这篇关于react native 中的并行获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:react native 中的并行获取请求


- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06