LoadRunner performance testing system learning tutorial: scripting asynchronous technology (8)

Last issue talked about the introduction of LoadRunner performance test correlation function, this issue we will learn asynchronous technology together.

The difference between synchronous and asynchronous

Some of the usual functions of the Web are to process requests in a synchronous manner. The steps of a typical synchronous request are as follows:

1. The user uses a Web browser to interact with the server;

2. Based on the user's input, submit a request to the server through a web browser;

3. Then the server sends the requested response back to the client and updates the client's information.

The synchronization method has some limitations. A typical drawback is that the dynamic data of the server cannot be displayed on the client side, such as the dynamic display of the stock price. Ideally, the client side of the application can dynamically display the updated data on the server side. , Synchronization updates the stock price at regular intervals. For example, every 10 seconds, the browser will automatically send a request to the server and get the latest stock price.

In some cases, asynchronous applications can be used instead of synchronous applications. When the server finds an event change, the asynchronous program will notify the client. The asynchronous application can better update the required information, so that the client does not need to wait for the server The request processing is completed, but other requests can be processed in this process, as long as the server processing is completed, the client will be automatically notified to update the processed value.

In the performance test process, in order to better handle this kind of service that the server dynamically updates the value at intervals, an asynchronous processing API function is added to the latest LoadRunner version to handle this situation, so that it will not be sent every time you replay The request to write some dynamic values ​​as fixed values ​​to better simulate user behavior.

Although there are many ways of asynchronous processing, there are mainly three ways: heap, polling and long polling.

Asynchronous communication method

Asynchronous communication is composed of request and response sequences. The usual asynchronous methods include heap, polling and long polling. If you choose the asynchronous method when recording a script, it depends on the asynchronous processing method of the recorded service. The communication principles of heap, polling and long polling are as follows:

Poll asynchronous communication

The client regularly sends HTTP requests to the server at regular intervals, such as every 5 seconds, sending a request. If the service accepts the response and updates the data, it will return the updated data to the client. If there is no update Data, then the client will continue to send HTTP requests to the server. The principle of asynchronous polling is shown in the figure.
LoadRunner performance testing system learning tutorial: scripting asynchronous technology (8)

Long polling asynchronous communication

Long polling means that if there is data after the server receives the request, it will immediately respond to the request and return the data to the client. If there is no data, it will stay for a period of time. During this period, if there is data, it will immediately respond to the request. If the time is up, there is no data. , The HTTP request is responded to, and the browser immediately sends the same HTTP request to query whether there is updated data after receiving the HTTP response. The asynchronous communication principle of polling is shown in the figure.
LoadRunner performance testing system learning tutorial: scripting asynchronous technology (8)

Heap asynchronous communication

The client opens a connection and sends an HTTP request to a known server, so that the client is no longer disconnected from the server. When necessary, the server will send a "sub-message" to the client to update the opened client. If the server does not To actually send update information, the server will send a "ping" message to prevent the client from closing the connection due to connection timeout. The principle of asynchronous communication on the heap is shown in the figure.
LoadRunner performance testing system learning tutorial: scripting asynchronous technology (8)

How to create an asynchronous script

During the recording of the script, if the script contains data that needs to be processed asynchronously, LoadRunner will automatically scan for data that needs to be processed asynchronously. After the recording is completed, the Aysnc settings dialog box will pop up, in which the asynchronous processing will be displayed. Happening.

In this article, the official booking system of Qunar is taken as an example, as shown in the figure. Introduce asynchronous script processing, the specific steps are as follows:
LoadRunner performance testing system learning tutorial: scripting asynchronous technology (8)

1. Select HTTP/HTML protocol to record script

Note: Asynchronous processing only applies to

Four protocols: HTTP/HTML, Flex, Silverlight and Web Services.

2. Set Async Scan options

Enter the Recording Options interface, select the General->Code Generation tab, and make sure that the Async Scan checkbox is selected.

Click the Async Options button to pop up the Asynchronous Request Thresholds dialog box, as shown in the figure, in which the parameters of the asynchronous request can be set.
LoadRunner performance testing system learning tutorial: scripting asynchronous technology (8)

A.Minimum Response Size:

Specify the minimum number of bytes in the response of the heap asynchronous conversation server. If the number of bytes sent by the server is less than the minimum number of bytes, then VuGen will not summarize this asynchronous type as a heap method.

B.Maximum Sub Message Size:

Specify the maximum number of bytes in the response of the heap asynchronous conversation server. If the number of bytes sent by the server is greater than the maximum number of bytes, then VuGen will not summarize this asynchronous type as a heap method.

C.Minimum Number of

Sub Messages:

Specify the minimum number of valid sub-messages sent by the heap asynchronous session. If the message sent by the server is less than the number of sub-messages, then VuGen will not summarize this asynchronous type as a heap method.

D.Interval Tolerance:

Specify the polling asynchronous interval time, in milliseconds.

E.Maximum Interval:

Specify the time interval between the end of the long polling asynchronous response and the sending of the next request.

1. Start recording script

2. After the business recording is completed, stop recording. At this time, VuGen will automatically scan whether asynchronous processing is required. If the scan finds information that needs asynchronous processing, the message shown in the picture will pop up.
LoadRunner performance testing system learning tutorial: scripting asynchronous technology (8)

Note: In order for VuGen to successfully determine the asynchronous behavior, the asynchronous communication must contain at least the required minimum number of client requests and server responses.

1. Click the Close button to complete the script recording. The following code is generated in VuGen:

/ Added by Async CodeGen.ID=Poll_0ScanType = RecordingThe following urls are considered part of this conversation: http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582390617&_token=72210&deduce=true http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582391928&_token=19725&deduce=true http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582395184&_token=24410&deduce=trueTODO - The following callbacks have been added to AsyncCallbacks.c.Add your code to the callback implementations as necessary. Poll_0_RequestCB Poll_0_ResponseBodyBufferCB Poll_0_ResponseCB / web_reg_async_attributes("ID=Poll_0", "URL=http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status={CorrelationParameter_3}&_token=72210&deduce=true", "Pattern=Poll", "PollIntervalMs=3000", "RequestCB=Poll_0_RequestCB", "ResponseBodyBufferCB=Poll_0_ResponseBodyBufferCB", "ResponseCB=Poll_0_ResponseCB", LAST);.../ Removed by Async CodeGen.ID = Poll_0/ / web_url("onewayflight_groupdata.jsp_6","URL=http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582391928&_token=19725&deduce=true","Resource=1","RecContentType=text/plain","Referer=http://flight.qunar.com/site/oneway_list.htm?searchDepartureAirport=%E6%B7%B1%E5%9C%B3&searchArrivalAirport=%E5%8D%97%E6%98%8C&searchDepartureTime=2013-04-12&searchArrivalTime=2013-04-15&nextNDays=0&startSearch=true&from=qunarindex","Snapshot=t167.inf", LAST); // Removed by Async CodeGen.ID = Poll_0/ / web_url("onewayflight_groupdata.jsp_7","URL=http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582395184&_token=24410&deduce=true","Resource=1","RecContentType=text/plain","Referer=http://flight.qunar.com/site/oneway_list.htm?searchDepartureAirport=%E6%B7%B1%E5%9C%B3&searchArrivalAirport=%E5%8D%97%E6%98%8C&searchDepartureTime=2013-04-12&searchArrivalTime=2013-04-15&nextNDays=0&startSearch=true&from=qunarindex","Snapshot=t168.inf", LAST); // Added by Async CodeGen.ID = Poll_0/ web_stop_async("ID=Poll_0",

Guess you like

Origin blog.51cto.com/14645850/2541353