nGrinder는 네이버에서 개발한 Enterpise 레벨 Java기반 성능 테스트 도구입니다.
Agent가 반드시 필요하며, Controller는 이를 조종하는 역할을 합니다. 분산 테스트/Web UI/Multi Tenancy 지원하고 Groovy/Jyshon으로 테스트 스크립트를 작성할 수 있습니다.
장점으로는 트랜잭션을 자유롭게 정의할 수 있으며(여러 요청을 하나의 Test로 묶을 수 있음) 스크립트 버전을 관리할 수 있고 실행한 테스트의 결과 또한 자동으로 저장 및 관리할 수 있습니다.
아키텍처는 아래와 같습니다.
이제 설치를 해봅시다.
# NGrinder 다운로드
wget https://github.com/naver/ngrinder/releases/download/ngrinder-3.5.9-20230227/ngrinder-controller-3.5.9.war
# JAVA11로만 실행 가능
java -Djava.io.tmpdir=/Users/heojeonghwa/ngrinder/lib -jar ngrinder-controller-3.5.9.war --port 7070
/Users/heojeonghwa/ngrinder = ngrinder-controller.war 파일이 존재하는 디렉토리
localhost:7070에 접속하여 초기 ID/Password(admin/admin
)를 입력합니다.
Agent를 다운받아 압축을 출어주고 cmd 창으로 접근하여 agent를 실행해 줍니다.
# Agent쉘스크립트 파일 실행
./run_agent.sh
# Agent 백그라운드 실행
./run_agent_bg.sh
4. Controller 화면으로 돌아가서 Agent Management를 확인합니다.
Agent가 잘 실행되고 있는지 확인할 수 있습니다.
만약 에러가 나면서 Script탭이 열리지 않는다면 Controller 및 Agent를 내린 후 .nGrinder 폴더 삭제 후 다시 기동이 필요합니다.
sudo rm -r .ngrinder
import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
// import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.ngrinder.http.HTTPRequest
import org.ngrinder.http.HTTPRequestControl
import org.ngrinder.http.HTTPResponse
import org.ngrinder.http.cookie.Cookie
import org.ngrinder.http.cookie.CookieManager
/**
* A simple example using the HTTP plugin that shows the retrieval of a single page via HTTP.
*
* This script is automatically generated by ngrinder.
*
* @author admin
*/
@RunWith(GrinderRunner)
class TestRunner {
public static GTest test
public static HTTPRequest request
public static Map<String, String> headers = [:]
public static Map<String, Object> params = [:]
public static List<Cookie> cookies = []
@BeforeProcess
public static void beforeProcess() {
HTTPRequestControl.setConnectionTimeout(300000)
test = new GTest(1, "101.101.217.190")
request = new HTTPRequest()
grinder.logger.info("before process.")
}
@BeforeThread
public void beforeThread() {
test.record(this, "test")
grinder.statistics.delayReports = true
grinder.logger.info("before thread.")
}
@Before
public void before() {
request.setHeaders(headers)
CookieManager.addCookies(cookies)
grinder.logger.info("before. init headers and cookies")
}
@Test
public void test() {
HTTPResponse response = request.GET("http://101.101.217.190:8080/api/v1/spaces", params)
if (response.statusCode == 301 || response.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
} else {
assertThat(response.statusCode, is(200))
}
}
}
test.record(this, "test")
안에 "test"는 (@Test가 붙은)테스트 메서드 이름을 가리킵니다. Tests Errors Mean Test Test Time TPS Mean Response Response Mean time to Mean time to Mean time to
Time (ms) Standard response bytes per errors resolve host establish first byte
Deviation length second connection
(ms)
Test 1 1 0 1691.00 0.00 0.59 315.00 185.19 0 0.00 17.00 1650.00 "101.101.217.190"
Totals 1 0 1691.00 0.00 0.59 315.00 185.19 0 0.00 17.00 1650.00
각 항목에 대해서 설명하자면 아래와 같습니다.
평균적인 TPS(초당 처리할 수 있는 트랜잭션 수)와 Mean Test Time(평균 테스트 시간)을 볼 수 있습니다.
또한 Logs를 클릭하면 로그파일을 조회하거나 다운로드도 가능합니다.
더 자세한 레포트가 보고싶다면 Detailed Report를 통해 조회 가능합니다.