Setting the number of concurrent function instance calls
Number of calls processed concurrently by a single function instance (concurrency) cannot exceed the relevant quota. This setting is only available in specific runtime environments. For more information, see Concurrent function instance calls.
- In the management console
, navigate to the folder containing the function. - Go to Cloud Functions.
- Select the function.
- Navigate to the Editor tab.
- Under Additional settings, in the Concurrent function instance calls section, check Enable and enter the number of concurrent function instance calls.
- Click Save changes.
To set the number of calls to be processed concurrently by a single function instance, run this command:
yc serverless function version create \
--function-name=<function_name> \
--runtime <runtime_environment> \
--entrypoint <entry_point> \
--concurrency 2 \
--execution-timeout 3s \
--source-path <path_to_ZIP_archive>
Where:
--function-name: Name of the function whose version you want to create.--runtime: Function runtime.--entrypoint: Entry point in<file_name_without_extension>.<handler_name>format.--concurrency: Maximum number of calls processed concurrently by a single function instance.--execution-timeout: Maximum function execution time before timeout.--source-path: ZIP archive with the function code and required dependencies.
Result:
done (1s)
id: d4evvn8obisa********
function_id: d4elpv8pft63********
created_at: "2020-08-01T19:09:19.531Z"
runtime: nodejs18
entrypoint: index.handler
resources:
memory: "134217728"
execution_timeout: 3s
image_size: "4096"
status: ACTIVE
tags:
- $latest
log_options:
folder_id: b1g681qpemb4********
concurrency: "2"
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To set the number of calls to be processed concurrently by a single function instance, set its concurrency as follows:
-
In the configuration file, describe the resources you want to create:
yandex_function: Description of the function being created and its source code.name: Function name.user_hash: Any string to identify the function version. When you change the function, update this string as well. Updating this string triggers a function update.runtime: Function runtime.entrypoint: Entry point in<file_name_without_extension>.<handler_name>format.memory: Amount of memory allocated to the function, in MB.concurrency: Maximum number of calls processed concurrently by a single function instance.execution_timeout: Maximum function execution time before timeout.service_account_id: ID of the service account you want to use to invoke the function.content: Function source code.content.0.zip_filename: Name of the ZIP archive containing the function source code.
Here is an example of the configuration file structure:
provider "yandex" { token = "<service_account_OAuth_token_or_static_key>" folder_id = "<folder_ID>" zone = "ru-central1-a" } resource "yandex_function" "test-function" { name = "<function_name>" user_hash = "<hash>" runtime = "<runtime>" entrypoint = "<entry_point>" memory = "128" concurrency = "2" execution_timeout = "10" service_account_id = "<service_account_ID>" content { zip_filename = "<path_to_ZIP_archive>" } }For more information about resource properties, see yandex_function.
-
Validate your configuration using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
You can check that the concurrency parameter was added using the management console
yc serverless function version get <version_ID>
To set the number of calls to be processed concurrently by a single function instance, create a function version using the createVersion REST API method for the Function resource or the FunctionService/CreateVersion gRPC API call. Add the concurrency field to the request body.