background

With the servitization design of mainstream systems, especially the popularity of SOA architecture and microservice architecture, interface has become the communication bridge between systems. Therefore, interface performance pressure measurement is becoming more and more important.

SOA(Server Orientation Architecture) is the current common component model. It links the different functional modules of a software system, called services, through interfaces. The interface can be a specific interface service or middleware that connects two modules to communicate. A large project is usually composed of multiple systems, each of which has a dedicated research and development team. The functions of a single system are called modules. The function of the module is divided by interface implementation and UI presentation of the background.

Microservices architecture is in some ways the next step in the continued evolution of service-oriented architecture SOA. Basically, this type of architecture is a special way to develop software, web, or mobile applications as a separate suite of services (also known as microservices). The creation of these services is limited to a specific business function, such as user management, user personas, e-commerce vehicles, search engines, social media logins, and so on. In addition, they are completely independent, which means they can write to different programming languages and use different databases. Centralized service management is almost nonexistent, and microservices communicate using lightweight HTTP, REST, or Thrift apis.

The main target

Obtain single interface/single service capacity

Find performance bottlenecks in your application

Discover a database performance bottleneck

The test strategy

An overview of the

Most of the time, we need to call the system interface platform when designing the interface performance pressure test script. If the interface platform does not provide a usable UI interface, we need to write our own code to connect the interface platform with pressure test tools and call the interface according to the corresponding protocol. Interface methods need to invoke many dependent methods during execution. Depending on the method, the return content also needs to be considered. But depending on the interface content we can’t control. Sometimes the dependency module doesn’t work properly, sometimes the dependency module isn’t fully developed, and sometimes we objectively and unconditionally make the dependency module return the desired outlier. After the Mock system (baffle) defines the data related to the interface, the Mock system (baffle) can fill in the target result to simulate the interface to return the desired content

In combination with the open source performance testing tool Jmeter (this article only focuses on this tool), the corresponding execution results can be obtained only by simulating THE URL through THE HTTP concurrent request, and then the interface execution can be judged according to the returned results. So the time cost is relatively low and it is relatively simple to convert a scenario into a test script. Parameters rarely change after an interface is published online. Because there are multiple callers after the interface is published as a service, if the parameter changes, all callers will be notified to modify the response, otherwise the caller will not be able to use it. The interface definition is stable and not prone to change, so there is not much maintenance work for the interface performance pressure test.

Main types of

type The specific content
Efficiency (performance) Concurrency, response time, TPS, error rate, resource usage
The stability of Long time repeated operation for single user, long time concurrent operation for multi-user, long time repeated operation for outlier, maximum failure time
pressure Handling within specification under over specification load
restorative Check whether the system recovers after the load becomes normal

Common interface

At present, the interface of the mainstream system can be roughly divided into HTTP interface and self-developed RPC (Remote Procedure Call) interface, and HTTP interface may be more common.

HTTP interface

HTTP interfaces are commonly used in pressure measurement WEB systems. There are two protocols: HTTP and HTTPS

HTTP Hypertext transfer protocol, default port 80 HTTPS secure hypertext transfer protocol, can be understood as the security version of HTTP, 443 common HTTP request methods: GET and POST

Two of the most commonly used methods for requesting/responding to a Server

GET requests data from the specified resource. POST submits data to be processed to the specified resource

The RPC interface

Remote Procedure Call Protocol (RPC) is a Protocol that requests services from Remote computer programs over the network without understanding the underlying network technology. In simple terms, this is to call the server-side method implementation as if it were calling a local class method.

You need to have some understanding of the concepts of STU (pile) and skeleton in RMI(Remote Method Invoke). RMI’s proxy mode passes methods to real objects through proxy objects. The Stub hosts the client and acts as a proxy for the remote object implementor. The skeleton class helps remote objects communicate with sttub connections.

Main principles:

Entity objects and business interfaces are shared by both clients and servers. Interface realization is the function realization of the defined business interface by the server and provides the interface instance registration service for the client to call.

