I am creating an application that requires significant image processing. We build it in a distributed estate with an arbitrary number of rendering machines that receive requests for rendering images from the RabbitMQ exchange.
Since the image request may appear during rendering processing, and because I do not want to duplicate the work of the two rendering servers, I created a column in the mySQL image table called is_rendering as a boolean.
When the render server receives a render request, it performs a series of steps that look like this:
- Select to update the image line.
- If is_rendering == true interrupt the visualization request
- Set is_rendering == true and complete the transaction
- Display image and save thumbnail in public store
- Set is_rendering == false and return
This definitely works, but I'm worried that these frequent database updates seem a little dumb. In addition, I am considering the edge case where the rendering server fails in the middle of rendering and leaves is_rendering == true, preventing this image from ever being displayed. The solution I am considering for this problem is to change the is_rendering column from the tinyint (1) field to datetime and save the lock date as a “true” value, and null as a “false” value. A periodic system health check can select all rows with the value is_rendering for a certain period of time and release the lock in this case.
Is this a reasonable approach to this problem or are there other more elegant approaches that I should consider?
Andrew
source share