Amazon Load Balancing and Auto Scaling

Amazon Load Balancing and Auto Scaling

Elastic Load Balancing

Elastic Load Balancing automatically distributes incoming application traffic across multiple Amazon EC2 instances. It enables you to achieve even greater fault tolerance in your applications, seamlessly providing the amount of load balancing capacity needed in response to incoming application traffic. Elastic Load Balancing detects unhealthy instances within a pool and automatically reroutes traffic to healthy instances until the unhealthy instances have been restored. We can enable Elastic Load Balancing within a single Availability Zone or across multiple zones for even more consistent application performance.

ELB Architecture

ELB routes traffic to your instances you register to be included with ELB.  The ELB instance has it’s own IP address and public DNS name.

One thing to keep in mind is that the requests are balanced between different availability zones and then evenly between the instances of that zone.  So if you have 10 instances in us-east-1a and 5 instances in us-east-1b your us-east-1b instances will service twice as much traffic per instance.  For that reason it is suggested that you keep your number of instances in each zone roughly equal.

Features of Elastic Load Balancing

  • Using Elastic Load Balancing, we can distribute incoming traffic across your Amazon EC2 instances in a single Availability Zone or multiple Availability Zones. Elastic Load Balancing automatically scales its request processing capacity in response to incoming application traffic.
  • Elastic Load Balancing can detect the health of Amazon EC2 instances. When it detects unhealthy load-balanced Amazon EC2 instances, it no longer routes traffic to those Amazon EC2 instances instead spreading the load across the remaining healthy Amazon EC2 instances.
  • Elastic Load Balancing supports the ability to stick user sessions to specific EC2 instances.
  • Elastic Load Balancing metrics such as request count and request latency are reported by Amazon CloudWatch.

Amazon EC2 Auto Scaling

What is Auto Scaling?

Amazon Auto Scaling is an easy-to-use web service designed to automatically launch or terminate EC2 instances based on user defined triggers. Users can set up Auto Scaling groups and associate triggers with these groups to automatically scale computing resources based on parameters such as bandwidth usage or CPU utilization. Auto Scaling groups can work across multiple Availability Zones – distinct physical locations for the hosted EC2 instances – so that if an Availability Zone becomes unhealthy or unavailable, Auto Scaling will automatically re-distribute applications to a healthy Availability Zone.

Auto Scaling allows you to automatically scale your Amazon EC2 capacity up or down according to conditions you define. With Auto Scaling, you can ensure that the number of Amazon EC2 instances you’re using scales up seamlessly during demand spikes to maintain performance, and scales down automatically during demand lulls to minimize costs. Auto Scaling is particularly well suited for applications that experience hourly, daily, or weekly variability in usage. Auto Scaling is enabled by Amazon CloudWatch and available at no additional charge beyond Amazon CloudWatch fees.

Features of Auto Scaling

  • Auto Scaling enables you to set conditions for when you want to scale up or down your Amazon EC2 usage. When one of the conditions is met, Auto Scaling automatically applies the action you’ve defined.
  • Auto Scaling enables your application to scale up Amazon EC2 instances seamlessly and automatically when demand spikes.
  • Auto Scaling allows you to automatically shed unneeded Amazon EC2 instances and save money when demand subsides.
  • Auto Scaling is enabled by Amazon CloudWatch and carries no additional fees.
  • If you’re signed up for the Amazon EC2 service, you’re already registered to use Auto Scaling and can begin using the feature via the Auto Scaling APIs or Command Line Tools.

Benefits of Amazon Auto Scaling

The core benefits of Auto Scaling:

Elastic Capacity—Automatically add compute capacity when application usage rises and remove itwhen usage drops

Cost Saving—Save compute costs by terminating underutilized instances automatically andlaunching new instances only on demand

Geographic Redundancy and Scalability—Automatically distribute, scale and balance applications over a wide geographic area using multiple Availability Zones.

Easier Maintenance—Automatically replace lost or unhealthy instances based on pre-defined triggers and thresholds

