Create a queue-based application server array.
A Server Arrays is made up of identical servers running in the cloud. Queue-based arrays are commonly used for performing batch processing tasks, where each server is a worker instance that's used to process items (work units) in an SQS input queue. Instances that are launched into an array must exist in the same region (e.g. AWS US-East), however you can control into which availability zones within that region that instances will be launched. Additional availability zone data transfer costs may apply.
You can use the RightScale Cloud Management Platform to monitor the number of items and scale up the number of instances in the server array accordingly. Currently, a server array can be configured to scale up based on the number of items in the queue or the age of the items in the queue. However, you are ultimately responsible for determining how to scale down the array. Since each application is unique, you must determine when an instance is no longer needed and expendable. There are several different ways that you can scale down your array.
- Manually terminate instances
- Create and configure a self-terminating script on each instance
- Use an external resource/instance to monitor instance usage in the array and determine which instance can/should be terminated.
There are two types of queue-based server arrays. They are both addressed in below.
- Based on the number of jobs in the queue
- Based on the amount of time a job is in the queue
Based on the amount of jobs in the queue
To create a server array, go to Manage -> Arrays and click New Array.
You will add the server array through the Add Server Array Assistant.
Provide the following information:
ServerTemplate - Choose the template that you would like to use in order to scale your deployment. This ServerTemplate will be used to create the new servers that will be added to the server array. Since you are scaling the number of application servers, you will need to select the latest version of the appropriate (PHP/Rails/TomCat) application ServerTemplate, not a frontend ServerTemplate. (If you need to make changes to the template, you will need to clone it.)
Note: Make sure that the Inputs for the ServerTemplate are properly configured and that they will boot correctly.
Based on the amount of time a job is in the queue
To create a server array, go to Manage -> Arrays and click a New button.
Provide the following information:
Nickname - Provide a Nickname for the server array. (e.g. MyFirstArray)
Array Type - select Queue-based as the type of server array. (The secondary configuration options will change accordingly.)
Deployment - Each server array must be associated with a particular deployment. Although you can attach more than one server array to a deployment.
Active - Leave the "Active" checkbox unchecked until you are ready to make the array active. WARNING: If checked, the array will be enabled after it is saved. New instances may be launched.
Cloud - Each array must be associated with a cloud or cloud region.
ServerTemplate - Select the ServerTemplate that will be used to create the worker instances in the server array. (If you need to make changes to the template, you will need to clone it.)
Note: Make sure that the Inputs for the ServerTemplate are properly configured and that they will boot correctly. Before making an array active, you might want to launch a test instance into the array to verify that a functional instance can be launched.
SSH Key & Security Group - Specify the appropriate SSH key and Security Group(s) that will be attached to the array.
Server Allocation Policy
Default min count - The minimum number of worker instances that must be operational at all times in the server array. You can set this value to zero to avoid idle server usage costs. But, if you have time-sensitive tasks that need to be processed immediately, you might want to use a value of at least one worker instance. Default = 1.
Default max count - The maximum number of servers that can be operational at any given time in the server array. Default = 20. Amazon will not let you launch more than 20 servers unless you submit a form request to increase this limit.
Availability Zone - Defines into which availability zone(s) new servers of your array will be launched. You can either select a specific zone or select the "Any" or "Weighted" option to disperse servers across multiple availability zones. By dispersing your servers across multiple availability zones, you are hopefully preventing all of your array servers from suddenly disappearing if an availability zone ever failed. The "Weighted" option allows you to control the ratio of server dispersion across all of the zones. For example, if you wanted to launch a majority of servers into a particular zone (us-east-1a), you can give 'us-east-1a' a larger weighted value than the other zones. Any positive integer is sufficient.
Note: Associated cross-zone data traffic rates do apply.
Elasticity function - defines how the server array should grow/shrink. Select sqs_item_age.
Elasticity params - defines the elasticity parameters that will be used to determine when a server array should be resized.
Max age - defines the threshold (in seconds) before a resize action occurs on the server array. (i.e. If an item's age is greater than or equal to the "max age," a new instance will be launched.) An item's age is determined by the Algorithm variable (max_10 or avg_10).
Regexp - each job task receives a timestamp when it's added to the queue. The timestamp is used to determine an item's "age" in the queue. It needs to contain a parenthesized sub-expression that, when matched, can be parsed as a date/time. The age is calculated by finding the difference between a timestamp specified in the body of the message and current time. The system finds this timestamp by matching a regular expression against the body of the message. We recommend that you create a field, created_at: with a UTC timestamp when creating a work_unit. You would specify the following regex string excluding the quotes "created_at: (\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d XXX)" where XXX is GMT or UTC depending on your machine. You would then specify the following for the elasticity function to determine the scaling event:
- If you are using UTC, copy and paste created_at: (\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d UTC) into the field.
- To verify that your regex expression matches the format of the timestamp in your work_unit go to Clouds -> AWS Global -> Queues and click on your input queue. Go to the Messages tab and click "View Top Item" link. You should now be able to see the format of the timestamp as it appears in the work_unit.
Algorithm - defines how an item's age will be determined, either by the average age or max (oldest) age. Default: "avg_10"
max_10 - the maximum age of 10 items in the queue. It will look for the oldest item in the sample.
avg_10 - the average age of 10 items in the queue.
Resize by - the number of instances that should be added/removed from a server array when a resize action occurs. Default = 1
Resize calm time - the time (in minutes) that must pass before another action can be taken on the server array. This variable helps prevent an array from being resized too frequently. Default = 5
Indicator - Select the input SQS queue that contains all of the job tasks.
Audit - (optional) Select the audit SQS queue that will store audit entries.
Audit entry analysis - If checked, it will populate a Statistics tab for your array. If unchecked, no Statistics tab will appear.
Currently, only one worker instance is running. A set of jobs was just added to the SQS input queue. Based on the elasticity parameters below, the server array will add 2 additional servers once an item (out of a sample of 10) has been in the SQS input queue for 30 seconds or longer. After 2 new servers have been launched, the server array must wait 10 minutes before it's allowed to resize again.
Max age: 30
Resize by: 2
Resize calm time: 10 min
Currently, there are 5 worker instances running. Based on the elasticity parameters below, the server array will add an additional server if the average age of 10 items in the SQS input queue is equal or greater to 2 minutes. After a new server is launched, the server array must wait 5 minutes before it's allowed to resize again.
Max age: 120
Resize by: 1
Resize calm time: 5 min