Performance test system based on online request CPC

Source: Internet
Author: User
Tags response code grafana influxdb

1. Background

Testers in the design of performance test scripts, the parameters in the HTTP request are often based on personal experience, and the tester level is uneven, design often has limitations, not comprehensive enough to cover the entire line of the real request, so the results of the performance test can not be true to reflect the actual situation online.

Using HTTP requests in the online environment to check the performance of the software, through the GOR record online real requests, as a performance test script request pool, the request pool materials for performance testing, can truly reflect the software system on-line environment performance indicators and problems.

2. Concept 2-1. Architecture diagram

2-2. Technology Stack Request Pool:

Gor:

HTTP Recording Tool Https://github.com/buger/gor

Webdis:

A very simple Web server providing an HTTP interface to Redis Https://github.com/nicolasff/webdis

Redis

Persistent cache

Performance Testing Tools:

Ngrinder two times development:

http://blog.csdn.net/neven7/article/details/50740018

Spring MVC

Link Visualization:

Watchman (Weibo APM)

InfluxDB:

Sequential DB https://github.com/influxdata/influxdb

Grafana:

Visualization tool Https://github.com/grafana/grafana

3. Implementation 3-1. Request Pool

Use Gor to record line requests, serialize to JSON String according to line request, persist to Redis; performance test scripts get to the online request data based on key, and perform a pressure test.

To facilitate the deployment of the request pool, Docker the request pool and use the following name to launch the Docker container:

-i-t--net=host gor-request-parser /bin/bash

To start recording online data:

808060 GET your_api_name NONBASIC ip port参数介绍:8080:监听端口60METHODyour_api_name:过滤其他url,只保留your_api_name请求NONBASIC:非BASIC认证接口,参数BASIC为BASIC接口ip port:webdis服务

After 60s, request data is persisted to Redis

***************************************************Gor HTTP request serializationHTTP request log, after 60 seconds, the record is terminated***************************************************version:***************************************************end of record, HTTP request serialized to request Pool@author Hugang***************************************************

The Redis key is$date_$hostname_$url

Value is a JSON Array with the form:

3-2. Performance test Scripts

Performance testing tool using Ngrinder, for two times development, please refer to: http://blog.csdn.net/neven7/article/details/50740018;
The performance test script uses Redis to fetch data on the wire, relying on Jedis, Fastjson, to import the 2 jar packages in script lib.

Example:

 PackageOrg.ngrinder;Import StaticNet.grinder.script.Grinder.grinderImport Staticorg.junit.assert.*Import Staticorg.hamcrest.matchers.*ImportNet.grinder.plugin.http.HTTPRequestImportNet.grinder.plugin.http.HTTPPluginControl;ImportNet.grinder.script.GTestImportNet.grinder.script.GrinderImportNet.grinder.scriptengine.groovy.junit.GrinderRunnerImportNet.grinder.scriptengine.groovy.junit.annotation.BeforeProcessImportNet.grinder.scriptengine.groovy.junit.annotation.BeforeThread//import static net.grinder.util.grinderutils.*//You can use the If you ' re using ngrinder after 3.2.3ImportOrg.junit.BeforeImportOrg.junit.BeforeClassImportOrg.junit.TestImportOrg.junit.runner.RunWithImportHttpclient.httpresponseImportHttpclient.nvpairImportJava.util.ArrayList;ImportJava.util.Collections;ImportJava.util.List;ImportGroovy.json.JsonBuilderImportGroovy.json.JsonSlurperImportCom.alibaba.fastjson.JSONArray;ImportRedis.clients.jedis.Jedis;/** * A Simple example using the HTTP plugin that shows the retrieval of a * single page via HTTP. * * This script was automatically generated by Ngrinder. * * @author Hugang * *@RunWith(Grinderrunner) class Testrunner { Public StaticGtest Test Public StaticHttpRequest request Public StaticFile file Public StaticJsonarray Jsonarray @BeforeProcess Public Static void beforeprocess() {httpplugincontrol.getconnectiondefaults (). Timeout =6000Test =NewGtest (1,"Pressure measurement IP") Request =NewHttpRequest () Test.record (request);//Read request pool dataJedis Jedis =NewJedis ("Redis IP", Redis port);//Redis keyString key ="Your Key";        String jsonstr = Jedis.get (key); Jsonarray = Jsonarray.parsearray (JSONSTR);//Grinder.logger.info (jsonarray.getstring (0));        //Grinder.logger.info ("before process.");}@BeforeThread      Public void Beforethread() {grinder.statistics.delayreports=true; }@Test     Public void Test(){//random Access        intindex = (int) (Math.random () * jsonarray.size ());        String httpinfo = jsonarray.getstring (index); def JSON =NewJsonslurper (). ParseText (httpinfo) String API = Json.api Map param = json.param def NVS = [] pa ram.each{key, Value--Nvs.add (NewNvpair (key, value))}//Get request, Wiki http://grinder.sourceforge.net/g3/script-javadoc/net/grinder/plugin/http/HTTPRequest.html        //Param1:uri, Param2:querydata        //HttpResponse get (java.lang.String uri, nvpair[] querydata) makes an HTTP GET request.HttpResponse result = Request. GET ("//Voltage measurement IP"+ API, NVs as nvpair[])if(Result.statuscode = =301|| Result.statuscode = =302) {Grinder.logger.warn ("Warning. The response may is not correct. The response code was {}. ", Result.statuscode); }Else{Assertthat (Result.statuscode, is ( $));//Request the returned data            //println (result.text);            //Define a transaction, the interface returns the data check, whether it containsAssertthat (Result.text, containsstring ("\" Code\ "")); }    }}
3-3. Visualization of link time distribution

Link time display, start Web Service specify-javaagent as the Watchman agent, using bytecode enhancement to get the distribution time of the code link over a certain period of time.
Please refer to: http://blog.csdn.net/neven7/article/details/50980726

Performance test system based on online request CPC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.