[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThis document guides you through creating and customizing push queues, including setting up a default queue or defining multiple custom queues with specific configurations.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage the processing rate of tasks in each queue by adjusting parameters such as \u003ccode\u003erate\u003c/code\u003e, \u003ccode\u003ebucket_size\u003c/code\u003e, and \u003ccode\u003emax_concurrent_requests\u003c/code\u003e, utilizing a token bucket system.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003etotal_storage_limit\u003c/code\u003e setting in the queue configuration file allows you to define the maximum storage consumed by task data across all queues, preventing excessive storage use and potential fork bomb errors.\u003c/p\u003e\n"],["\u003cp\u003eBy setting \u003ccode\u003emax_concurrent_requests\u003c/code\u003e, you can control the maximum number of tasks that execute simultaneously, mitigating the risk of increased latency causing a surge in concurrent task processing and potential system overload.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud console's Cloud Tasks page allows you to view all queues, and by clicking on a queue name, you can view all tasks within that queue.\u003c/p\u003e\n"]]],[],null,["# Creating Push Queues\n\nThis page describes how to create and customize a push queue, and how to\nexamine the contents of a queue.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| java-gen2\n|\n| /services/access). If you are updating to the App Engine Java 11/17 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/java-differences) to learn about your migration options for legacy bundled services.\n\nUsing a queue configuration file to create queues\n-------------------------------------------------\n\nTo process a task, you must add it to a push queue. App Engine provides a\ndefault push queue, named `default`, which is configured and\nready to use with default settings. If you want, you can just add all your tasks\nto the default queue, without having to create and configure other queues.\n\nTo add queues or change the default configuration, edit the queue configuration file\nfor your application, which you upload to App Engine. You can create up to 100\nqueues. Queues cannot be created dynamically.\n\nThis queue configuration file defines two queues: \n\n queue:\n - name: queue-blue\n target: v2.task-module\n rate: 5/s\n\n - name: queue-red\n rate: 1/s\n\nTo upload the file: \n\n gcloud app deploy queue.yaml\n\n| **Note:** Your app should not assume App Engine processes tasks in a queue in the order in which they were enqueued.\n\nAll tasks added to `queue-blue` are sent to the target module `v2.task-module`.\nThe refresh rate of `queue-red` is changed from 5/s to 1/s. Tasks will be\ndequeued and sent to their targets at the rate of 1 task per second.\n\nIf you delete a queue, you must wait approximately 7 days before creating\na new queue with the same name.\n\nThere are many other parameters that can be added to the configuration file to\ncustomize the behavior of a push queue. For more information, see the\n[queue configuration file reference](/appengine/docs/legacy/standard/java/config/queueref).\n| **Note:** If you are using a service account to manage authentication for deploying your queue configuration file, it needs to have the `serviceusage.services.list` permission. This permission can be added either using the [`serviceusage.serviceUsageViewer`](/iam/docs/understanding-roles#service-usage-roles) role or by creating a [custom role](/iam/docs/understanding-custom-roles) with that permission.\n\nDefining the push queue processing rate\n---------------------------------------\n\n\nYou can control the rate at which tasks are processed in each of your queues by\ndefining other directives, such as\n[`rate`](/appengine/docs/legacy/standard/java/config/queueref#rate),\n[`bucket_size`](/appengine/docs/legacy/standard/java/config/queueref#bucket_size),\nand\n[`max_concurrent_requests`](/appengine/docs/legacy/standard/java/config/queueref#max_concurrent_requests).\n\nThe task queue uses [token buckets](https://wikipedia.org/wiki/Token_bucket) to\ncontrol the rate of task execution. Each named queue has a token bucket that\nholds tokens, up to the maximum specified by the `bucket_size`, or a maximum of\n5 tokens if you don't specify the bucket size.\n\nEach time your application executes a task, a token is removed from the bucket.\nYour app continues processing tasks in the queue until the queue's bucket runs\nout of tokens. App Engine refills the bucket with new tokens continuously based\non the `rate` that you specified for the queue.\n\nIf your queue contains tasks to process, and the queue's bucket contains tokens,\nApp Engine simultaneously processes as many tasks as there are tokens.\nThis can lead to bursts of processing, consuming system resources and competing\nwith user-serving requests.\n\nIf you want to prevent too many tasks from running at once or to prevent\ndatastore contention, use `max_concurrent_requests`.\n\nThe following sample shows how to set `max_concurrent_requests` to limit\ntasks and also shows how to adjust the bucket size and rate based on your\napplication's needs and available resources: \n\n queue:\n - name: queue-blue\n rate: 20/s\n bucket_size: 40\n max_concurrent_requests: 10\n\nSetting storage limits for all queues\n-------------------------------------\n\nYou can use your queue configuration file to define the total amount of storage that task data\ncan consume over all queues. To define the total storage limit, include an\nelement named [`total_storage_limit`](/appengine/docs/legacy/standard/java/config/queueref#total_storage_limit)\nat the top level: \n\n # Set the total storage limit for all queues to 120MB\n total_storage_limit: 120M\n queue:\n - name: queue-blue\n rate: 35/s\n\nThe value is a number followed by a unit: `B` for bytes, `K` for kilobytes, `M`\nfor megabytes, `G` for gigabytes, `T` for terabytes. For example, `100K`\nspecifies a limit of 100 kilobytes. If adding a task would cause the queue to\nexceed its storage limit, the call to add the task will fail. The default limit\nis `500M` (500 megabytes) for free apps. For billed apps there is no limit until\nyou explicitly set one. You can use this limit to protect your app from a [fork\nbomb](https://wikipedia.org/wiki/Fork_bomb)\nprogramming error in which each task adds multiple other tasks during its\nexecution.\n\nIf your app is receiving errors for insufficient quota when adding\ntasks, increasing the total storage limit can help. If you are using this\nfeature, we strongly recommend setting a limit that corresponds to the storage\nrequired for several days' worth of tasks. This allows the queues to be\ntemporarily backed up and continue to accept new tasks\nwhile working through the backlog while still being protected from a fork bomb\nprogramming error.\n\nConfiguring the maximum number of concurrent requests\n-----------------------------------------------------\n\nYou can control the processing rate by setting\n`max_concurrent_requests`, which limits the number of tasks that can execute\nsimultaneously.\n\nIf your application queue has a rate of 20/s and a bucket size of 40, tasks in\nthat queue execute at a rate of 20/s and can burst up to 40/s briefly. These\nsettings work fine if task latency is relatively low; however, if latency\nincreases significantly, you'll end up processing significantly more concurrent\ntasks. This extra processing load can consume extra instances and slow down your\napplication.\n\nFor example, let's assume that your normal task latency is 0.3 seconds. At this\nlatency, you'll process at most around 40 tasks simultaneously. But if your task\nlatency increases to 5 seconds, you could easily have over 100 tasks processing\nat once. This increase forces your application to consume more instances to\nprocess the extra tasks, potentially slowing down the entire application and\ninterfering with user requests. You can avoid this possibility by setting\n`max_concurrent_requests` to a lower value.\n\nFor example, if you set `max_concurrent_requests` to 10, our\nexample queue maintains about 20 tasks/second when latency is 0.3 seconds.\nWhen the latency increases over 0.5 seconds, this setting throttles the\nprocessing rate to ensure that no more than 10 tasks run simultaneously. \n\n queue:\n # Set the max number of concurrent requests to 50\n - name: optimize-queue\n rate: 20/s\n bucket_size: 40\n max_concurrent_requests: 10\n\nMonitoring queues in the Google Cloud console\n---------------------------------------------\n\n1. In the Google Cloud console, go to the Cloud Tasks page.\n\n [Go to **Cloud Tasks**](https://console.cloud.google.com/cloudtasks)\n\n Note that if you go to the App Engine **Task queue** page, there\n will be instructions that guide you to the Cloud Tasks page.\n This update in the Google Cloud console does not change how Task queues\n function.\n2. Enable the Cloud Tasks API.\n\n3. Once you're in the Cloud Tasks page, you will see a list of all\n of the queues in the application. Clicking on a the name of a queue brings up\n the **Queue Details** page, which shows all of the tasks in the selected queue.\n\nWhat's next\n-----------\n\nLearn about [creating tasks](/appengine/docs/legacy/standard/java/taskqueue/push/creating-tasks)."]]