Creating Push Queues

This page describes how to create and customize a push queue, and how to examine the contents of a queue.

Using queue.yaml to create queues

To process a task, you must add it to a push queue. App Engine provides a default push queue. If you add all your tasks to the default queue you do not need to create a queue explicitly. If you want to customize the performance settings of the default queue, or supply two or more queues to organize task requests, you can create as many push queues as you need.

You cannot create queues dynamically in your program. You must define them in a queue.yaml file, which you upload to App Engine.

For example, this queue.yaml file defines two queues:

queue:
- name: queue-blue
  target: v2.task-module

- name: queue-red
  rate: 1/s

All tasks added to queue-blue are sent to the target module v2.task-module. The refresh rate of queue-red is changed from the default 5/s to 1/s. Tasks will be dequeued and sent to their targets at the rate of 1 task per second.

There are many other parameters that can be added to the queue.yaml file to customize the behavior of a push queue. For more information, see the queue.yaml reference.

Defining the push queue processing rate

You can control the rate at which tasks are processed in each of your queues by defining other directives, such as rate, bucket_size, and max_concurrent_requests.

The task queue uses token buckets to control the rate of task execution. Each named queue has a token bucket that holds a certain number of tokens, defined by the bucket_size directive. Each time your application executes a task, it uses a token. Your app continues processing tasks in the queue until the queue's bucket runs out of tokens. App Engine refills the bucket with new tokens continuously based on the rate that you specified for the queue.

If your queue contains tasks to process, and the queue's bucket contains tokens, App Engine processes as many tasks as there are tokens remaining in the bucket. This can lead to bursts of processing, consuming system resources and competing with user-serving requests.

If you want to prevent too many tasks from running at once or to prevent datastore contention, you use max_concurrent_requests.

The following samples shows how to set max_concurrent_requests to limit tasks and also shows how to adjust the bucket size and rate based on your application's needs and available resources:

queue:
- name: optimize-queue
  rate: 20/s
  bucket_size: 40
  max_concurrent_requests: 10

Setting storage limits for all queues

You can use queue.yaml to define the total amount of storage that task data can consume over all queues. To define the total storage limit, include an element named total_storage_limit at the top level:

# Set the total storage limit for all queues to 120MB
total_storage_limit: 120M
queue:
- name: foo
  rate: 35/s

The value is a number followed by a unit: B for bytes, K for kilobytes, M for megabytes, G for gigabytes, T for terabytes. For example, 100K specifies a limit of 100 kilobytes. If adding a task would cause the queue to exceed its storage limit, the call to add the task will fail. The default limit is 500M (500 megabytes) for free apps. For billed apps there is no limit until you explicitly set one. You can use this limit to protect your app from a fork bomb programming error in which each task adds multiple other tasks during its execution. If your app is receiving errors for insufficient quota when adding tasks, increasing the total storage limit can help. If you are using this feature, we strongly recommend setting a limit that corresponds to the storage required for several days' worth of tasks. In this way, your app is robust to its queues being temporarily backed up and can continue to accept new tasks while working through the backlog while still being protected from a fork bomb programming error.

Monitoring queues in the Cloud Platform Console

The Task Queues page in the Cloud Platform Console. displays information about all the task queues in your application.

  1. Visit the Task Queues page in the Cloud Platform Console and select the Push Queues tab in the menu bar at the top of the page.

    Go to the Push Queues tab

  2. The Push Queues tab lists all of the queues in the application. Clicking on a queue name brings up the Task Queue Details page where you can see all of the tasks in the selected queue.

What's next

Send feedback about...

App Engine standard environment for Python