简体   繁体   English

angular2异步http请求

[英]angular2 async http requests

May be I don't understand how async requests should work, but from my point of view 1 ajax or 10 should took almost the same time to be finished. 可能是我不了解异步请求应如何工作,但是从我的角度来看,完成1个ajax或10个ajax几乎需要花费相同的时间。 Right now I'm facing a problem, I'm sending 3 ajax requests at the same time, and it took about 3 seconds for the first ajax, 15 seconds for the second, and 18 for the last. 现在,我遇到了一个问题,我同时发送了3个Ajax请求,第一个Ajax大约花费了3秒,第二个Ajax花费了15秒,最后一个花费了18秒。 But if I send only first ajax - it's took 3 seconds, only second - 15 seconds, only third - 1 second. 但是,如果我只发送第一个Ajax,则花费3秒,仅花费第二个-15秒,仅花费第三个-1秒。 So, in other words it doesn't matter if I send 3 ajax together 因此,换句话说,我一起发送3个ajax都没关系

this.contractService.saveContractsForOpportunity(selectedContracts).subscribe(data => {

});
this.contractService.saveContractsForOpportunity(selectedContracts).subscribe(data => {

});
this.contractService.saveContractsForOpportunity(selectedContracts).subscribe(data => {

});

Or if I send it one by one like this 或者我像这样一一发送

this.contractService.saveContractsForOpportunity(selectedContracts).subscribe(data => {
    this.contractService.saveContractsForOpportunity(selectedContracts).subscribe(data => {
       this.contractService.saveContractsForOpportunity(selectedContracts).subscribe(data => {

       }); 
    });        
});

It tooks the same time to be finished 需要花费相同的时间才能完成 在此处输入图片说明

May be it's only about backend or server configuration? 可能仅仅是后端或服务器配置?

Most likely your problem lies on the server side. 您的问题很可能出在服务器端。 Does the server allow handling multiple requests from the same IP in parallel? 服务器是否允许并行处理来自同一IP的多个请求?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM