In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will show you how to change the function configuration to realize the timing configuration preset concurrency. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
Preset concurrency allows concurrent instances to be started in advance according to configuration, rather than when a request is accepted. You can use this feature to set the preset concurrency quota for the specified version of the function. By configuring preset concurrency, computing resources can be prepared in advance and the time-consuming caused by cold start, running environment initialization and business code initialization can be reduced.
Since the preset concurrency function started internal testing, it has received hot attention, and some users have grabbed the qualification of internal testing, and put forward a lot of valuable suggestions for us. Thank you for your attention and support.
One of the suggestions is: "tomorrow morning at 10: 00 to start the event, I need to preset a lot of concurrency in advance, but I am very worried that I forgot to configure (overslept), is there any way to set a schedule?"
Of course there is! As a small expert in using Serverless, we will change the cloud function configuration today to achieve timing configuration preset concurrency.
The preset is wonderful, sleep in!
First, create a function
In the SCF console * * New * * function, search for "preset" in the search box, select scheduled preset Demo, and click next to complete the creation.
Function console address: https://console.cloud.tencent.com/scf/list
Open the code editing page of the function, and we can see that the code in it uses Tencent Cloud's Python SDK to modify the function configuration (the calling code can be generated by using the API Explorer tool in the API document of the cloud function).
Now, this code has the ability to set preset concurrency, but it is not authorized yet. It's like a kid learning to use a password lock, but ta doesn't know what the door password is.
There are two ways to authorize:
The first is a long-term key, which can be obtained in the "access key" of the console "access key" instead of os.environ.get ('TENCENTCLOUD_SECRETID') and os.environ.get (' TENCENTCLOUD_SECRETKEY') in the code, and the os.environ.get ('TENCENTCLOUD_SESSIONTOKEN') parameter is removed.
This method has a clear text key in the code, which has a certain security risk, so we use the second approach here-bind the running role.
Second, bind the running role (automatic binding when creating a function is supported)
The key to binding a running role is to bind a role with a QcloudSCFFullAccess policy to this function. You can add a policy to an existing role, or you can create a new role to bind. Here we create a new role.
On the "function Management > > function configuration" page, click "Edit" at the top right to enter the editing state, enable "running role", and click to enter the "New running role" page.
Select "SCF" (here you can Ctrl+F scf, about in the lower right corner), "next".
Select "QcloudSCFFullAccess Policy" and then "fill in the role name" to complete the role creation.
Go back to the console of SCF, select the newly created scf_full_role in the running role, and click "finish".
Third, configure timing triggers
Next, there is the key to this article: after getting the key and mastering the method of opening the door, how should we timing?
On the trigger Management page, we create a new timing trigger, which cannot be modified after creation, so we need to fill in the correct configuration at one time.
3.1 set trigger period
The time configuration of the timing trigger uses an cron expression, and the seven required fields represent seconds, minutes, hours, days, months, weeks, and years, respectively. For a detailed description of the articles in which you can view cloud functions, here are some common use cases:
055 19 24 3 * 2021 means that 0.021 * will be triggered at 19: 55 on March 24, 2021 * that 015 10 * * MON-FRI * will be triggered at 2 am on the 1st of each month, that 0010 MON-FRI will be triggered at 10:15 every day from Monday to Friday, that it will be triggered at 10:00, 2 pm every day. Triggering 0 * / 309-17 * at 4 o'clock means triggering 0012 * * WED * every half hour from 9: 00 a.m. to 5: 00 p.m. Every day. It means triggering every Wednesday at 12:00
It can be flexibly configured according to the needs of the business, and it is recommended to start at least half an hour or an hour in advance.
3.2 preset Information
In the "additional information" of the timing trigger, we need to fill in the function and version information we need to preset.
Qualifier is the version number of the function, and VersionProvisionedConcurrencyNum is the concurrent value of the required preset. Entering 0 means canceling the preset.
{"Region": "ap-beijing", "FunctionName": "your_function_name", "Namespace": "your_namespace", "Qualifier": "2", "VersionProvisionedConcurrencyNum": 5}
Create two triggers here, which are responsible for starting preset concurrency and turning off preset concurrency, respectively.
Set the configuration information for Startup preset concurrency-fill in the additional Information:
# cron expression 0 55 19 24 3 * 202 additional information {"Region": "ap-beijing", "FunctionName": "your_function_name", "Namespace": "default", "Qualifier": "2", "VersionProvisionedConcurrencyNum": 5}
Set the configuration information for "turn off preset concurrency"-fill in the "additional information"
# cron expression 0 00 23 24 3 * 202 additional information {"Region": "ap-beijing", "FunctionName": "your_function_name", "Namespace": "default", "Qualifier": "2", "VersionProvisionedConcurrencyNum": 0}
After configuration, the timing trigger is started, and the timing preset concurrency is configured.
If you want to confirm whether the preset concurrency is configured properly, you can check the record of the corresponding time in the call log. If you see that RequestID is returned correctly in the log, it proves that the preset concurrency has been successfully configured or closed.
The above is how to use function configuration to achieve timing configuration preset concurrency of all the content, more and how to use function configuration to achieve timing configuration preset concurrency related content can search the previous article or browse the following article to learn ha! I believe the editor will add more knowledge to you. I hope you can support it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.