Answer the question
In order to leave comments, you need to log in
How to work with DB in Gearman/RabbitMQ?
How should work with the database be done when the workers work in queues? For example, I'm using Gearman, writing a worker that endlessly listens to its "queue". When a task arrives, it makes a request, processes the data, and writes the result to the database.
If the connection is created at the beginning, and it will always be open, this is probably not entirely correct (and it will fall off by timeout). And if you make a connection every time a task is executed, it is not reasonable (for example, 10 tasks came in a second - and 10 times a second there was a connection / disconnection).
Answer the question
In order to leave comments, you need to log in
As an option - get yourself a timeout inside the worker to disconnect from the database server. Those. the worker started working, a task arrived - they connected to the database and processed it. Then, if there were no tasks for 30 seconds, they disconnected from the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question