Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Jika layanan berjalan terlalu lama, sistem akan mengambil langkah-langkah untuk menghentikan atau membatasi
layanan tersebut.
Untuk layanan Cloud Run, setelan waktu tunggu permintaan menentukan
waktu saat respons harus ditampilkan oleh layanan yang di-deploy ke
Cloud Run. Jika respons tidak ditampilkan dalam waktu yang ditentukan, permintaan akan berakhir dan error 504 akan ditampilkan. Perhatikan bahwa instance container yang
menyajikan permintaan tidak dihentikan. Container atau kode mungkin terus memproses permintaan yang dihentikan dan mungkin memproses permintaan lain. Untuk
menghindari hal ini, cegah waktu tunggu di layanan Anda dengan teknik berikut:
Tetapkan waktu tunggu yang lebih tinggi dari waktu eksekusi yang diharapkan.
Lacak jumlah waktu yang tersisa selama eksekusi. Kemudian, lakukan pembersihan dan
kembali lebih awal.
Periode waktu tunggu
Waktu tunggu disetel secara default ke 5 menit
(300 detik) dan dapat diperpanjang hingga
60 menit
(3600 detik).
Anda dapat mengubah setelan ini saat men-deploy image container atau dengan memperbarui
konfigurasi layanan.
Selain mengubah waktu tunggu permintaan Cloud Run, Anda juga
harus memeriksa framework bahasa Anda untuk mengetahui apakah framework memiliki setelan waktu tunggu
permintaannya sendiri yang juga harus diperbarui. Beberapa klien layanan Cloud Run
juga dapat menerapkan waktu tunggu yang lebih ketat.
Peran yang diperlukan
Untuk mendapatkan izin yang
diperlukan untuk mengonfigurasi dan men-deploy layanan Cloud Run,
minta administrator Anda untuk memberi Anda
peran IAM berikut:
Jika Anda men-deploy layanan
atau fungsi dari kode sumber, Anda
juga harus memiliki peran tambahan yang diberikan kepada Anda di project dan
akun layanan Cloud Build.
Setiap perubahan konfigurasi akan
menghasilkan revisi baru. Revisi selanjutnya juga akan otomatis mendapatkan
setelan konfigurasi ini, kecuali jika Anda melakukan pembaruan eksplisit untuk mengubahnya.
Anda dapat menetapkan waktu tunggu permintaan menggunakan konsol Google Cloud , command line gcloud, atau file YAML saat Anda membuat layanan baru atau
men-deploy revisi baru.
Pilih Services dari menu, lalu klik Deploy container untuk
mengonfigurasi layanan baru.
Jika Anda mengonfigurasi layanan yang sudah ada, klik
layanan tersebut, lalu klik Edit dan deploy revisi baru.
Jika Anda mengonfigurasi layanan baru, isi halaman setelan
layanan awal, lalu klik Container, Volume, Jaringan, Keamanan untuk meluaskan
halaman konfigurasi layanan.
Klik tab Container.
Di kolom Waktu tunggu permintaan, masukkan nilai waktu tunggu yang ingin Anda gunakan dalam satuan detik. Gunakan nilai yang berkisar dari 1 hingga 3600 detik, atau dari 1 hingga 60 menit.
TIMEOUT: waktu yang diperlukan untuk menampilkan respons, menggunakan nilai bilangan bulat atau
nilai durasi absolut—misalnya
1m20s yaitu 1 menit, 20 detik. Jika Anda
menggunakan nilai bilangan bulat, satuannya akan diasumsikan sebagai detik. Nilai yang Anda
tentukan harus kurang dari 60 menit.
Anda juga dapat menetapkan waktu tunggu permintaan selama
deployment menggunakan perintah:
gcloudrundeploy--imageIMAGE_URL--timeout=TIMEOUT
Ganti kode berikut:
IMAGE_URL: referensi ke image container, misalnya, us-docker.pkg.dev/cloudrun/container/hello:latest. Jika Anda menggunakan Artifact Registry,
repositoriREPO_NAME harus
sudah dibuat. URL mengikuti format LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
.
TIMEOUT: waktu yang diperlukan untuk menampilkan respons, menggunakan nilai bilangan bulat atau nilai durasi—misalnya, 1m20s yaitu 1 menit, 20 detik. Jika Anda menggunakan nilai bilangan bulat, satuannya akan
diasumsikan sebagai detik. Nilai yang Anda tentukan harus kurang dari
60 menit.
YAML
Jika Anda membuat layanan baru, lewati langkah ini.
Jika Anda mengupdate layanan yang sudah ada, download konfigurasi YAML-nya:
IMAGE_URL: referensi ke image container, misalnya, us-docker.pkg.dev/cloudrun/container/hello:latest. Jika Anda menggunakan Artifact Registry,
repositoriREPO_NAME harus
sudah dibuat. URL mengikuti format LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
.
VALUE: waktu tunggu yang dipilih, dalam detik.
Buat atau perbarui layanan menggunakan perintah berikut:
gcloudrunservicesreplaceservice.yaml
Terraform
Untuk mempelajari cara menerapkan atau menghapus konfigurasi Terraform, lihat Perintah dasar Terraform.
resource"google_cloud_run_v2_service""default"{name="cloudrun-service-request-timeout"location="us-central1"deletion_protection=false # set to "true" in productiontemplate{containers{image="us-docker.pkg.dev/cloudrun/container/hello"} # Timeouttimeout="300s"}}
Ganti 300s dengan waktu tunggu permintaan yang diinginkan untuk layanan Anda.
Lihat setelan waktu tunggu permintaan
Untuk melihat setelan waktu tunggu permintaan saat ini untuk
layanan Cloud Run Anda:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-21 UTC."],[],[],null,["# Set request timeout for services\n\nIf a service runs for too long, the system takes steps to terminate or throttle\nit.\n\nFor Cloud Run services, the request timeout setting specifies the\ntime within which a response must be returned by services deployed to\nCloud Run. If a response isn't returned within the time specified, the\nrequest ends and an error 504 is returned. Note that the container instance that\nserved the request is not terminated. The container or code might keep\nprocessing the terminated request and might be processing other requests. To\navoid this, prevent timeouts in your service with the following techniques:\n\n- Set a timeout higher than your expected execution time.\n- Track the amount of time left during execution. Then perform cleanup and return early.\n\nTimeout period\n--------------\n\nThe timeout is set by default to 5 minutes\n(300 seconds) and can be extended up to\n60 minutes\n(3600 seconds).\n\nWhen triggering your service from [Eventarc events](/run/docs/triggering/trigger-with-events),\n[Pub/Sub push subscriptions](/run/docs/triggering/pubsub-triggers)\nor [Cloud Scheduler](/run/docs/triggering/using-scheduler), the timeout\nof these services apply.\n| **Important:** For a timeout longer than 15 minutes, Google recommends implementing retries and making sure the service is tolerant to clients re-connecting in case the connection is lost (either by ensuring requests are idempotent, or by designing request handlers in such a way that they can resume from the point where they left off). The longer the timeout is, the more likely the connection can be lost due to failures on the client side or the Cloud Run side. When a client re-connects, a new request is initiated and the client isn't guaranteed to connect to the same instance of the service.\n\nYou can change this setting when you deploy a container image or by updating\nthe service configuration.\n\nIn addition to changing the Cloud Run request timeout, you should also\ncheck your language framework to see whether it has its own request timeout\nsetting that you must also update. Some clients of the Cloud Run\nservice might also impose a more restrictive timeout.\n\nRequired roles\n--------------\n\n\nTo get the permissions that\nyou need to configure and deploy Cloud Run services,\n\nask your administrator to grant you the\nfollowing IAM roles:\n\n- [Cloud Run Developer](/iam/docs/roles-permissions/run#run.developer) (`roles/run.developer`) on the Cloud Run service\n- [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity\n\n\nIf you are deploying a [service](/run/docs/deploying-source-code#required_roles)\nor [function](/run/docs/deploy-functions#required-roles) from source code, you\nmust also have additional roles granted to you on your project and\nCloud Build service account.\n\nFor a list of IAM roles and permissions that are associated with\nCloud Run, see\n[Cloud Run IAM roles](/run/docs/reference/iam/roles)\nand [Cloud Run IAM permissions](/run/docs/reference/iam/permissions).\nIf your Cloud Run service interfaces with\nGoogle Cloud APIs, such as Cloud Client Libraries, see the\n[service identity configuration guide](/run/docs/configuring/services/service-identity).\nFor more information about granting roles, see\n[deployment permissions](/run/docs/reference/iam/roles#additional-configuration)\nand [manage access](/iam/docs/granting-changing-revoking-access).\n\nSetting and updating request timeout\n------------------------------------\n\nAny configuration change leads to the\ncreation of a new revision. Subsequent revisions will also automatically get\nthis configuration setting unless you make explicit updates to change it.\n\nYou can set request timeout using the Google Cloud console, the gcloud\ncommand line, or a YAML file when you [create a new service](/run/docs/deploying#service) or\n[deploy a new revision](/run/docs/deploying#revision). \n\n### Console\n\n\n1. In the Google Cloud console, go to Cloud Run:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Select **Services** from the menu, and click **Deploy container** to\n configure a new service.\n If you are configuring an existing service, click the\n service, then click **Edit and deploy new revision**.\n\n3. If you are configuring a new service, fill out the initial service\n settings page, then click **Container(s), Volumes, Networking, Security** to expand the\n service configuration page.\n\n4. Click the **Container** tab.\n\n - In the **Request timeout** field, enter the timeout value that you want to use in seconds. Use values ranging from `1` to `3600` seconds, or from 1 to `60` minutes.\n5. Click **Create** or **Deploy**.\n\n### gcloud\n\nYou can [update the request timeout](/sdk/gcloud/reference/run/services/update)\nfor a given revision at any time by using the following command: \n\n```bash\ngcloud run services update SERVICE --timeout=TIMEOUT\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e: the name of your service.\n- \u003cvar translate=\"no\"\u003eTIMEOUT\u003c/var\u003e: the time within which a response must be\n returned, using an integer value or an\n [absolute duration value](/sdk/gcloud/reference/topic/datetimes)---for\n example `1m20s` which is 1 minute, 20 seconds. If you\n use an integer value, the unit is assumed to be seconds. The value you\n specify must be less than 60 minutes.\n\n | **Note:** When you update your service with the new timeout value, a new revision is created.\n\nYou can also set the request timeout during\n[deployment](/sdk/gcloud/reference/run/deploy) using the command: \n\n```bash\ngcloud run deploy --image IMAGE_URL --timeout=TIMEOUT\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e: a reference to the container image, for example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry, the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e .\n- \u003cvar translate=\"no\"\u003eTIMEOUT\u003c/var\u003e: the time within which a response must be returned, using an integer value or a duration value---for example, `1m20s` which is 1 minute, 20 seconds. If you use an integer value, the unit is assumed to be seconds. The value you specify must be less than 60 minutes.\n\n### YAML\n\n1. If you are creating a new service, skip this step.\n If you are updating an existing service, download its [YAML configuration](/run/docs/reference/yaml/v1):\n\n ```bash\n gcloud run services describe SERVICE --format export \u003e service.yaml\n ```\n2. Update the `timeoutSeconds` attribute:\n\n ```yaml\n apiVersion: serving.knative.dev/v1\n kind: Service\n metadata:\n name: SERVICE\n spec:\n template:\n spec:\n containers:\n - image: IMAGE\n timeoutSeconds: VALUE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e: the name of your Cloud Run service.\n - \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e: a reference to the container image, for example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry, the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e .\n - \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e: the chosen timeout, in seconds.\n3. Create or update the service using the following command:\n\n ```bash\n gcloud run services replace service.yaml\n ```\n\n### Terraform\n\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\nAdd the following to a [`google_cloud_run_v2_service`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service) resource in your Terraform configuration: \n\n\u003cbr /\u003e\n\n resource \"google_cloud_run_v2_service\" \"default\" {\n name = \"cloudrun-service-request-timeout\"\n location = \"us-central1\"\n\n deletion_protection = false # set to \"true\" in production\n\n template {\n containers {\n image = \"us-docker.pkg.dev/cloudrun/container/hello\"\n }\n # Timeout\n timeout = \"300s\"\n }\n }\n\nReplace `300s` with your service's desired request timeout.\n\nView request timeout settings\n-----------------------------\n\nTo view the current request timeout settings for your\nCloud Run service: \n\n### Console\n\n1. In the Google Cloud console, go to Cloud Run:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Click the service you are interested in to open the **Service details**\n page.\n\n3. Click the **Revisions** tab.\n\n4. In the details panel at the right, the request timeout setting\n is listed under the **Container** tab.\n\n### gcloud\n\n1. Use the following command:\n\n ```bash\n gcloud run services describe SERVICE\n ```\n2. Locate the request timeout setting in the returned\n configuration."]]