[JAVA] Load test with JMeter

I summarized it because there was no memorandum of addiction and an article that explained from top to bottom unexpectedly.

Purpose

Do a load test with JMeter. 10 accesses per second. Target https://hogehoge.jp/abc With basic authentication nuxt.js, API communication backend Laravel JMeter is done on Mac.

JMeter installation

Install JMeter anyway. Do it with brew. If you don't have brew, install brew.

To use JMeter, you need the main body and Java.

brew install jmeter
brew tap homebrew/cask-versions
brew cask install java

At the time of writing this, java version 14 was installed, but it worked normally.

Run JMeter

Run from the console.

jmeter

This will open the GUI tool. Use this screen to create a test plan (test content).

スクリーンショット 2020-06-10 17.49.17.png

Localizing into Japanese

To make it Japanese, select the following from the menu. Options > ChooseLanguage > Japanese

Creating a test plan

Left column setting

Right-click on "Test Plan" in the left column Add> Threads (Users)> Thread groups Select to create a thread group.

Next, right-click on the "thread group" created above. Add> Sampler> HTTP Request Add> Listener> Statistical Report Add> Listener> View Results in Table Add> Listener> Save Response to File Add> Listener> Graph display Select to create each.

Then it looks like this.

スクリーンショット 2020-06-10 17.57.05.png

Thread group settings

Decide how many times to run the test every few seconds. Number of threads: 10 Ramp-UP period (seconds): 1 Number of loops: 1

To set. The above means that 10 requests will be executed in 1 second.

HTTP request settings

Select the HTTP request in the left column and enter the information.

Setting items Set value
protocol https
Server name or IP hogehoge.jp
HTTP request GET
path /abc

If you have basic authentication

Right click on HTTP request Add> Configuration Element> HTTP Authentication Manager Select and create.

Setting items Set value
Base URL https://hogehoge.jp/
User name Basic authentication username
password Basic authentication password
Mechanism BASIC
スクリーンショット 2020-06-10 18.01.49.png

Save

Select ** TestPlan and press ** Ctrl + s to save. After this, this file will be used, so save it in a convenient location.

test

I will test if it works for the time being. Press the green △ at the top of the GUI to execute. After execution, select "Show results in table" and if Status is green, it is successful.

スクリーンショット 2020-06-10 18.17.04.png

JMeter implementation

Implementation is done with CUI instead of GUI. Execute with the following command.

jmeter -n -t ~/src/jmeter/test_plan.jmx -l ~/src/jmeter/log.jtl
#For the path, set the location of the saved file. Please specify an appropriate location for the log.

Check the log

The contents of the log are like this.

cat ~/src/jmeter/log.jtl
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1591777603078,21372,HTTP request,429,Too Many Requests,Thread group 1-9,text,false,,347449,208,10,10,https://hogehoge.jp/abc,16242,0,238
1591777603178,21915,HTTP request,429,Too Many Requests,Thread group 1-10,text,false,,353217,208,9,9,https://hogehoge.jp/abc,16151,0,220
1591777602975,24513,HTTP request,429,Too Many Requests,Thread group 1-8,text,false,,358302,208,8,8,https://hogehoge.jp/abc,16689,0,211
1591777602877,25325,HTTP request,429,Too Many Requests,Thread group 1-7,text,false,,346781,208,7,7,https://hogehoge.jp/abc,16539,0,175
1591777602578,29420,HTTP request,429,Too Many Requests,Thread group 1-4,text,false,,623792,208,6,6,https://hogehoge.jp/abc,18709,0,308
1591777602353,30684,HTTP request,429,Too Many Requests,Thread group 1-1,text,false,,623792,208,5,5,https://hogehoge.jp/abc,18968,0,533
1591777602676,30529,HTTP request,429,Too Many Requests,Thread group 1-5,text,false,,623792,208,4,4,https://hogehoge.jp/abc,18419,0,210
1591777602378,30834,HTTP request,429,Too Many Requests,Thread group 1-2,text,false,,623792,208,3,3,https://hogehoge.jp/abc,19032,0,508
1591777602776,30459,HTTP request,429,Too Many Requests,Thread group 1-6,text,false,,623792,208,2,2,https://hogehoge.jp/abc,18681,0,168
1591777602477,30900,HTTP request,429,Too Many Requests,Thread group 1-3,text,false,,623792,208,1,1,https://hogehoge.jp/abc,18591,0,409

Gununu ... This is due to the limit on the number of requests for laravel. Let's adjust the number of simultaneous accesses by referring to the articles around here. https://qiita.com/HorikawaTokiya/items/c04e410e4ed76d3dddc2

That's it. Chan-chan.

Recommended Posts

Load test with JMeter
Integration Test with Gradle
[Rails] Test with RSpec
Test Nokogiri with Rspec.
Automatically test with Gauge
Unit test with Junit.
Test Web API with junit
Test Active Strage with RSpec
Remote debugging with Gradle test
Test GraphQL resolver with rspec
test
REST API test with REST Assured Part 2
Test with RSpec + Capybara + selenium + chromedriver
test
Output test coverage with clover + gradle
Download large files with Apache JMeter
test
test
[Java] Test private methods with JUnit
Copy and paste test with RSpec
Test list inclusion relationships with AssertJ
Test Spring framework controller with Junit
Let's unit test with [rails] Rspec!
Set the access load that can be changed graphically with JMeter (Part 1)
MASCHINE test Linear Regression with Multiple Variables
With EqualsVerifier, the equals () test was instant
[Ruby on Rails] View test with RSpec
Control test order in Junit4 with enumeration
Java EE test (CDI / interceptor) with Arquillian
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Model test with RSpec
How to test private scope with JUnit
JUnit 5 gradle test fails with lombok annotation
rails test fails with database reference error
Java automated test implementation with JUnit 5 + Gradle
Form class validation test with Spring Boot