부트모아 사이트의 부하를 테스트 해보고 테스트 바탕으로 성능 개선을 하고자 nGrinder를 사용해 보기로 하였다.
https://github.com/naver/ngrinder/releases
Releases · naver/ngrinder
enterprise level performance testing solution. Contribute to naver/ngrinder development by creating an account on GitHub.
github.com
최신 버전의 controller를 다운 받고
java -jar ngrinder-controller-{version}.war --port=8300
실행시켜 주었다.
그 다음, localhost:8300으로 접속해
초기 id, password 인 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, "Test1")
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://127.0.0.1:8080/articles", 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))
}
}
}
sample script를 약간 변형해 내 프로젝트에 요청하였더니 테스트가 진행 되었다.
'부트모아' 카테고리의 다른 글
[V2] JPA는 sql injection에 무조건 안전한가? (0) | 2024.09.28 |
---|---|
[V2] 부트모아 사이트 XSS 필터링 (1) | 2024.09.28 |
[V2] Spring Security CSRF (1) | 2024.09.28 |
[V2] Vault를 사용한 보안 강화 (1) | 2024.09.28 |
[V3] 캐싱을 통한 쿼리 줄이기 (2) | 2024.09.28 |