向另一台服务器发送多个http请求

向另一台服务器发送多个http请求

本文介绍了Rails - 向另一台服务器发送多个http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1000个用户在同一时间向我的Rails服务器发出请求。对于每个用户,我需要向其他服务器发出50个http请求,每个服务器需要1秒钟才能响应。如何编写应用程序代码以便我尽快回复用户?

1000 users make a request to my Rails server at exactly the same time. For each user, I need to make 50 http requests to other servers, each taking 1 second to respond. How do I go about coding my application so that I can respond to the users as quickly as possible?

(注意:应用程序尚未启动且数字是假设的。)

推荐答案

我认为你需要用ActiveJob实现一个Job排队系统,例如Sidekiq 。

I think you need to implement a Job queuing system with ActiveJob and for example Sidekiq.

所以你的工作人员可以发出这50个http请求。

So your workers can make these 50 http requests.

在服务器发出这些请求时,您必须告诉用户耐心等待。通过这种方式,用户立即得到一条消息,表明正在进行某些操作,然后您可以通知用户作业是否已完成。

You'll have to tell the user to be patient while your server is making these requests. This way, the user get's instantly a message which says that there's something going on, you could then notify the user if the jobs have finished.

这篇关于Rails - 向另一台服务器发送多个http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 07:32