当前位置:网站首页>Pressure measuring tool: correct opening mode of tarsbenchmark

Pressure measuring tool: correct opening mode of tarsbenchmark

2020-12-08 10:58:14 Tencent Yunjia community

​ Introduction | Tars Is led by Tencent open source , And donate to Linux The foundation's microservices RPC frame . and TarsBenchmark The launch of is to Tars Further improvement of Ecology , It supports online pressure testing, which greatly reduces the threshold for developers to use online evaluation service performance . This article is about Tencent expert engineer Chen Linfeng in cloud + Community salon online Share and organize , Hope to communicate with you .

Click this link to view the full live playback

One 、TarsBenchmark What is it?

1. Common pressure measuring tools

We are serving some of the backstage APP Before going online , Usually do some performance evaluation , And then we'll evaluate . For example, how many users can the developed project serve , And how much concurrency can be undertaken ?

(1)Apache Bench

Classic performance evaluation tools AB, Also called Apche Beach, It's a http Pressure testing tools for protocol services , It's a lot of WebAPP The classic pressure testing tool of , use C Language development , It is easy to use and has good performance .

But it also has shortcomings , The main reason is that it uses a single thread mode , Many of the servers in our background are multi-core , So it doesn't do the full performance of our server .

(2)Wrk

New pressure measuring tools Wrk, It makes up for AB The disadvantages of single thread design . It's an event driven network , On the Internet IO They have a better performance in terms of .

In addition, it supports scripting language . Can be in lua Generate random content . Now most of the back-end services are deployed in a distributed way , If only one request is replayed continuously , It is easy to cause high load of single machine , But it can't reflect the service capability of the real cluster . and wrk Improvements have been made in these two areas , So it's widely used .

(3)GHZ

There is also a typical pressure testing tool in microservices GHZ, He is GRPC A pressure measuring tool under the frame , The development language is golong, Therefore, it has good concurrency capability .

Its use case uses JSON The format organization of , It USES PB Good reflection makes it easy to put JSON The use case is transformed into the binary mode needed for network transmission , So it's very convenient to use .

(4)JMeter

Finally, let me introduce JMeter Tools , It's using Java Language development , Provides a graphical interface interaction form , Support distributed deployment , It can make up for the lack of single machine performance .

But because JMeter It's equivalent to a thread model , Simulate a user request with a thread , In fact, when threads accumulate to a certain number , Thread scheduling and contention can bring some extra CPU expenses , So its stand-alone performance has some shortcomings .

2. TarsBenchmark What is it? ?

There may be many other common pressure measuring tools , It's not going to unfold here one by one , The following is the main introduction TarsBenchmark, Let's see what features this tool has ?

(1) Pressure measuring tool for single machine operation

TarsBenchmark Is based on Tars A pressure measuring tool for ecology , It mainly serves Tars Service, and Tars It's Tencent's open source multilingual 、 High performance 、 Easy to operate microservices framework , Its communication protocol is Tars, and Tars Is similar to the PB A transport protocol for binary systems , And it's completely self-developed by Tencent . At present, the number of people involved in the development is approaching 300 A person , stay Github You type in TarsCloud You can enter the official introduction article to learn about our Tars.

Tars Support C++ And other development languages ,Tars Compared with other development frameworks such as PRPC etc. , It also provides a service platform , And it can help developers and enterprises to quickly build stable and reliable distributed microservice applications , Developers just need to focus on business logic , So as to improve the efficiency of R & D and operation .

(2) A platform supporting cloud pressure testing

TarsBenchmark Not only can it run on a single machine , It also provides a pressure measurement in the cloud Web platform , It can support distributed pressure testing , So that developers can be very convenient and leisurely TarsService Pressure measurement , To assess the Tars Service performance .

(3) Not only ForTarsService

When you use non in your team Tars Agreement Services , It can also be easily satisfied . In the rear TarsBenchmark In the use , I will show you how to develop non Tars agreement , It is easy to meet the pressure test of third party agreement with our tools .

3. What problems have been solved  ?

that TarsBenchmark What problems have been solved ? It mainly lies in the following three points :

  • High performance : Give full play to multi-core CPU Ability to calculate ,8 A nuclear machine can output 40Wtps Ability ;
  • High scalability : Support any one Tars Interface pressure test , Friendly support for non Tars agreement ;
  • Simple and easy to use : Use cases adopt JSON Format , Writing convenience , Support online cloud pressure measurement  .

