ES 검색기능을 구현 후, 성능 테스트를 해봤다.
먼저 TimeConfiguration을 빈드로 수동 등록해줘야 했다:
@Configuration
public class TimerConfiguration {
@Bean
public TimedAspect timedAspect(MeterRegistry meterRegistry) {
return new TimedAspect(meterRegistry);
}
}
ContentController:
@Timed("search.sql")
@GetMapping("/test/sql")
public CursorResponseContentDto findContentsRepository(@Valid @ModelAttribute ContentSearchRequest request) {
log.info("[콘텐츠 목록 조회 요청] contentRepository - request={}", request);
CursorResponseContentDto response = contentService.findContents(request);
log.info("[콘텐츠 목록 조회 응답] contentRepository - resultCount={}",
response.data() != null ? response.data().size() : 0);
return response;
}
@Timed("search.request")
@GetMapping("/test/es")
public CursorResponseContentDto findContentsEsRepository(@Valid @ModelAttribute ContentSearchRequest request) {
log.info("[콘텐츠 목록 조회 요청] contentEsRepository - request={}", request);
CursorResponseContentDto response = contentService.findContentsEsRepository(request);
log.info("[콘텐츠 목록 조회 응답] contentEsRepository - resultCount={}",
response.data() != null ? response.data().size() : 0);
return response;
}
테스트용 컨트롤러 엔드포인트 2개를 만들었다. 하나는 sql db를 조회하고, 하나는 es db를 조회한다.
테스트 환경이었는데, ddl-auto: update로 해놔서 데이터를 새로 불러올 필요가 없었고, sql db와 es db는 동기화를 마친 상태였다.
마지막으로 actuator에 metrics를 추가했다
management:
endpoints:
web:
exposure:
include: health, info, metrics, prometheus
endpoint:
health:
show-details: always
테스트를 해야하므로 Postman으로 각 엔드포인트에 리퀘스트를 3번 보내봤다:
http://localhost:8080/api/contents/test/sql?keywordLike=안녕&limit=10&sortBy=createdAt&sortDirection=DESCENDING
http://localhost:8080/api/contents/test/es?keywordLike=안녕&limit=10&sortBy=createdAt&sortDirection=DESCENDING
SQL (http://localhost:8080/actuator/metrics/search.sql)

ES (http://localhost:8080/actuator/metrics/search.request)

총 3번 리퀘스트를 각 엔드포인트로 보냈는데, 평균 시간을 계산해보면
- SQL: 평균 = TOTAL_TIME / COUNT = 1.841346299/3 = 0.61378209966 초 (613 ms)
- ES: 평균 = TOTAL_TIME / COUNT = 0.529007001/3 = 0.176335667 초 (176 ms)
3개의 리퀘스트 기준으로 보니까 ES가 약 3.5배 정도 빠르다는 것을 확인했다!
'Codeit > 프로젝트' 카테고리의 다른 글
| [모두의 플리] watcherCount를 Redis로 리팩토링 (0) | 2025.12.23 |
|---|---|
| [모두의 플리] 트러블슈팅 - 실시간 시청 세션 동기화와 Race condition (0) | 2025.12.02 |
| Elastisearch 토이 프로젝트 만들어보기 (프로젝트를 위한 준비..) (0) | 2025.11.27 |
| [모두의 플리] 고도화 - redis를 이용한 분산환경 고려 (pub/sub) (0) | 2025.11.26 |
| [모두의 플리] 트러블 슈팅 - 웹소켓 환경에서 유저 정보 가져오기 (0) | 2025.11.26 |