例如:如果项目 A 中的服务账号发送一个发布请求,发布到项目 B 中的主题,系统会将此请求计入项目 A 的配额。在某些情况下,您可能希望将配额使用量计入其他项目。您可以使用 X-Goog-User-Project 系统参数来更改配额归因的项目。如需详细了解 X-Goog-User-Project,请参阅系统参数。
[[["易于理解","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-08-17。"],[],[],null,["# Pub/Sub quotas and limits\n\nGoogle Cloud uses quotas to restrict how much of a particular shared Google Cloud resource that you can use. Each quota represents a specific\ncountable resource, such as API calls to a particular service, the number of\nbytes sent to a particular service, or the number of streaming connections used\nconcurrently by your project.\n\nMany services also have limits that are unrelated to the quota system. These are\nfixed constraints, such as maximum message sizes or the number of Pub/Sub resources you can create in a project, which cannot be\nincreased or decreased.\n| **Key Point:** This document provides information about quotas and resource limits for Pub/Sub. You can request increases to quotas, but limits cannot be adjusted. For more information, see [Working with quotas](/docs/quota).\n\nView and manage quotas\n----------------------\n\nFor a given project, you can use the\n[IAM \\& admin quotas dashboard](https://console.cloud.google.com/iam-admin/quotas?project=_&service=pubsub.googleapis.com)\nto view current quota limits and usage. You can also use this dashboard to do the following:\n\n- Reduce your quota limits\n- Initiate a process to apply for higher quota limits\n\nFor more information about monitoring and alerting on your quota usage, see\n[Monitoring](/pubsub/docs/monitoring#quota).\n\nQuota usage attribution\n-----------------------\n\nFor push subscriber throughput, quota usage is charged against the project that\ncontains the push subscription. This is the project that appears in the name of\nthe subscription.\n\nFor all other quotas, usage is charged against the project associated with the\ncredentials specified in the request. The quota usage is not charged against\nthe project that contains the requested resource.\n\nFor example: If a service account in project A sends a publish request to\npublish to a topic in project B, the quota is charged to project A.\nIn some cases, you might want quota usage to be charged against another\nproject. You can use the `X-Goog-User-Project` system parameter to\nchange the project for quota attribution. For more information about `X-Goog-User-Project`,\nsee [System parameters](/apis/docs/system-parameters#definitions).\n\nYou can use gcloud CLI to set the project for quota attribution\nfor a specific request. The gcloud CLI sends\nthe `X-Goog-User-Project` request header.\n\nYou must have the `roles/serviceusage.serviceUsageConsumer` role\nor a custom role with the `serviceusage.services.use` permission on the project\nthat you are going to use for quota attribution.\n\nThe following example shows how to get a list of subscriptions in the project\n\u003cvar translate=\"no\"\u003eRESOURCE_PROJECT\u003c/var\u003e while charging the *Administrator\noperations* quota against the project \u003cvar translate=\"no\"\u003eQUOTA_PROJECT\u003c/var\u003e. Run\nthe following command in your Google Cloud CLI terminal: \n\n gcloud pubsub subscriptions list --project=\u003cvar translate=\"no\"\u003e\n RESOURCE_PROJECT\u003c/var\u003e --billing-project=\u003cvar translate=\"no\"\u003e\n QUOTA_PROJECT\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eQUOTA_PROJECT\u003c/var\u003e with the ID of the Google Cloud project against which you want to charge quota.\n\nNote that in Pub/Sub, the billed project is always the one that\ncontains the resource. You can change the project only for quota attribution.\n\nPub/Sub quotas\n--------------\n\nThe quotas listed in the following table can be viewed and edited on a\nper-project basis in the\n[APIs and services quotas dashboard](https://console.cloud.google.com/apis/api/pubsub.googleapis.com/quotas?project=_).\n\nRegional quotas are divided into 3 types:\n\n- Large regions: `europe-west1`, `europe-west4`, `us-central1`, `us-east1`, `us-east4`, `us-west1`, `us-west2`\n- Medium regions: `asia-east1`, `asia-northeast1`, `asia-southeast1`, `europe-west2`, `europe-west3`\n- Small regions: all other regions\n\n\u003cbr /\u003e\n\nExactly-once delivery quotas are region specific. Check the details for each region in the following table.\n| **Note:** For all throughput quotas, usage is measured in [1 kB units](#throughput_quota_units).\n\nThroughput quota units\n----------------------\n\nThroughput quota usage is measured in 1kB units. 1 kB is 1000 bytes. For\nexample, in a `PublishRequest` with 105 messages of 50 bytes each, the user data\nsize is `105 * 50 bytes = 5250 bytes`, so the quota usage is\n`max(1kB, ceil(5250 bytes/1000)) = 6kB`.\n\nResource limits\n---------------\n\n| **Note:**It is not possible to request increases to the following limits.\n\nUse a service account for higher quotas\n---------------------------------------\n\nIf you use the Google Cloud CLI tool with a normal user account (that is, a\nnon-service account), Pub/Sub operations are limited to a rate\nsuitable for manual operations. Rates in excess of this limit results in the\n[RESOURCE_EXHAUSTED](/pubsub/docs/error-codes#resource-exhausted) error. The\nsolution is to make sure that you are using service account credentials. If you\nwant to use credentials from the gcloud CLI for automation,\n[activate a service account](/sdk/gcloud/reference/auth/activate-service-account)\nfor your Pub/Sub operations.\n\nUse locational endpoints to route requests\n------------------------------------------\n\nIf you have additional quota in particular regions, you can route requests to\nthese regions using\n[locational Pub/Sub endpoints](/pubsub/docs/reference/service_apis_overview#service_endpoints).\nWhen you publish messages to a global endpoint, the Pub/Sub\nservice might route traffic to a region that does not have sufficient quota.\n\nQuota mismatches\n----------------\n\nQuota mismatches can happen when published or received messages are smaller than\n1000 bytes. For example:\n\n- If you publish 10 500-byte messages in separate requests, your publisher\n quota usage will be 10,000 bytes. This is because messages that are smaller than\n 1000 bytes are automatically rounded up to the next 1000-byte increment.\n\n- If you receive those 10 messages in a single pull response, your\n subscriber quota usage might be only 5 kB, since the actual\n size of each message is combined to determine the overall quota.\n\n- The inverse is also true. The subscriber quota usage might be greater than\n the publisher quota usage if you publish multiple messages in a single publish\n request or receive the messages in separate Pull requests."]]