Two 、TarsBenchmark principle

1. Principle of tool pressure measurement

(1) Multi process

Let's first introduce the implementation of high performance design , We have also analyzed AB and Wrk, among Wrk Yes AB The upgrade of is mainly implemented by multithreading , and TarsBenchmark It is also a multi process approach .

In the main process, we will go according to the number of physical cores of the server fork Equal number of pressure testing processes , The pressure measurement process is completely isolated , That is to run independently , Avoid competing for critical resources between processes . Of course, the number of pressure testing processes can be specified by parameters , Default will be based on CPU The effective kernel number of Fork The corresponding process .

(2) Network processing

In terms of network, it adopts an event driven approach , It's through a timer , Sending and receiving network events , Effectively avoid the Internet IO The block .

In addition, we use connection pool in connection , In connection pool, connection reuse is adopted for each connection . In our analysis AB Pressure measurement principle found that : When AB When a link is set up and a message goes out , After receiving this message, the next message will be sent , So in this link it will have a wait operation , Can't make full use of links and generate them at a uniform rate QPS.

and TarsBenchmark It's based on connection multiplexing , It doesn't depend on whether the opposite end returns . For external services, return to this scenario , When we use AB During the pressure test , Sometimes you will find that the server's return is very timely , So at this point AB Can achieve a very high output capacity ; But when it takes a lot of time for the server to return ,AB There will be a multiplier decline in output capacity .

for example : CGI stay 20ms The return of and 200ms Return , The same number of links affects AB Ten times the difference in performance output , So we think that link design is a waste .

stay TarsBenchmark Design with this in mind , Based on the serial number of the protocol packet, it can choose the next message sending time without depending on the time when the server returns the packet , By returning the package number to locate the time of the contract , So as to calculate the state information in the process of pressure measurement .

(3) Multi dimensional monitoring

There is some communication between our pressure measuring process and the main process , Information exchange is accomplished through the lockless queue , Including the time-consuming statistics mentioned above 、 The statistics of error codes are completed through the lockless queue .

(4) Protocol extension

In addition, in the area of agreement , We adopt the model of protocol agent factory ,TarsBenchmark The default is Tars Pressure test of the agreement . But if you have some private agreements , You can refer to Tars Protocol implementation , It can also be integrated into , The agent factory can automatically identify new protocols .

(5) Support random data

stay Tars In agreement pressure test ,TarsBenchmark Can support the generation of random data , Random functions are also available , It can effectively avoid replay of the only request in the process of pressure test .

(6) Automatically generate use cases

stay Tars The agreement part , We also provide a tool , To generate automatically Tars Test cases required by the service .TarsBenchmark The test case of the test case is JSON Format , Users just need to edit Value It's easy to initiate a pressure test .

2. Principle of distributed pressure measurement

Distributed pressure testing is mainly to solve the problem of using the platform by many people at the same time . Its main parts consist of four parts .

The first part is WebUI entrance , It's integrated in Tarsweb above , Provides a very simple set of interactions .

The second part is CGI, Mainly do test case management , This includes the database of CRUD operation 、 Control of authority .

Third 、 The four parts are backstage service , Including a pressure test Admin Service and Node service ( Pressure measurement node).Node Service is responsible for performing specific pressure testing tasks , The tool will be destroyed automatically with the system after pressure test , And in distributed pressure testing , It depends on pressure measurement admin To destroy .

To reduce complexity ,TarsBenchmark In the design time uses the multithreading way (linux System scheduling CPU Resources are in threads ). Pressure measurement admin Will accept CGI Instructions , For example, the user is typing QPS Pressure test required for dispatch node when , Because of piezometry node The smallest unit of scheduling is thread , A thread can be set up 3~5 Million output capacity , Then, based on this single thread capability, we calculate the number of threads needed , Finally, assign it to our pressure test node To perform a pressure test inside .