Ease of Use—Manage your instances spread across either one or several availability zones as a single entity, using simple command-line tools or programmatically via an easy to use web service API

Common Uses for Auto Scaling

Common Uses for Auto Scaling

Automatically Scaling Your Amazon EC2 Fleet

Auto Scaling enables you to closely follow the demand curve for your applications, reducing the need to provision Amazon EC2 capacity in advance. For example, you can set a condition to add new Amazon EC2 instances in increments of 3 instances to the Auto Scaling Group when the average CPU utilization of your Amazon EC2 fleet goes above 70 percent; and similarly, you can set a condition to remove Amazon EC2 instances in the same increments when CPU Utilization falls below 10 percent. Often, you may want more time to allow your fleet to stabilize before Auto Scaling adds or removes more Amazon EC2 instances. You can configure a cool-down period for your Auto Scaling Group, which tells Auto Scaling to wait for some time after taking an action before it evaluates the conditions again. Auto Scaling enables you to run your Amazon EC2 fleet at optimal utilization.

Maintaining Your Amazon EC2 Fleet at a Fixed Size

If you’re sure you want to run a fixed number of Amazon EC2 instances, Auto Scaling helps ensure you’ll always have that number of healthy Amazon EC2 instances available and running. You can create an Auto Scaling Group and set a condition that your Auto Scaling Group will always contain this fixed number of instances. Auto Scaling evaluates the health of each Amazon EC2 instance in your Auto Scaling Group and automatically replaces unhealthy Amazon EC2 instances to keep the size of your Auto Scaling Group fixed. This ensures that your application is getting the compute capacity you expect.

Auto Scaling with Elastic Load Balancing

Let’s say that you want to make sure that the number of healthy Amazon EC2 instances behind an Elastic Load Balancer is never fewer than two. You can use Auto Scaling to set this condition, and when Auto Scaling detects that this condition has been met, it automatically adds the requisite amount of Amazon EC2 instances to your Auto Scaling Group. Or, if you want to make sure that you add Amazon EC2 instances when latency of any one of your Amazon EC2 instances exceeds 4 seconds over any 15 minute period, you can set that condition, and Auto Scaling will take the appropriate action on your Amazon EC2 instances — even when running behind an Elastic Load Balancer. Auto Scaling works equally well for scaling Amazon EC2 instances whether you’re using Elastic Load Balancing or not.

To set up an auto-scaled, load balanced EC2 application following steps are required :

1) CreateLoadBalancer: An LoadBalancer is represented by a DNS name and provides the single destination to which all requests intended for your application should be directed. This Step is optional if you are not using LoadBalanced Application

Call CreateLoadBalancer with the following parameters :

§ AvailabilityZones = us-east-1a

§ LoadBalancerName = MyLoadBalancer

§ Listeners = lb-port=80,instance-port=8080,protocol=H

2)    CreateLaunchConfiguration: A LaunchConfiguration captures the parameters necessary to create new EC2 Instances. Only one launch configuration can be attached to an AutoScalingGroup at a time. When you attach a new or updated launch configuration to your AutoScalingGroup, any new instances will be launched using the new configuration parameters.

Call CreateLaunchConfiguration with the following parameters :

o Comuplsory Parameters :

§ ImageId = Unique ID (also called as AMI ID) of the Amazon Machine Image (AMI) which was assigned during registration.(We can get the same while bundling the AMI). Eg: ami-f7c5219e

§ LaunchConfigurationName = Name of the launch configuration to create. Eg : MyLaunchConfiguration.

§  InstanceType = This specifies the instance type of the EC2 instance. Eg : m1.small

o   Optional Parameters :

§ KeyName = The name of the EC2 key pair.

§   SecurityGroups = Names of the security groups with which

to associate the EC2 instances.

§   UserData = The user data available to the launched EC2 instances.

§   KernelId = ID of the kernel associated with the EC2 AMI.

§   RamdiskId = ID of the RAM disk associated with the EC2 AMI.

§   BlockDeviceMappings = Specifies how block devices are exposed to the instance. Each mapping is made up of a VirtualName and a DeviceName.

