F
F
Fixis2016-01-13 09:56:55
RabbitMQ
Fixis, 2016-01-13 09:56:55

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

2 answer(s)
V
Vadim Stepanov, 2016-01-21
@Fixis

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.

F
Fixis, 2016-01-22
@Fixis

Yes, that's how it started to be implemented)
Thank you!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question