We have an ECS cluster with 3 EC2 instances. In this cluster we have a bunch of services running, all separate apps with 1 task.
Frequently when I try to run a new service, ECS tries to run the task in an EC2 instance with not enough memory/CPU, while there is a different instance available with more than enough. In fact, there are now 2 instances with both 5 tasks, and 1 instance with only 1.
What could be the reason of this weird division of tasks? I’ve tried every possible task placement strategy but that doesn’t seem to make a difference. Or perhaps task placement is only relevant for multiple tasks from the same service? That still doesn’t explain why it won’t just run on an instance that does have enough memory.
Thanks for your suggestions!
Edit: this has been a recurring issue, and is not related to the outages at the time of posting a.f.a.i.k.
The task placement strategies use different criteria for determining where to place the task. The binpack strategy does exactly what you’re seeing, but not what you want. It intentionally places more tasks on one instance, rather than spreading them evenly.
I think if you want to get the tasks to spread evenly, you can use the following strategy,
but I also don’t think this will work perfectly such that you will have an even distribution all the time. If you’re seeing issues running out of memory, just create more instances using either autoscaling or by setting a higher number of desired instances. 3 instances is a low number anyways, I’d recommend 9 for availability purposes, if you can afford it.