비전공자도 이해할 수 있는 Redis 입문/실전
performance-comparison-before-after-redis-nestjs
✅ Redis를 적용했을 때의 성능 측정
# 스프링 프로젝트 경로로 들어가서 아래 명령어 실행
$ ./gradlew clean build -x test
$ cd build/libs
$ java -jar -Dspring.profiles.active=prod {빌드된 jar 파일명}
여러 번 요청을 보내보니 평균적으로 20ms 정도의 속도가 나오는 걸 확인할 수 있다.
✅ Redis를 적용하지 않았을 때의 성능 측정
BoardService
@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();
}
}
캐싱을 적용시키는 어노테이션을 주석 처리한 뒤 Postman으로 테스트를 해보자.
# 스프링 프로젝트 경로로 들어가서 아래 명령어 실행
$ ./gradlew clean build -x test
$ cd build/libs
$ java -jar -Dspring.profiles.active=prod {빌드된 jar 파일명}
여러 번 요청을 보내보니 평균적으로 500ms 정도의 속도가 나오는 걸 확인할 수 있다. 레디스를 적용하지 않으니 확연하게 성능이 느려진 걸 확인할 수 있다.