简体   繁体   中英

How to configure memory based Auto Scaling on Amazon EC2?

I am deploying a rails application on EC2 instances, where I want to configure Auto Scaling to be used with an Elastic Load Balancer. On a particular threshold I want to spawn a new instance. While configuring trigger for auto scaling group, we have options for CPU Utilization, Network or disk IO; but being a rails application, I will face resource crunch on memory rather than CPU or IO.

Has anyone configured EC2 Auto Scaling for a rails application successfully? What is the preferred way of using AWS with rails?

FYI: I am using passenger as application server.

Thanks for your time.

I have not done it with Rails, but with java in Tomcat.We used tomcat valves/scripts to detect the memory usage and post it in Amazon cloudWatch as Custom cloud watch metrics. You can create an scale out trigger based on cloudwatch alarm monitoring this metric.

Some sections of the above technique can even be overlapped for rails.

Actually, I think you should try to tune your Passenger configuration based on the instance type you are using (here is an article about this: http://blog.scoutapp.com/articles/2009/12/08/production-rails-tuning-with-passenger-passengermaxprocesses ). This should ensure that at full load you are using all the RAM available but you are not spawning more passenger instances than RAM available.

This, in my experience leads to saturating all the resources (CPU & RAM) and you could trigger an autoscale policy based on CPU usage. You also should tweak the instance type in order to achieve the best performance (I've used cc1.xlarge instance with a fair amount of success).

If you're set on autoscaling based on RAM, you should be able to create a metric on CloudWatch that is monitoring RAM usage and autoscale using that metric. Creating a metric is just publishing the metric data at regular intervals using the CloudWatch API ( http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/CloudWatch/Metric.html ). You could create a rails background task that runs every minute and publishes the metric data.

i think you can use the new signaling feature, monitor the memory metric and start the instance using api:

http://aws.typepad.com/aws/2010/12/amazon-cloudwatch-alarms.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM