When doing Web program performance testing, LoadRunner and JMeter are two commonly used tools, compared to each other, jmeter is very light, and open source free, get started quickly. Here is a brief introduction of the use of JMeter, to login Baidu search as an example.
JMeter operation requires a JDK environment, this does not introduce much. Software interface:
-
Right-click the test plan and add a thread group
The thread group interface can configure the number of threads, "ramp-up Period (in seconds):" This parameter is
Configure the amount of time these thread groups are fully booted (you can set the time to long, which prevents the server from starting to get a lot of pressure), and you can configure the number of cycles, followed by a scheduler configuration.
-
Analysis of the process of login Baidu, first visit http://www.baidu.com, Baidu assigned to you a baiduid cookie; Click the "Login" button, The browser will take the relevant parameters and cookies to request nsclick.baidu.com, after Baidu to prevent CSRF attack (CSRF detailed analysis see: http://www.yeetrack.com/?p=220), will send a token to the client After entering username, password, the browser will be the user name, password, Token and related parameters post to passport.baidu.com for verification, after the success of the verification, Baidu will be assigned to the browser cookie, where there are Saveuserid and Bduss two, the above process can be easily obtained through the Firefox plugin Httpfox (about FIR Efox plug-in Httpfox, see http://www.yeetrack.com/post/2012-11-22/firefox%2520httpfox%25E6%258F%2592%25E4%25BB%25B6 in detail)
-
OK, start, create a new HTTP request in the thread group, fill in the domain name, port and other information
, &N Bsp , &NB Sp after the visit to Baidu, the server will immediately assign a Baiduid cookie, we need to extract this cookie, complete the subsequent authentication, right-click on this HTTP request, Add a regular expression extractor &NBS P , &NB Sp , &NB Sp , &NB SP; , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp Its page should be filled in like this: , &NB Sp , &NB Sp , &NB Sp , &NB Sp   , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp cookie in the header of the return packet, select the message header, the cookie name is Baiduid, the regular expression is used to match the cookie in the message header, The cookie in the HTTP message header looks like this: baiduid=eb8a76382372306096a079f34c1c84ea:fg=1; h_ps_pssid=1690_1438_1541_1542_1662_1582, Expression baiduid= (. *), which can be extracted from the cookie value (if you do not know the regular expression, see http:// www.yeetrack.com/post/2012-11-02/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%88%E4%B8%80%EF%BC%89), The following template means that if we write a regular expression that matches more than one piece of content, we go to the first of them, such as $1$, which is the second, the default value below means that if there is no match to the content, a default value is specified, which can not be filled in.
-
OK, next, click on the Baidu page in the upper right corner of the "login", with Httpfox or browser-brought network view to find the corresponding parameters. Corresponds to JMeter, which is to create a new HTTP request, get method. Should be filled in as follows: &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp 8 parameters to be filled out in the form, respectively. There is a parameter T, which refers to the current UNIX timestamp, and JMeter provides some functions that we can call directly${__time ()} This is called the JMeter system function to get the local time.
-
Well, forgetting one step, in the third step we use regular expressions to extract the cookie from the HTTP header of the return message, and we need to put this cookie into the JMeter message manager so that when Jmter sends an HTTP request, it automatically brings in the appropriate cookie, right-click on the "thread group The Add Cookie Manager component:
Add complete, configure, should look like this:
The name is the key of the cookie, which corresponds to the name in the HTTP message header; The value is the cookie we extract from the regular expression Value,${baiduid} refers to the value of the variable that is taken out of the baiduid (to correspond to the name of the regular Expression page), and the following two are used later. The domain and path of the cookie are filled in sequence.