当前位置:网站首页>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 .
边栏推荐
- Gin framework: add API logging Middleware
- The cloud game is rendered by the server. How much broadband does the server need
- [Tencent cloud double 12.12] from 56 yuan! New users of Tencent cloud buy for the first time, which is more cost-effective!
- Using the database middleware MYCAT to realize read-write separation (dual master and dual slave)
- Efficient Internet access and systematic learning
- Echo framework: add API logging Middleware
- How to apply for top-level domain names? What are the types of top-level domain names?
- Question: can you get download the resources of Baidu online disk?
- How to build your own website? Is it difficult?
- Wkwebview audio and video media playback processing
猜你喜欢
随机推荐
MySQL Cases-MySQL 8.0.26 bug ERROR 1064 (42000) at line1: You have an error
Start tcapulusdb process
In PHP, use recursive depth to merge multiple arrays
Official spoilers! Figure 1 understand Tencent security @2021 Tencent digital ecology Conference
Easycvr cannot be played when cascaded to the superior platform. Troubleshooting
Go language starts again, go modules' past life, present life and basic use
Afnetworking server client
[tcapulusdb knowledge base] manually view the online operation of tcapulusdb
How does easydss solve the problem that the concurrency is too large and the disk read / write cannot keep up?
Do you still understand the deadlock handling methods in MySQL performance testing and tuning?
Is a trademark domain name useful? How long does it take to register a domain name?
The principle of Fortress application publisher
Cloud rendering: cloud exhibition hall of Tencent digital ecology Conference - open roaming mode on cloud
How to choose the appropriate configuration server?
The cloud University of "digital and real integration, CO building authentic Internet" is surging forward
How to protect your code - ollvm (1)
Is the server connected to the fortress machine a virtual machine? What if the fortress machine IP is not connected
Are cloud game servers expensive to rent? Factors to consider in cloud game server leasing
How to install an application publisher
Data acquisition and transmission instrument environmental pollution monitoring of iron and steel plant


