liveBook · Manning

Queue depth

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

Queue length is the number of messages waiting in a message queue at a given time.

Queue depth is the number of messages waiting in a message queue at a given time. In Amazon SQS, it indicates how much asynchronous work remains for consumers to process. section 17.3.2 section 17.3

Queue depth can drive capacity changes. A CloudWatch alarm monitors the SQS ApproximateNumberOfMessagesVisible metric; when the threshold is exceeded, it triggers an Auto Scaling policy. section 17.3.2

Use queue depth to connect workload pressure with worker capacity:

  • Scale up when the queue reaches five messages by adding an EC2 instance. section 17.3.2
  • Scale down when the queue becomes empty, using an alarm and policy with opposite values. section 17.3.2
  • Prefer step scaling here because message count does not directly correlate with the number of instances processing messages. section 17.3.2

URL screenshot workers

A bookmark sends a URL and identifier to an SQS queue. Node.js applications on EC2 poll the queue, create screenshots, and store them in S3. Queue depth controls the desired number of worker instances. section 17.3.2

Listing 17.7 Monitoring the length of the SQS queue
# [...]
HighQueueAlarm:
  Type: 'AWS::CloudWatch::Alarm'
  Properties:
    EvaluationPeriods: 1                            #1
    Statistic: Sum                                  #2
    Threshold: 5                                    #3
    AlarmDescription: 'Alarm if queue length is higher than 5.'
    Period: 300                                     #4
    AlarmActions:                                   #5
    - !Ref ScalingUpPolicy
    Namespace: 'AWS/SQS'                            #6
    Dimensions:                                      #7
    - Name: QueueName
      Value: !Sub '${SQSQueue.QueueName}'
    ComparisonOperator: GreaterThanThreshold        #8
    MetricName: ApproximateNumberOfMessagesVisible  #9
# [...]

Inspect the CloudWatch alarm configuration for monitoring SQS queue depth, including its threshold, period, namespace, and metric name. section 17.3.2

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Defines queue depth and demonstrates threshold alarms and step scaling, but does not develop a general metric model.
Examples
Demonstrates URL screenshot workers, a five-message threshold, CloudFormation alarms, and one-instance step scaling.
What you can do after
Operate/configure queue-based scaling by defining a CloudWatch alarm and step-scaling policy for an Auto Scaling group.
How it connects
Connects Amazon SQS with Amazon CloudWatch, EC2, Auto Scaling, asynchronous decoupling, and stateless servers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.