Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
preface
Sometimes during testing or debugging, you need to know your interface performance.
For the choice of a performance test tool, it is optional but must be lightweight, so I recommend Siege
Siege Installation Procedure
$wget < http://download.joedog.org/siege/siege-latest.tar.gz > $tar ZXF siege - latest. Tar. Gz $CD siege - 4.0.2 / $ ./configure $ sudo make $ sudo make installCopy the code
Check whether the installation is successful
Check the installation path of $which siege /usr/local/bin/siege Check the version of $siege -v siege 4.0.2Copy the code
Example of siege commands
10 concurrent url&Method & Parameters interface send requests for 10 minutes, start debugging mode, no interval time, XX logs are written to XX directory
siege --debug -c10 -t10M '<http://mapp.xxxxx.com/api/product/list> POST SystemVersion = 6.0 & deviceId = 864361034921867 & deviceToken = 9 cab8a947832db553951ea716c417eab & source = android&appVersion = 3.0.3 & T = 1495179270635 & pageIndex = 1 & pageSize = 20 & regChannel = app&resolution = 1080 * 1812 & deviceModel = EVA - AL00 & density = 3.0 & ' >>/data/siegelogs/siege2017051917.log
10 concurrent URl&Method & Parameters send requests 20 times, debug mode is opened, no interval time, XX logs are written to XX directory
siege -c10 -r20 '<http://mapp.xxxxx.com/api/product/list> POST SystemVersion = 6.0 & deviceId = 864361034921867 & deviceToken = 9 cab8a947832db553951ea716c417eab & source = android&appVersion = 3.0.3 & T = 1495179270635 & pageIndex = 1 & pageSize = 20 & regChannel = app&resolution = 1080 * 1812 & deviceModel = EVA - AL00 & density = 3.0 & ' >>/data/siegelogs/siege201705191750.log
Simulate the same user to submit 10 purchase requests repeatedly
Siege ‘interface address POST Specific input parameter’ -r 1 -c 10
siege 'https://mapp.xiaoniuapp.com/api/product/buyProduct.do POST parameters' -r 1 -c 10
Create a test_urls file first, write the request information to the test_urls file request URL¶meters1 (defect, The login user name needs to be parameterized) URL¶meters2 URL¶meters3Copy the code
Specific commands are as follows:
siege --debug -r 2 -c 1 -b -f /data/siegefiles/test_urls -b >>/data/siegelogs/siege201705221136.log
The same user concurrently submits multiple interfaces
Prepare the interface test file -bingfa, for example, the same user buys the current treasure at the same time redeem the current treasure, test whether there is data error
- The specific commands are as follows
siege --debug -r 1 -c 2 -b -f /data/siegefiles/bingfa -b >>/data/siegelogs/siege201705221136.log
conclusion
From installation to use, what’s the end result? Can not be blindly only use, more to understand the key, such as results analysis. Are there a lot of question marks about the output? And the author sorted it out for you.
The results of the stress test include the following:
Transactions Elapsed time Used to be transferred Data Response time Concurrency is the setting of the maximum number of Concurrency clients. Transaction rate Throughput HTTP OK received: indicates the number of successful packets. Failed transactions: indicates the number of Failed transactions. Shortest Transaction: indicates the Shortest response timeCopy the code