This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

preface

Before developing performance test scripts, you need to be proficient in using a performance test tool, or not proficient in writing code.

After all, designing a proper performance test script is a good starting point for performance testing.

1. Analysis of system characteristics

Analyze the characteristics of the system: used to doing various HTTP protocol interface performance test, what if encounter other protocols: Dubbo, SOAP, MQ and so on

1.1. Jforum
It is Java implementation of a powerful and robust discussion board system, B/S architecture, belongs to the Web system, so the basic can be seen is HTTP protocol, JSP pages. But unlike restful apis, or JSON return object interfaces, or XML messages, it can be difficult to develop scripts.Copy the code
1.2. Service Architecture
It is developed around the MVC framework and can be deployed on Servlet 3.1 containers or application servers running in Java 8; Simple deployment mode: Tomcat /jboss+Jforum+mysql.Copy the code

Second, script development

There is a previous article on script development, through a little analysis and functional experience, then the system test script, is not suitable for capturing packages or interface documents to complete the development;

Simple through the recording of the way to generate scripts, and then improve it; Solution: Badboy+JMeter, JMeter itself recording components generate scripts.

2.1 Script Recording Process (omitted)

The plan has been given, as long as the actual operation can be. The resulting script is structured as follows:

2.2. Improve the script

What does it take to perfect a script?

  • After script development is completed, the first step is playback to confirm whether the request is successful and whether the business is successful.
  • Then according to the request results to improve the script, increase rationality, robustness.
  • Does the user need to be parameterized? Some systems are designed so that the user can log in repeatedly in a single machine.
  • Whether the context request parameters are related, assuming that different users request different data, the next interface’s input parameter dependency may fail.
  • For interface authentication, the login interface should not only be responsible for login, and the subsequent request should also carry the token. The background needs to check whether the authentication is passed before delivering data.
2.3. Parameterization

This is an important way to enhance scripts. Correlation processing is also a way of parameterization.

In real business scenarios, requests come from different users and the response data varies.

  • Describes several components that JMeter uses for parameterization
  1. CSV Data Set Config: most commonly used for processing large amounts of Data.
  2. Counter
  3. User Defined Variables
  4. Random Variable

There are also pre-processors, database SQL operations, and powerful data source configuration elements such as CSV

  • Introduces several components that JMeter uses to correlate
  1. JSON Extractor: Used to deal with JSON objects
  2. Regular Expression Extractor: Regular expressions are great for extracting data in HTML or other text formats
  3. BeanShell PostProcessor

Again, it has a lot of choices, and I'm just going to pick some of the representative ones, and I'm not going to repeat them here.

  • This section describes several JMeter functions that can also be used for parameterization
  1. ${__counter(,)}
  2. ${__CSVRead(,)}
  3. ${__iterationNum}
  4. ${__Random (1, 10,)}
  5. ${__threadNum}

Conclusion: about parametric because involving JMeter tool itself to use of the role of components, don't go into here, recommend the JMeter's official website (https://jmeter.apache.org/usermanual/index.html), with the use of the detailed introduction.

Scene design

Back at this point, the script has been developed, and one recommendation is that all scripts be developed as a minimum unit business scenario, so that it is both independent and seamless.

3.1. Independent scripts

Let’s not call it standalone scenarios, because a standalone script that is not affected by other scripts can perform performance tests as a business scenario.

So what should we do with standalone scripts? Remember in performance testing, did you analyze performance metrics? Must have, otherwise performance test basis, meaning?

Assume that the following data is obtained through service log monitoring or system monitoring:

One of Log in 25% Posting 10% Reply to 15% Browse the 50%
tps 13.75 5.5 8.25 27.5

It is actually set up by scenario, login does not need to exist as a separate script, because we do not do performance testing for login, or performance problems do not occur in the login scenario.

As follows: We need to post (in the system is to support anonymous Posting), reply need to log in, so the login and these two operations into a separate script, then browsing is an independent script.

Note: All script minimum transactions are the HTTP Sampler sampler itself, which can contain multiple operations through the transaction controller.

3.2. Combination scenarios

Through the previous data analysis, the inevitable performance test scenario is crossover, that is, it is impossible for all users to post and reply at the same time, it must be someone Posting and reply.

Now that you know the scale data, you need to design your scripts when they are finished: don’t put all your business in the same thread group because it’s complicated,

It is not possible to accurately distribute samples in proportion. It is suggested to separate a thread group according to the business, so that it is easy to maintain and expand, and most importantly, it does not affect the execution order.

  • Log in and post
  • Log in and reply
  • Do not log in to browse
3.3. Scenario design is not a composite script

The so-called design refers to the operation habits of actual users more closely, that is, to simulate user behavior.

  1. It’s not a rush of logins, it can be regular or irregular logins, say 30 users, 5 logins every 2 seconds, 30 logins in 12 seconds;
    1. The myth is that unless it is a one-time controller, it will log in and immediately perform other business or itself
  2. When users operate in practice, they will certainly think, rather than agree with others to operate together. They can only say that they want to be concurrent with the meaning, so the thinking time also needs to be considered
  3. In order to accurately find the performance inflection point, the system pressure must last for a period of time, so this time can be captured from the system monitoring to see the peak and valley, from when it began to go up and slowly down.

Note that the thread iteration limit priority is less than the duration, i.e., when the duration is 0, constrained by the ramp up time(SEC), which ends in a few seconds and the thread stops.

Four,

Scenario design is not simply to design scripts and combine scenarios, but to conform to user behavior habits and simulate real production business behaviors.

The preparation for the performance test includes setting up the environment, constructing data and script development

Before performing performance tests, there should be a reasonable scenario design so that performance bottlenecks can be accurately located

During the execution of performance test, one is to observe the running status of scripts and the other is to monitor system resources

The final performance result analysis can be further analyzed in the process and finally through the monitoring platform

In general, performance testing this thing, not on paper, more need to combat, the process is not heavy, only the order and by virtue of experienced experience.

“Welcome to the discussion in the comments section. The nuggets will be giving away 100 nuggets in the comments section after the diggnation project. See the event article for details.”