[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eSetting a minimum number of instances for Cloud Run functions helps avoid cold starts and reduces latency for latency-sensitive applications.\u003c/p\u003e\n"],["\u003cp\u003eCold starts occur when a function initializes its execution environment from scratch, which can take a noticeable amount of time.\u003c/p\u003e\n"],["\u003cp\u003eWhile Cloud Run functions keep instances idle for a period after handling requests, explicitly setting minimum instances can further reduce cold starts.\u003c/p\u003e\n"],["\u003cp\u003eYou can configure minimum instance limits during function deployment or by modifying an existing function via the Google Cloud console or the \u003ccode\u003egcloud\u003c/code\u003e command-line tool.\u003c/p\u003e\n"],["\u003cp\u003eSetting a minimum number of instances will incur costs, as you are billed for the idle time of those instances, and the Recommender service can provide recommendations for setting minimum instances for functions.\u003c/p\u003e\n"]]],[],null,["# Configure minimum instances (1st gen)\n=====================================\n\nYou can avoid cold starts for your application and reduce application latency by\nsetting a minimum number of instances.\n\nCloud Run functions scales by creating new instances of your function.\nEach of these instances can handle only one request at a time, so large spikes\nin request volume often cause longer wait times as new instances are created to\nhandle the demand.\n\nBecause functions are stateless, your function sometimes initializes the\nexecution environment from scratch, which is called a *cold start*. Cold starts\ncan take significant amounts of time to complete, so we recommend setting a\nminimum number of Cloud Run functions instances if your application is\nlatency-sensitive.\n| **Note:** Setting a minimum number of instances incurs cost. For details, see the [Pricing](/functions/pricing) page.\n\n### Idle instances and cold starts\n\nTo minimize the impact of\n[cold starts](/functions/1stgendocs/concepts/execution-environment#cold-starts),\nCloud Run functions attempts to keep function instances idle for an unspecified\namount of time after handling a request. During this idle time, resources such\nas open database connections might be persisted in case another request needs\nto be handled. Instances kept idle in this way count toward the maximum\ninstances limit for your function, but you are not billed for this idle time.\n\nThis built-in behavior might not be sufficient for your application,\nparticularly if it is latency-sensitive. Explicitly setting a minimum number of\ninstances can further help you avoid cold starts and reduce application latency.\n\nNote that when instances are kept idle because a minimum number of instances has\nbeen set, these instances are not considered active unless they have served\ntraffic recently. For example, this means that if a function has not recently\nserved traffic, the \"Active Instances\" metric may show no instances are active,\neven if a value for minimum instances has been set.\n\nNote also that when you set a minimum number of instances, you *are* billed for\nthe idle time of those instances---see [Pricing](/functions/pricing).\n\nSetting and clearing minimum instance limits\n--------------------------------------------\n\nYou can set a minimum number of instances for a function during deployment. Each\nfunction has its own minimum instances setting.\n\n### Setting minimum instance limits\n\nYou can set a minimum instance limit using either the Google Cloud CLI\nor the Google Cloud console. \n\n### Console\n\nTo set a minimum instance limit for a new function:\n\n1. To create a new function, go to the Cloud Run functions page in the\n Google Cloud console: \n\n [Go to the Cloud Run functions page](https://console.cloud.google.com/functions)\n\n2. Click **Create function**.\n\n3. Fill in the required fields for your function.\n\n4. Expand the **Runtime, build...** section at the end of the page and click\n the **Runtime** tab.\n\n5. In the **Minimum number of instances** field in the **Autoscaling**\n section, enter a number greater than or equal to 1.\n\n6. Click **Next**.\n\n7. Click **Deploy**.\n\nTo set a minimum instance limit for an existing function:\n\n1. Go to the Cloud Run functions page in the Google Cloud console: \n\n [Go to the Cloud Run functions page](https://console.cloud.google.com/functions)\n\n2. Click the name of an existing function to be taken to its\n **Function details** page.\n\n3. Click **Edit**.\n\n4. Expand the **Runtime, build...** section at the end of the page and click\n the **Runtime** tab.\n\n5. In the **Minimum number of instances** field in the **Autoscaling**\n section, enter a number greater than or equal to 1.\n\n6. Click **Next**.\n\n7. Click **Deploy**.\n\n### gcloud\n\nTo set a minimum instance limit, run the following command: \n\n gcloud functions deploy \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e \\\n --no-gen2 \\\n --min-instances \u003cvar translate=\"no\"\u003eMIN_INSTANCE_LIMIT\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e: The name of your function.\n\n- \u003cvar translate=\"no\"\u003eMIN_INSTANCE_LIMIT\u003c/var\u003e: The number to set as the minimum instance\n limit, cannot exceed 1000.\n\nThe function's minimum instance limit is set.\n\n### Clearing minimum instance limits\n\nYou can clear or remove a minimum instance limit using either the\nGoogle Cloud CLI or the Google Cloud console. \n\n### Console\n\nTo clear a function's minimum instance limit:\n\n1. Go to the Cloud Run functions page in the\n Google Cloud console: \n [Go to the Cloud Run functions page](https://console.cloud.google.com/functions)\n\n2. Click the name of an existing function to be taken to its\n **Function details** page.\n\n3. Click **Edit**.\n\n4. Expand the **Runtime, build...** section at the end of the page and click\n the **Runtime** tab.\n\n5. In the **Minimum number of instances** field in the **Autoscaling**\n section, enter 0.\n\n6. Click **Next**.\n\n7. Click **Deploy**.\n\n### gcloud\n\nUse the `--clear-min-instances` flag at deploy time: \n\n gcloud functions deploy \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e --clear-min-instances\n\nThe function's minimum instance limit is cleared.\n\nGetting recommendations to set minimum instances\n------------------------------------------------\n\nThe [Recommender service](/functions/1stgendocs/configuring/recommender) automatically\nsupplies recommendations for deployed functions that could benefit from\nhaving minimum instances set."]]