관리 메뉴

피터의 개발이야기

[nGrinder] 간단 실행 방법 본문

DevOps/nGrinder

[nGrinder] 간단 실행 방법

기록하는 백앤드개발자 2022. 6. 2. 02:38
반응형

 

ㅁ 개요

 ㅇ nGrinder 도커 환경 구성 후 간단 실행 과정을 정리하였다.

 

 

ㅁ 간단 실행 방법

 ㅇ google을 테스트 URL로 설정하였다.

 

 

ㅁ 테스트 생성

 ㅇ Test for www.google.com이 생성되었다. 

 

 

ㅁ 테스트 설정

 ㅇ Agent : Agent수, Controller에 연결승인된 수만큼까지만 지정할 수 있다.
 ㅇ 에이전트별 가상사용자 : Agent당 가상 유저수, Process와 Thread로 구성한다.
 ㅇ 스크립트 : 테스트할 스크립트
 ㅇ 테스트 대상 서버 : 테스트 대상 호스트
 ㅇ 테스트 시간 : 테스트할 시간
 ㅇ 실행 횟수 : 테스트 실행 횟수(각 Thread당으로 전체 실행 횟수는 Vuser per agent를 곱한 값이다)
 ㅇ Ramp-Up 사용 : 트래픽을 서서히 증가하게하는 설정

 

 

ㅁ 테스트 실행

 ㅇ 저장 후 시작 버튼 클릭시 테스트가 실행된다. 

 ㅇ 지금 시작 버튼을 클릭하였다.

 

 

ㅁ 결과화면

 ㅇ 총 Vuser, TPS, 최고 TPS, 평균 테스트시간, 총 실행 테스트, 성공한 테스트, 에러, 동작 시간의 지표를 볼 수 있다.

 

ㅁ 상세보고서

 ㅇ 총 Vuser, TPS, 최고 TPS, 평균 테스트시간, 총 실행 테스트, 성공한 테스트, 에러, 동작 시간의 시간대별 그래프 지표를 볼 수 있다.

 

 

ㅁ 테스트 스크립트

import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.plugin.http.HTTPRequest
import net.grinder.plugin.http.HTTPPluginControl
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 java.util.Date
import java.util.List
import java.util.ArrayList

import HTTPClient.Cookie
import HTTPClient.CookieModule
import HTTPClient.HTTPResponse
import HTTPClient.NVPair

/**
 * 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 NVPair[] headers = []
	public static NVPair[] params = []
	public static Cookie[] cookies = []

	@BeforeProcess
	public static void beforeProcess() {
		HTTPPluginControl.getConnectionDefaults().timeout = 6000
		test = new GTest(1, "www.google.com")
		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)
		cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
		grinder.logger.info("before thread. init headers and cookies");
	}

	@Test
	public void test(){
		HTTPResponse result = request.GET("http://www.google.com", params)

		if (result.statusCode == 301 || result.statusCode == 302) {
			grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode); 
		} else {
			assertThat(result.statusCode, is(200));
		}
	}
}

 ㅇ 테스트 스크립트는 자동으로 생성이 되었다.

 

 

ㅁ 함께 보면 좋은 사이트

 o https://github.com/naver/ngrinder/wiki/Quick-Start

 

GitHub - naver/ngrinder: enterprise level performance testing solution

enterprise level performance testing solution. Contribute to naver/ngrinder development by creating an account on GitHub.

github.com

 

반응형

'DevOps > nGrinder' 카테고리의 다른 글

[nGrinder] Docker로 nGrinder 구성 과정 정리  (0) 2021.03.03
Comments