At present, RPC interfaces mainly include Hession, Dubbo, HTTP, Thrift, Hprose, etc

Hession, Dubbo, Thrift, and Hprose are all implementations of remote method invocation, where the client needs to keep stubs to invoke the interface. This is why we need the Jmeter reference JAR package for performance profiling.

Hession: is a lightweight remoting onhttp tool. It uses a simple method to provide RMI functions. It is a kind of remote method call and uses binary RPC protocol (based onhttp protocol).

Dubbo: Alibaba open source a high performance excellent service framework, a remote method call framework. The Dubbo registry is responsible for registering and searching service addresses, which are equivalent to service catalogs. The Dubbo monitoring center is responsible for counting the number and time of service invocation

Thrift: An open source facebook framework for interoperable and scalable services A framework for remote method calls, extensible and cross-language development of services. Allows you to define data types and service interfaces (IDL) in a simple definition file. The server skeleton is then generated and the client invokes the proxy

Hprose: An open source framework for remote method calls developed by Chinese. It is an advanced lightweight, cross-language, cross-platform, object-oriented, high-performance remote dynamic communication middleware.

HTTP: Commonly used in WEB applications, text transfer is based on HTTP. When a URL sends a request, the server’s doGet or doPost methods are called to get the parameters. It is relatively easy to test HTTP interfaces by locating URL interfaces and passing assertions.

The following is a brief description of the interfaces:

Hession Interface pressure test:

Obtain the interface through the interface URL. If you copy the interface definition and custom classes, the package name should be the same as the development package. It is not recommended to directly copy the code, because it is not easy to maintain. It is usually obtained using HessianSpringFactoryBean, combined with Jmeter custom JAVA class requests and stubs into the test tool for compression

HessianProxy is the core class for Hessian client to process client requests. It adopts proxy mode and invokes the remote interface by the proxy client. The timing diagram of the main program of Hessian Client is as follows:

Dubbo interface pressure test:

If the service interface is obtained through the Dubbo registry, you need to specify the address of the Dubbo registry when setting up the test environment. You also need to configure the address of the Dubbo registry and the name of the interface that provides services externally when extending Jmeter. Direct connection to Jmeter requires importing JAR packages related to the Dubbo framework. The Jemter Dubbo plugin is now available and can be imported directly

Node description:

Provider: service Provider that exposes services Consumer: service Consumer that invokes remote services Registry: Registry for service registration and discovery Monitor: monitoring center that collects statistics on service invocation times and service invocation time Container: service running Container Jemter Dubbo plugin address: github.com/dubbo/jmete…

Jemter DubboSample screenshots

Thrift interface pressure test:

Write the interface (IDL) with Stub resident client invocation, generate the server skeleton class and client invocation proxy. The skeleton class helps remote objects communicate with stTUbb resident client connections. The client and server side are tightly coupled. You can’t individually change the interface on either side (not the implementation of the server-side code), the data types passed by the server and client are exactly the same

The specific method can refer to the following article:

Performance tool Jmeter compacts Thrift RPC services

Hprose interface pressure measurement:

The defined business interface is realized by the server, and the interface instance registration service is provided to the client to call. The local functions and methods are published as services, and the client can define the calling interface according to its own needs, or call the server-side functions or methods directly. Then, Jmeter customized JAVA class request and Stub access to the test tool for pressure measurement.

HTTP interface pressure test:

In short, the method of interface compression test varies with different frameworks, but in general, it is the steps of obtaining the interface, concurrent requests, parameterizing data, executing scripts, asserting results, and monitoring data.

So let’s do two practical examples

Practical examples

First, what is a Mock?

Here is the definition of mock from Taobao.com’s Interface Test White Paper:

A mock is the use of various techniques to simulate various resources needed for testing.

A mock resource typically has the following characteristics:

The measured target depends on the resource

This resource can be unstable, return results vary, or not always available for a variety of reasons

The resource has nothing to do with the quality of the object being tested

These resources may be an external or underlying interface, a system, a set of data objects, or a working environment for a set of target software. Mock can avoid the dependence on external real resources to achieve isolated testing of the tested target, thus greatly reducing the difficulty of testing and saving the cost of testing.