3)    CreateAutoScalingGroup: An AutoScalingGroup is a representation of an application running on multiple Amazon Elastic Compute Cloud (EC2) instances. The AutoScalingGroup can be used to automatically scale the number of instances or maintain a fixed number of instances.

Call CreateAutoScalingGroup with the following parameters :

o Comuplsory Parameters :

§  AutoScalingGroupName = Name of AutoScalingGroup.

§  AvailabilityZones = List of Availability Zones for the group.

§  LaunchConfigurationName = Name of launch configuration to use with group.

§  MinSize = Minimum size of group.

§  MaxSize = Maximum size of the group.

o   Optional Parameters :

§  LoadBalancerNames = List of LoadBalancers to use.

§  Cooldown = The amount of time after a scaling activity completes before any further trigger-related scaling activities can start. Time is in seconds.

4)    CreateOrUpdateScalingTrigger: In Auto Scaling, the trigger mechanism uses defined metrics and thresholds to initiate scaling of AutoScalingGroups.

Call CreateOrUpdateScalingTrigger with following Parameters.

o   Comuplsory Parameters :

§  AutoScalingGroupName = The name of the AutoScalingGroup to be associated with the trigger.

§  Dimensions = A list of dimensions associated with the metric used by the trigger to determine whether to fire.

§  MeasureName = The measure name associated with the metric used by the trigger to determine when to fire; for example, CPU, network I/O, or disk I/O. Valid Values: CPUUtilization | NetworkIn | NetworkOut | DiskWriteOps | DiskReadBytes | DiskReadOps | DiskWriteBytes

§  Statistic = The statistic that the trigger uses when fetching metric statistics to examine. Valid Values: Minimum | Maximum | Sum | Average

§  Period = The period associated with the metric statistics in seconds. Constraints: must be a multiple of 60

§  TriggerName = The name for this trigger. Constraints: Must be an alphanumeric string. Must be unique within the scope of the associated AutoScalingGroup.

§  LowerThreshold = The lower limit for the metric. If all data points in the last BreachDuration seconds exceed the upper threshold or fall below the lower threshold, the trigger activates.

§  LowerBreachScaleIncrement = The incremental amount to use when performing scaling activities when the lower threshold has been breached. Constraints: Must be a positive or negative integer followed by a % sign. Note : If you specify only a positive or negative number, then the AutoScalingGroup increases or decreases by the specified number of actual instances. If you specify a positive or negative number with a percent sign, the AutoScaling group increases or decreases by the specified percentage.

§  UpperThreshold = the upper limit for the metric. If all data points in the last BreachDuration seconds exceed the upper threshold or fall below the lower threshold, the trigger activates.

§  UpperBreachScaleIncrement = The incremental amount to use when performing scaling activities when the upper threshold has been breached. Note If you specify only a positive or negative number, then the AutoScalingGroup will increase or decrease by the specified number of actual instances. If you specify a positive or negative number with a percent sign, the AutoScaling group will increase or decrease by the specified percentage.

§  BreachDuration = the amount of time in seconds used to evaluate and determine if a breach is occurring. The service will look at data between the current time and the number of seconds specified in this parameter to see if a breach has occurred. Constraints: Must be a multiple of 60

o   Optional Parameters :

§  Unit = the standard unit of measurement for a given measure that the trigger uses when fetching metric statistics to examine. Valid Values: Seconds | Percent | Bytes | Bits| Count | Bytes/Second | Bits/Second | Count/Second | None.

§  CustomUnit = the user-defined custom unit for a given measure. This is used by the trigger when fetching the metric statistics it uses to determine whether to activate. Note Custom units are currently not available.

Projecting Costs

Auto Scaling is enabled by Amazon CloudWatch and carries no additional fees. Each instance launched by Auto Scaling is automatically enabled for monitoring and the Amazon CloudWatch monitoring charge will be applied. Partial hours are billed as full hours. Regular Amazon EC2 service fees apply and are billed separately

Advertisements
Explore posts in the same categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: