Auto Scaling your Workers based on Queue Length
Join the DZone community and get the full member experience.
Join For Free- Dynamic scaling based on instances load (e.g CPU).
- Automatically launching and terminating instances.
- Supporting both on demand (expensive) instances and Spot (marginal cost) instances.
- Create a base AMI to a worker/consumer machine
- If your code tends to change you may define a method that will update to the latest code when machine is being launched
- A better solution may be using a DevOps platform such as Puppet or Chef.
- Define auto scaling initial configuration with an initial size of minimum and maximum number of instances (N = 1).
- Define a spot instance price: make it reasonable (not too high to avoid extra cost, and not too low to actually launch instances when needed).
- Create a cron that will run every 1 min and will check the queue length. This cron will terminate or launch instances by adjusting the auto scaling configuration minimum and maximum number of instances (N).
- What is the ratio of tasks in queue (Q) to running instances (for example R = 2)
- How quick do you want to reach this ratio. The quicker you do, the higher it will cost (instances that are billed hourly, may be terminated and relaunched again only few minutes after that).
- Keeping the ratio of queue length and running instances constant: for example: N = max[1, Q/R]
- Soften the ratio by using previous calculated number N': N = (N' + max[1, Q/R])/2
Published at DZone with permission of Moshe Kaplan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments