How to limit instance count of firebase functions
Asked Answered
L

4

7

I use following firebase cli command to deploy my firebase functions

firebase deploy --only functions

How can I limit the number of instances for functions, when deployed like this? It looks like gcloud command has --max-instances option to limit instances, but couldn't find anything like this for firebase cli.

Lungan answered 18/11, 2020 at 5:11 Comment(1)
You may want to reconsider the accepted answer. I have just tried @nathan's solution and it works perfectly. The parameter is well documented in the link they provided. ^^Swap
S
11

You can set the maxInstances when you write the function, using runWith and passing in RuntimeOptions

Something like this:

 functions
.runWith({maxInstances: 3})
.https.onCall(() => {});
Sinuate answered 15/12, 2020 at 21:14 Comment(1)
Updated Link:firebase.google.com/docs/reference/functions/…Receipt
E
3

If you are writing a function with Python for 2nd gen Cloud Functions then you can use:

@https_fn.on_call(max_instances=10)
def foo(req: https_fn.CallableRequest) -> any:
    ...
Enfranchise answered 25/5, 2023 at 3:32 Comment(0)
A
2

There is currently no option on the Firebase CLI for this. Feel free to file a feature request with Firebase support. If such an option is added, it likely won't end up in the CLI, but rather the function builder interface, similar to how region and memory are set.

For now, you can use the Google Cloud console by finding your deployed function there and editing to to use the value you want.

Aggy answered 18/11, 2020 at 5:18 Comment(4)
Couldn't find an option in google cloud console to change the instance count. I can only see options to copy function, test function, view logs and delete. Any idea where to edit the max instance count?Lungan
Click the edit button at the top to edit a deployed function after selecting it.Aggy
Found it! ThanksLungan
The maxInstances option is not listed on the linked page for the FunctionBuilder interface, but it is listed on the page for the RuntimeOptions object, linked from the accepted answer. Probably the FunctionBuilder.runWith documentation should be updated! Also should probably be mentioned here: firebase.google.com/docs/functions/manage-functionsZermatt
R
0

For the latest Firebase V2, you can set maxInstances globally like this:

const { setGlobalOptions } = require("firebase-functions/v2"); // import it here

setGlobalOptions({ maxInstances: 10 }); // set it here

exports.helloWorld = onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

Reremouse answered 3/2, 2024 at 11:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.