Rails - sending multiple http requests to a anothe

2019-09-12 13:58发布

问题:

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?

(Note: the app hasn't launched and the numbers are hypothetical.)

回答1:

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

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.