It is important to note that there are differences between passing a test using a mock and passing a test using a real environment. Sometimes we just need the system we’re testing to be able to handle all sorts of dependencies, both normal and abnormal, and we can’t guarantee that our mock will simulate every one of them. So mock only when it’s really necessary.

Moco

Moco is basically a mock tool framework that you can download as a JAR package

There’s this quote on Moco’s Github.

Integration, especially based on HTTP protocol, e.g. web service, REST etc, is wildly used in most of our development. In the old days, we just deployed another WAR to an application server, e.g. Jetty or Tomcat etc. As we all know, it’s so boring to develop a WAR and deploy it to any application server, even if we use an embeded server. And the WAR needs to be reassembled even if we just want to change a little bit. Translation:

Integration, especially HTTP protocol based integration, such as Web services, REST, etc., is used extensively in most of our development. In the past, we just deployed another WAR package to the application server, such as Jetty or Tomcat, etc. Developing a WAR package and deploying it to any application server is notoriously tedious, even if we’re using an embedded server. The WAR package also needs to be repackaged even if we just want to change it slightly. To put it simply, Moco is a solution to the awkward situation of developing front-end without back-end support and developing interface dependencies that are not in place. Of course, Moco’s flexibility allows it to be used in more and more scenarios, such as when we develop interface performance compression scripts.

Features:

You only need to configure request and Response, which support HTTP, HTTPS, and socket. It’s very flexible.

You can set Headers, Cookies, StatusCode, and so on in request.

Support for GET, POST, PUT, DELETE and other requests, suitable for Web development.

No environment configuration is required, just the Java environment.

The modification takes effect immediately. You just need to maintain the interface, the contract. Support for all possible data formats, such as JSON, text, XML, file, etc.

It also integrates with other tools, such as Junit, Maven, Gradle, and more. Foo. Json configuration example:

[
  {
  "response":
    {
     "text":"Hello, Moco"  
    }
  }
]
Copy the code

Load the configuration to start the Moco HTTP Server

java -jar moco-runner-standalone.jarhttp -p 12306 -c foo.json

Github address: github.com/dreamhead/m…

Pressure the HTTP GET method

In each example, only one thread is set

Startupget. json configuration file:

[{" description ":" this is a get request with cookies and parameters ", "request" : {" uri ":" 7 dget/", "method" : "get", "cookies" : {" login ":" 7 dgroup "}, "Queries" : {" name ":" zuozewei ", "sex" : "man"}}, "response" : {" text ":" success! "}}]Copy the code

Load the configuration to start the Moco HTTP Server

Jmeter set Cookies

The name field is the name of a cookie.

The value field is the value of a cookie.

The domain field is the domain name that can access the cookie. The localhost is a non-top-level domain name, such as the second-level domain name or the third-level domain name. The domain of the cookie can only be the top-level domain name or the second-level domain name or the third-level domain name itself, and cookies of other second-level domain names cannot be set. Otherwise, cookies cannot be generated.

Jmeter sets the HTTP GET Request

Note that the query string (name/value pair) is sent in the URL of the GET request: /7dget? name1=value1&name2=value2

Response result received by Jmeter

Correctly receive the return information to the server

Pressure the HTTP POST method

Startupget. json configuration file:

[{"description":" this is a request with headers and cookies and Json parameters ", "request":{"uri":"/ 7dPOST ", "method":"post", "headers":{ "content-type":"application/json" }, "cookies":{ "login":"7dgroup" }, "json":{ "name":"zuozewei", "sex":"man" } }, "response":{ "status":200, "json":{ "name":"success", "code":"1" } } } ]Copy the code

Load the configuration to start the Moco HTTP Server

Jmeter set headers

Jmeter set Cookies

Jmeter sets the HTTP POST Request

Note that the parameter is in JOSN format and is sent in the body of the message.

Response result received by Jmeter

According to our configuration, the server returns data in Json format

That brings us to the end of our two little practices