TarsBenchmark These data will be stored in the pressure test temporarily Admin Inside , Pressure measurement Admin The service generally recommends the mode of primary and standby deployment , Distributed pressure test case writing also adopts JSON Format , There is a tool in the background to help users automatically generate demo Use cases . The writing of use cases is also very simple .TarsBenchmark It also provides testing capabilities , It is convenient for users to verify whether the current function is normal during pressure test .

3. Protocol conversion   

We know Tars It's a binary 、 Extensible cross language protocol , It supports C++、PHP、Java and Node, Its essence is TLV The agreement . But the whole pressure test , If the JSON This kind of organization , How to make it binary ? This may be the biggest difficulty in the whole pressure measurement , that TarsBenchmark How to solve this problem ?

Let's first analyze Tars The principle of protocol coding and decoding of ,T contain Tag and Type, In transmission, there are four in front of the binary bit , Show up as a Tag. The next step is to represent the data Type, Tars The agreement can support at most 16 Type of data , It has been compiled to 14 Kind of . This is a Tars It was designed in the beginning , At present, the type of our data is not beyond our encoding , It shows that the design at that time was still forward-looking .

There are seven basic types , There are three more complex types . for instance , Take the very common nesting of two structures as an example , The binary result is shown in the figure above , On the far right is an effect that is finally encoded , First of all, we see that this is B The effect of binary structure coding , From the first 0 Start , That means it's this a One of the variables Tag, We look for a, It's the beginning of the structure , Enter into a The first one after the structure is also 0 ,tag The corresponding is int data , Then there are two bytes of data ,4 Into the 2 The words corresponding to 1、2、3 and 4.

16 We can see 1 It is the bits1, Corresponding s The variable of ,6 It's the real guy who represents it , Its byte length is 4, We can see it's following 616、63 and 64, Correspondence is abcd, then 0p The end represents the end of the structure . The next step is 14, We found that 1 It's for this kind of float data type , then 4 There are four bits The data of , After deserialization, it corresponds to such a structure , It corresponds to the structure in the middle of us .

If we use edit binary to pressure test our Tars, I think most people will collapse , A simple structure can also be written , But when you have many or more than ten members in your structure , Or the structure is nested inside the structure , Most of the development is going to be crazy , Therefore, editing in this way is obviously not advisable .

that TarsBenchmark How does it work ? We will Tars Interface file of , utilize IDL Tools , First of all, the syntax number is generated into a description file , The description file contains three parts :Tag、Type and Name. about Web The platform will be saved to DB Go inside , use RPC Called Tars stay body There's another layer head, It has four key messages : A request id, The service name , The name of the function , And parameter binary body.

In the realization of TarsBenchmark I'm going to check this description file Name, And then through Name get Tag and Type, And then from the use case Value, Re pass Tars The encoding and decoding rules are written into binary system Buffer Inside , It's finally done JSON to Tars This conversion of .

Its converse conversion is actually the same , Let's first restore it from binary to Tars Of Tag and Type, And then we passed Tag In the description file Type and Name, And then through Name and Value Restore JSON The format of , The above is a RPC Call process in the client protocol conversion process .

4. The third party Service Pressure measurement

It is also very simple to adopt a third party agreement , The implementation of four function interfaces can be completed for non Tars Protocol support .

These four function interfaces are initialization interfaces , Packet break interface ( use TCP Stream format for long links , Where do response packets end up , In this input Function in the implementation can be ), Coding interface , Decoding interface .

Implementation of the request encoding interface , There is a very important parameter in this id, Our system generates one for each request id, If this interface supports, you can put id Come back .

With our Tars For example , We are head There's a id Fill in ,RPC The response will come back with the same id,TarsBenchmark Will respond to this request , Calculate the time and success rate of the request . If the third-party service does not support the return sequence number , Need to be in isSupportSeq() return false, It goes into disorder mode , Can't do link reuse .

That's all TarsBenchmark Design principle of .

3、 ... and 、TarsBenchmark Use

1. Code directory structure

Source path : https://github.com/TarsCloud/TarsBenchmark.

Let's look at it first TarsBenchmark Code structure of , It is mainly divided into four parts , The first thing to look at from the bottom up is the tool , service , Common modules and resource files . Focus on the common modules , Mainly 3 part : agreement , Network and monitoring .

  • Protocol support : Two protocols are supported by default , One is HTTP agreement , One is Tars The agreement .
  • monitor : The common data of pressure measurement are stored by the monitor , Lock free queue communication is also implemented here .
  • The Internet : Event driven , Non blocking Socket Pattern design .

