Reputation: 39
I have a service which sends tasks to a worker contained in a Docker image. Now I want to scale it using AWS FreeTier (so AutoScale group is not an option?). I tested an t2.micro instance build using this image and everything works fine. If I create x instances manually how do I balance the load between them? Can the instance set a flag saying it can accept more requests? Memory and CPU usage levels might not be helpful because of cleanup logic. It could be still running with low CPU and memory usage.
Upvotes: 1
Views: 116
Reputation: 46839
I would suggest using SQS. Let the instances 'pull' work, instead of trying to 'push' work to them.
Put each 'task' into the SQS queue, and the instance request a task to work on when they are ready. If they successfully complete the task, then the worker/instance removes it from the Queue, and can ask for another task to work on.
If the instance fails for some reason, the task will eventually be put back in the queue automatically, and can be picked up by another worker.
While one worker has a task-item to work on, it won't also be given to another worker at the same time (caveat: except in extremely rare cases and likely under very high volumes - personally I have never had it happen, but you need to consider the possibility).
Upvotes: 3