English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# Java Task Queue Configuration Using YAML

Applications define task queues in a configuration file called `queue.yaml`. You can use `queue.yaml` to configure both . This configuration file is optional for push queues, which have a default queue. Pull queues must be specifically configured in `queue.yaml`.

- About Queues
- Setting the Storage Limit for All Queues
- Defining Push Queues and Processing Rates
- Defining Pull Queues
- Configuring Retry Attempts for Failed Tasks
- Queue Definitions
- Updating Task Queue Configuration

## About Queues

An app can define task queues using a file named `queue.yaml`. The file specifies a directive named `queue`. Within this directive, you can name any number of individual queues and define their processing rates..

The app's queue configuration applies to all versions of the app. If a given version of an app enqueues a task, the queue uses the task handler for that version of the app. To control this behavior, see the target parameter.

An app can only add tasks to queues defined in `queue.yaml` and the default queue. If you upload a new `queue.yaml` file that removes a queue, but that queue still has tasks, the queue is "paused" (its rate is set to 0) but not deleted. You can re-enable the deleted queue by uploading a new `queue.yaml` file with the queue defined.

## Setting the Storage Limit 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 a directive named `total_storage_limit` at the top level just above each `queue` line, like this:

    # 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 may 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.

## Defining Push Queues and Processing Rates

You can define any number of individual queues by providing a queue `name`. You can control the rate at which tasks are processed in each queue by defining other directives, such as `rate`, `bucket_size`, and `max_concurrent_requests`. You can read more about these directives in the Queue Definitions section.

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.

### Configuring the Default Queue

All apps have a push queue named `default`. This queue has a preset rate of 5 tasks per second, but you can change this rate by defining a default queue in `queue.yaml`. If you do not configure a default queue in `queue.yaml`, the `default` queue doesn't display in the Administration Console until the first time it is used. You can customize the settings for this queue by defining a queue named `default` in `queue.yaml`:

    queue:
    # Change the refresh rate of the default queue from 5/s to 1/s
    - name: default
      rate: 1/s

### Configuring the Processing Rate

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. You can adjust the bucket size and rate based on your application's needs and available resources as follows:

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

## Defining Pull Queues

You can specify any named queue as a by adding the `mode: pull` directive to `queue.yaml`. If you are using the Task Queue REST API, you also need to create an access control list (ACL) using the acl directive. This directive allows you to restrict access to user email addresses corresponding to an account hosted by Google. The following code snippet creates a pull queue named pull-queue with two users in the ACL:

    queue:
    - name: pull-queue
      mode: pull
      acl:
      - user_email: bar@foo.com
      - user_email: user@gmail.com

## Configuring Retry Attempts for Failed Tasks

Tasks executing in the task queue can fail for many reasons. If a task fails to execute (by returning any HTTP status code outside of the range 200–299), App Engine retries the task until it succeeds. By default, the system gradually reduces the retry rate to avoid flooding your application with too many requests, but schedules retry attempts to recur at a maximum of once per hour until the task succeeds.

Push queues and pull queues differ in how they retry tasks, as described in the following sections.

### Retrying Tasks in Push Queues

In push queues, you can specify your own scheme for task retries by adding the retry_parameters directive in `queue.yaml`. This addition allows you to specify the maximum number of times to retry failed tasks in a specific queue. You can also set a time limit for retry attempts and control the interval between attempts.

The following example demonstrates various retry scenarios:

- In `fooqueue`, tasks are retried at least seven times and for up to two days from the first execution attempt. After both limits are passed, it fails permanently.
- In `barqueue`, App Engine attempts to retry tasks, increasing the interval linearly between each retry until reaching the maximum backoff and retrying indefinitely at the maximum interval (so the intervals between requests are 10s, 20s, 30s, ..., 190s, 200s, 200s, ...).
- In `bazqueue`, the interval increases to twice the minimum backoff and retries indefinitely at the maximum interval (so the intervals between requests are 10s, 20s, 40s, 80s, 120s, 160s, 200s, 200s, ...).

    queue:
    - name: fooqueue
      rate: 1/s
      retry_parameters:
        task_retry_limit: 7
        task_age_limit: 2d
    - name: barqueue
      rate: 1/s
      retry_parameters:
        min_backoff_seconds: 10
        max_backoff_seconds: 200
        max_doublings: 0
    - name: bazqueue
      rate: 1/s
      retry_parameters:
        min_backoff_seconds: 10
        max_backoff_seconds: 200
        max_doublings: 2