2. The code to compile

Compiling is two main parts of code , One is TarsCpp, If there is a need for cloud pressure measurement ,TarsWeb It's also a dependency .

The steps of compiling are also very simple , First clone the code , Create a temporary directory through cmake Finish compiling , You can generate three programs , Namely tb、nodeserver and adminserver. Most of the time, the minimum requirement is just one tool tb, Tools can be executed directly on a single machine , And when you have cloud pressure testing needs , Execute it. install set up script , One click installation to Tarsweb In the middle .

There are mainly several parameters here , One is web Of host,adminserver Recommendations and Tars Basic services are deployed together , Because it doesn't consume too much CPU, however nodeserver Different , Separate deployment is recommended , And it's scalable horizontally .

3. Single tool pressure measurement

For single tool pressure test use , The following parameters can be adjusted according to the actual situation :

  • -c It's the number of pressure test links ,-s It's the biggest qbs The limitation of , If not specified -s Will try to detect the maximum performance of the server to achieve pressure testing ;
  • -D、-P Pressure test the port of the target server , The target server can execute multiple addresses , Distinguish by commas ;
  • -n Parameters : Specify the number of processes for pressure testing .-T Appoint TCP perhaps UDP, Default TCP;
  • -p Parameters : Interface communication protocol , If it's your own private agreement , Can be changed to the name of the private agreement .

In each cycle of pressure measurement , There will be some time-consuming distribution 、 Statistics of success rate 、 Average time-consuming P99 perhaps P90 This kind of statistical information of , It can be printed out periodically , Avoid not knowing the current service during the pressure test process , In addition, the continuous pressure test time can also be passed by -i Parameter to specify .

4. Cloud distributed pressure measurement

Cloud piezometry is very simple to use , stay TarsWeb There is a pressure test entrance in the interface debugging , The use case shows that , These use cases are automatically generated when you add them , When you pressure test , You just need to specify these pressure test targets IP,QPS Pressure test can be initiated anytime, anywhere , And you can see the service performance in the pressure test process .

Four 、TarsBenchmark results

1. development history

We are in 2016 Open source in Tencent in 1995 , At first it was just a tool , There are few supported protocols , Mainly Tars, and Tars Inside it's called taf agreement .

stay 2018 After two years, the number of support agreements has become very rich , The old services can be supported by this tool , At present, it is widely used internally . In addition, it supports the cloud Web Pressure measurement , There are more than a few hundred people using it every week , You don't need to log in to IDC On the machine , It can be launched anytime, anywhere .

This year, 4 We also contributed it to the open source community in January TarsCloud, Small partners for the benefit of the community , You are welcome to give advice .

2. Contrast with the same type

The current response is very good , Compared to some other open source tools , This tool uses c++ Language development , There are two patterns , One is multi process , In other words, the tool adopts the mode of multi process , In the cloud, the thread pool mode is adopted for pressure testing , Support distributed pressure testing , The performance of a single machine is relatively high AB and Wrk There was also a good performance .

most important of all TarsBenchmark Support uniform contracting , Because it's based on the way connections are reused , Return without relying on the request on a continuous send , So we can do the contract at a uniform speed , It also supports the generation of random content . In addition, it also supports on-line pressure measurement , This is also TarsBenchmark A very important highlight of .

That's what we're sharing today , Welcome to participate in ecological contribution . In addition, if there is a demand for our position , You can send your resume directly to my email :linfengchen@tencent.com.

5、 ... and 、Q&A

Q:wrk and TarsBenchmark What's the difference ? How to do pressure test selection ?

A: That's a good question , Just now we said wrk Relatively speaking, it's with our TarsBenchmark The network model is actually the same , It's based on multithreading and network attached mode . however wrk Is pure http Protocol pressure testing tool for ,http Protocols can be understood as disordered patterns , Can't do link reuse , There are some limitations to performance , You can't send it at a uniform rate .

On the other hand ,wrk Mainly a pure HTTP agreement , It doesn't support private protocols , Private agreements are still a little tricky to use , our TarsBenchmark It will perform better in terms of protocol scalability .

