@Service public class BoardService { ... // @Cacheable(cacheNames = "getBoards", key = "'boards:page:' + #page + ':size:' + #size", cacheManager = "boardCacheManager") public List<Board> getBoards(int page, int size) { Pageable pageable = PageRequest.of(page - 1, size); Page<Board> pageOfBoards = boardRepository.findAllByOrderByCreatedAtDesc(pageable); return pageOfBoards.getContent(); } }
# 스프링 프로젝트 경로로 들어가서 아래 명령어 실행 $ ./gradlew clean build -x test # 정확한 테스트를 위해 Spring Boot 서버를 백그라운드에서 실행시키자. $ cd build/libs $ nohup java -jar -Dspring.profiles.active=prod {빌드된 jar 파일명} & # 8080번 포트에 Spring Boot 서버가 잘 실행되고 있는 지 확인 $ lsof -i:8080
더 정확한 성능 측정 방법이 있지만 성능 테스트에 초점을 맞춘 강의가 아니기 때문에 간편한 방법으로 측정하고자 한다.
# K6의 스크립트 파일이 위치한 경로에서 아래 명령어 실행시키기 $ k6 run --vus 30 --duration 10s script.js
--vus 30 : 가상 유저(Virtual Users)를 30명으로 셋팅
(API 요청을 보내는 사용자가 30명인 것처럼 부하 생성)--duration 30s : 30초 동안 테스트를 유지
@Service public class BoardService { ... @Cacheable(cacheNames = "getBoards", key = "'boards:page:' + #page + ':size:' + #size", cacheManager = "boardCacheManager") public List<Board> getBoards(int page, int size) { Pageable pageable = PageRequest.of(page - 1, size); Page<Board> pageOfBoards = boardRepository.findAllByOrderByCreatedAtDesc(pageable); return pageOfBoards.getContent(); } }
# 스프링 프로젝트 경로로 들어가서 아래 명령어 실행 $ ./gradlew clean build -x test # 기존 서버 종료 $ lsof -i:8080 $ kill {PID 값} # 정확한 테스트를 위해 Spring Boot 서버를 백그라운드에서 실행시키자. $ cd build/libs $ nohup java -jar -Dspring.profiles.active=prod {빌드된 jar 파일명} & # 8080번 포트에 Spring Boot 서버가 잘 실행되고 있는 지 확인 $ lsof -i:8080
$ k6 run --vus 30 --duration 10s script.js