### Retrying Tasks in Pull Queues

In pull queues, you can specify the number of times to retry a task using the retry_parameters directive with the task_retry_limit field. The system counts each time you lease a task using . When the count exceeds the `task_retry_limit`, the system deletes the task automatically. If you don't specify a `task_retry_limit`, the system never deletes a task automatically.

The following code sample shows how to specify a pull queue limited to seven retry attempts:

    queue:
    - name: pull-queue
      mode: pull
      retry_parameters:
        task_retry_limit: 7

## Queue Definitions

The `queue.yaml` file is a YAML file whose root directive is `queue-entries`. This directive contains zero or more `queue` directives, one for each named queue.

A `queue` directive contains configuration for a queue. It can contain the following directives:

`acl`Experimental! (pull queues only)

  Creates an access control list (ACL) for Pull Queues using the Task Queue REST API. The ACL is composed of the specified email addresses. Accepts email addresses only from a Google Account. Enter each email address on its own line as follows `- user_email: user@gmail.com`. For more information, please see Defining Pull Queues.

`bucket_size` (push queues only)

  Task queues use a "token bucket" algorithm for dequeueing tasks. The bucket size limits how fast the queue is processed when many tasks are in the queue and the rate is high. This allows you to have a high rate so processing starts shortly after a task is enqueued, but still limit resource usage when many tasks are enqueued in a short period of time.

  If no `bucket_size` is specified for a queue, the default value is 5.

  For more information on the algorithm, see the Wikipedia article on token buckets.

`max_concurrent_requests` (push queues only)

  Sets the maximum number of tasks that can be executed at any given time in the specified queue. The value is an integer. By default, this directive is unset and there is no limit on the maximum number of concurrent tasks.

  Restricting the maximum number of concurrent tasks gives you more control over your queue's rate of execution. In particular, you can explicitly control the number of clones that a queue consumes. Limiting the number of concurrent requests in a given queue allows you to make resources available for other queues or online processing.

`mode`

  Identifies the queue mode. This setting defaults to `push`, which identifies a queue as a . If you wish to use , set the mode to `pull`.

`name`

  The name of the queue.

  A queue name can contain letters, numbers, and hyphens.

`rate` (push queues only)

  How often tasks are processed on this queue. The value is a number followed by a slash and a unit of time, where the unit is `s` for seconds, `m` for minutes, `h` for hours, or `d` for days. For example, the value `5/m` says tasks will be processed at a rate of 5 times per minute.

  If the number is `0` (such as `0/s`), the queue is considered "paused," and no tasks are processed.

`retry_parameters`
  Configures retry attempts for failed tasks. This addition allows you to specify the maximum number of times to retry failed tasks in a specific queue. You can also set a time limit for retry attempts and control the interval between attempts.
  task_retry_limit
    The maximum number of retry attempts for a failed task. If specified with `task_age_limit`, App Engine retries the task until both limits are reached.
  min_backoff_seconds (push queues only)
    The minimum number of seconds to wait before retrying a task after it fails.
  max_backoff_seconds (push queues only)
    The maximum number of seconds to wait before retrying a task after it fails.
  max_doublings (push queues only)
    The maximum number of times that the interval between failed task retries will be doubled before the increase becomes constant. The constant is:
    2**(max_doublings - 1) * min_backoff_seconds.
  task_age_limit (push queues only)
    The time limit for retrying a failed task, in seconds, measured from the time the task was created. The value is a number followed by a unit of time, where the unit is `s` for seconds, `m` for minutes, `h` for hours, or `d` for days. For example, the value `5d` specifies a limit of five days after the task's first execution attempt. If specified with `task_retry_limit`, App Engine retries the task until both limits are reached.
`target` (push queues only)

  The version of your application on which the tasks in this queue will be invoked.

  If unspecified, then tasks are invoked on the same version of the application where they were enqueued. So, if you enqueued a task from the default application version without specifying a target on the queue, the task is invoked in the default application version.

## Updating Task Queue Configuration

The task queue configuration for the app is updated when you upload the application using `appcfg.py update`. You can update just the configuration for an app's task queues without uploading the full application. To upload the `queue.yaml` file, use the `appcfg.py update_queues` command:

    appcfg.py update_queues myapp/

See Uploading and Managing a Python App for more information.