当前位置:网站首页>Cloud function pressure measurement based on wechat applet
Cloud function pressure measurement based on wechat applet
2022-06-24 02:40:00 【cailynyu】
During the pressure measurement of a project , The wechat applet cloud function needs to be pressure tested , However, cloud functions are called through wechat applets instead of http request , It is not possible to simulate user access through the pressure test tool , So how to measure the cloud function ?
What is a cloud function ?
Official document of wechat applet That's how it's described :
The cloud function is in the cloud ( Server side ) Running functions . No need to buy 、 Set up server , Just write the function code and deploy it to the cloud to call on the applet side , At the same time, cloud functions can also call each other .
Let's look at an example of a cloud function :
// ...
exports.main = async (event, context) => {
// ...
return {
sum: event.a + event.b
}
}The above code implements : Will the incoming a and b Add as sum Field is returned to the caller .
Before calling this cloud function in a small program , You need to deploy the cloud function to the cloud first . After deployment , The cloud function can be called in the applet :
wx.cloud.callFunction({
// Cloud function name
name: 'add',
// Parameters passed to cloud function
data: {
a: 1,
b: 2,
},
success: function(res) {
console.log(res.result.sum) // 3
},
fail: console.error
})This successfully creates a simple cloud function , And successfully call... In the applet .
How to realize cloud function pressure measurement ?
As can be seen from the above section , Cloud functions are called through wechat applets , The general pressure measurement pursues commonality , Will be based on http Request for pressure test . Is it possible for the cloud function to pass http Request to third party ( Non wechat applet ) To call ?
Here are three options to try :
Method 1 according to appid and secret obtain access_token To trigger the cloud function
Step 1 : call auth.getAccessToken Interface , According to the applet unique credentials appid and Applet unique credential key secret Get the globally unique background interface call credentials of the applet access_token( appid and secret It can be obtained when the applet is registered )
Request address :GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Request parameters :
Return value :
adopt postman Call the interface to get access_token
Step 2 : call invokeCloudFunction Interface , With https Method to request cloud functions
Request address :POST https://api.weixin.qq.com/tcb/invokecloudfunction?access_token=ACCESS_TOKEN&env=ENV&name=FUNCTION_NAME
Request parameters :
Return value :
adopt postman Call the interface to trigger the cloud function
This method of accessing cloud functions Checkpoint lie in :
The cloud functions developed by the cloud are seamlessly integrated with wechat login authentication . When the applet calls the cloud function , The incoming parameters of the cloud function will be injected into the applet end users openid, And by http api Method to trigger cloud functions without user information , therefore , This method Is not workable .
See :https://developers.weixin.qq.com/minigame/dev/wxcloud/guide/functions/userinfo.html
Method 2 Manually realize concurrent pressure measurement 、 The logic of the calculation results
Pressure measurement is divided into pressure measurement end ( hereinafter referred to as A End ), Service under pressure test ( hereinafter referred to as B End ).
Process implementation to be updated ...
Method 3 Create a new cloud function http Trigger path
Add cloud functions to the cloud development module of Tencent cloud Trigger path , Get the... Corresponding to the cloud function http request URL, be used for jmeter The isobaric tool configuration script performs pressure testing on cloud functions , The specific steps are as follows :
- Get into
Development of cloud CloudBase modular, Click onCloud functions
- Cloud function /test For example , If you want to test Cloud function for pressure measurement : Request parameters :
- Get into http Access the service interface :
- choice “ Click the jump ”
- Click on “ newly build ”
- Create a trigger path for the required pressure measurement cloud function :
- After setting up the trigger path , Click the corresponding function , You can trigger the request cloud function in the browser :
- Copy the browser address bar URL, You can get the cloud function http request URL, be used for jmeter Script configuration .
In contrast , Adopting method 3 can quickly realize cloud function pressure measurement .
summary
If necessary Cloud function for pressure measurement , You can add pressure test in Tencent cloud function module Trigger path of cloud function , obtain http Request to implement the pressure test of cloud functions .
边栏推荐
- What is the industrial Internet? What is the industrial Internet platform?
- How many graphics cards are required for cloud game servers? What should be paid attention to when purchasing servers
- More than 10 million Android users installed a fraud app and doubled the number of blackmail attacks in the UK | global network security hotspot
- [tcapulusdb knowledge base] manually view the online operation of tcapulusdb
- What information should be provided for enterprise trademark registration? Is it difficult to register a trademark?
- Echo framework: add API logging Middleware
- How does easydss solve the problem that the concurrency is too large and the disk read / write cannot keep up?
- Centeros environment setup
- In PHP, use recursive depth to merge multiple arrays
- How to improve the success rate of trademark registration? How long does it take to register a trademark?
猜你喜欢
随机推荐
Prompt error when Jekyll runs cannot load such file -- webrick (LoadError)
Code 128 barcode details
How much does it cost to rent a cloud game server? Which cloud game server is more reliable?
IPhone sending SMS implementation
How to build a cloud game server what needs to be considered to build a cloud game server
Create and mount large files
Wwise + GME game voice scheme: unlock more voice playing methods and let players "sound in their environment"
How to build your own cloud game server and what are the building steps
Are cloud game servers expensive to rent? Factors to consider in cloud game server leasing
November 1 global network security hotspot
Tornado code for file download
Tke single node risk avoidance
S2b2c platform of fresh food industry reshapes the ecosystem of agricultural products and builds a mobile fresh food comprehensive mall
What are the main functions of DNS? What are the benefits of IP address translation
What is the industrial Internet? What is the industrial Internet platform?
Visual AI, first!
Afnetworking usage and cache processing
Case of data recovery by misoperation under NTFS file system
[Tencent cloud load balancing CLB] cross region binding 2.0 (new version) idc-ip best practices!
Start tcapulusdb process