Q: We are now TarsBenchmark What's the amount of code ?

A: We're still very lightweight , We calculate that the effective code is about several thousand lines .

I have the impression that 3000 To 4000 Between the lines , It's a very small amount of code , The learning curve is also very gentle , Not too complicated , As long as there are some C++ Language foundation can be used quickly .

Q:TarsBenchmark as well as TarsJMeter The difference between ?

A: Just now when we warmed up the field, we also said , our JMeter It uses the thread mode to simulate users , Execute a user's request response in a thread , This kind of thread scheduling overhead is still very large , Imagine the scale of 10000 threads on a single machine , Thread scheduling depends on the operating system , So like JMeter The performance of the network model will not be very good .

Of course, there are also some people who are interested in this kind of JMeter An extension has been made , because JMeter The biggest application is good scalability , It supports distributed pressure testing , Single machine is not good , It can be distributed to make up for , This is a JMeter A big advantage .

In addition, its reporting is the design idea of plug-ins , It's still quite advanced , For example, we have some data about our results , We can report to others UI Do some presentation on the language , This one is JMeter A big advantage , When we do research on several common pressure testing tools on the market , By combining the strengths of their architectures, we'll end up with our TarsBenchmark.

Sum up ,TarsBenchmark Better single machine performance .

Q: Why not golong Language development

A: This has some background , We started with 2015 To 2016 This product was made in ,Tars The ecology of that time , Within us, we mainly use C++ Mainly ,golong In fact, we have done a lot of low-level ability support in the network , Our endogenous version also has golong The implementation of the , But there is no open source .

Through comparison, we found that C++ The performance will be better than golong The network model is a little better , Mainly reflected in the encoding and decoding of this piece of efficiency will be higher .

Q:Tars Which interfaces are supported ,http Do you support it? ?

A: This is supported by , You use the latest version of Tars You can write your own interface , So our TarsBenchmark In itself, it also supports http Pressure test of the agreement .

Q: Is it to support this kind of kafka Do some pressure testing ?

A:kafka These components basically have their own pressure testing tools , In fact, I personally suggest , You can use some pressure testing tools of its frame components to satisfy , Of course, you are interested in studying our own TarsBenchmark, According to the idea I just said, we can realize three functions 、 Four functions , It can also be done for you kafka A pressure test is extracted .

Q: Why is efficiency so high ? Can it be improved ?

A: Just now in the tool, I also introduced to you , There are mainly four aspects , One is multi process , Give full play to CPU The computational efficiency of . The second aspect is that we adopt this non assembly network model , The third is based on this kind of network link attachment way, avoids the link to be idle there , Fourth, the so-called non blocking communication is adopted .

There is no way to continue to improve ? We've also found that , For example, we are in a complex Tars There are still some problems with the coding and decoding efficiency of the interface , So if there is any improvement , The main idea is to consider the idea of zero copy in encoding and decoding , Our operating system and compression tools try to zero copy buffer operations , Include this binary protocol to Tars For example , We convert it into Tars Try to use more efficient coding and decoding efficiency tools , At present, we are trying to make further improvement .

Q:TarsBenchmark At present, we can see relevant products and solutions on Tencent cloud , Will you go to Tencent cloud in the future ?

A: at present , Mainly in the form of open source to build , Provide in an open source way , There are no plans to go to the cloud at present , If the Tars The ecology of , We can provide free of charge to the majority of users to use , Including businesses and individuals .

Q: It's using C++ 11 Standard design ?

A: This is right , We are adopting C++ 11 The standard to complete . Besides, I also suffer from Tarscloud Official commission , If you're right Tars We pay more attention to , You can pay attention to its official website , Its source code is just in PPT Inside , You can focus on the cloud + The official account of the community can be recovered by online salon . Code structure can be found in our last program , Namely Tarscloud A directory of capabilities and its parameters , You can find the materials you are interested in to learn or try .

Q: Whether big data products can be pressure tested ?

A: What you mean by big data products is idp Piezometry of ? At present, big data like this also has its own set of communication protocols , If you grasp the laws of this protocol , Or you know how some of its protocols are designed , In fact, it can be .

版权声明
本文为[Tencent Yunjia community]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201208105756494y.html