Answer the question
In order to leave comments, you need to log in
How to store result of 200+ threads in DB?
There is an application whose task is to make a search for the user's request. The procedure is approximately the following: user request -> request to various APIs -> getting results from the API -> saving to the database -> data processing -> response to the user. Such a search should work quickly (within 15-20 seconds).
For one user request, it is supposed to make 200+ requests to the API with different parameters.
Now 200 threads are created for the search, which make requests to the API and write to the database. The problem is that this solution looks very limited - if another user comes and does a search, another 200+ threads will be created and the response time will decrease significantly.
I am looking towards using Sidekiq, RabbitMQ, so that I can add search servers and parallelize the search (for example, each server executes queries with different parameters), but I have doubts - what to do with MySQL? Will there be a problem with max_connections if several servers write to the same database? What other solutions can be considered so that it is possible to parallelize the search, and at the end of the work of all, receive the "search completed" event in order to process the data?
Application - Rails, database - MySQL.
Answer the question
In order to leave comments, you need to log in
The most universal solution is of course the job queue. Do not get carried away creating connections to the database. It's better to have a few connections that are fast than a bunch of connections that are slow.
At the very least, you can always write a solution (ala on Erlang) that will take on the work of parallelization, you just need to call the necessary http-api of such a server and get a response.
To make the database work quickly, you can install a bunch of mysql slave servers, and also access them. Of course, you can only write to one. In general, it all depends on your task. You have a stingy description of what you want to do and why.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question