Skip to content

Refactor/BE/#419: ThemeController에 캐싱 적용 & 크롤러 캐싱 성능 최적화 #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 13, 2023

Conversation

Capoomaru
Copy link
Collaborator

@Capoomaru Capoomaru commented Dec 12, 2023

🤷‍♂️ Description

테마 관련 API들에는 캐싱을 적용해도 문제 없을 것으로 판단되서 수정해요.
크롤러에 캐싱을 최적화해서 성능을 최적화해요.

📝 Primary Commits

  • 테마 관련 API들에 캐싱을 적용해요.

    • 테마 관련 API들에는 캐싱된 결과를 반환해도 문제가 없어요.
    • 현재 캐싱은 요청에 대해 캐싱하고 있어요.(url이 동일하면 캐싱된 결과 반환)
    • 서버의 부하를 줄이고(DB 접근 최소화) UX면에서 불편함을 겪지 않도록 프론트엔드와 협의 끝에 3초간 캐싱처리하기로 결정했어요.
    • 테마 상세정보, 위치기반 테마 리스트 API에는 변환이 필요없을 것으로 생각되어 1분간 캐싱합니다.
  • 시간표 크롤링 API에 대한 캐싱 처리를 최적화 하도록 변경했어요.

    • 기존은 요청 기반으로 캐싱을 처리해요
    • 하지만 프론트엔드에서 당일의 경우 현재시간을 기준으로 요청을 보내요
    • 이로 인해서 동일한 날짜지만 서로 다른 날로 인식되어 캐싱이 적용되지 않아요
    • 이를 해소하고자 날짜가 yyyy-mm-dd 로 변환된 값을 기준으로 키를 사용해요
    • key: { date: 'yyyy-mm-dd', shop: '홍대점', theme: '나를잊어요' }
  • 크롤러 중 지점 내 모든 테마를 조회하는 경우 함께 캐싱해요.

    • 현재 넥스트에디션의 경우 지점 내 모든 테마들에 대한 시간표를 생성한 후 반환해요
    • 이 정보들이 아까워 함께 캐싱하도록 처리했어요.
    • 덕분에 같은 지점에 대한 요청이 있으면 응답 속도가 빨라져요.

📷 Screenshots

넥스트에디션 신림점의 Tester에 대한 요청을 보낸 후 같은 지점의 LOVER에 요청을 보내면 캐싱된 데이터가 반환되는 모습을 볼 수 있음
image

closes #419

- 기본값: 10초
- ThemeController 내부 요청들은 모두 캐싱되도 문제가 없다고 판단됨
- 기본값: 3초
- Location, Details 의 경우 1분으로 처리
@Capoomaru Capoomaru requested a review from JEM1224 December 12, 2023 10:23
@Capoomaru Capoomaru self-assigned this Dec 12, 2023
- MySQL의 DB 조회 과정이 추가되는 오버헤드가 필요함
- 대신 시간 값이 다르고 날짜만 같아도 캐싱됨(당일 데이터에 한해서 성능 향상)
- NextEdition의 경우 크롤링하는 지점 내 모든 테마들의 timetable을 가져올 수 있음 -> 이를 캐싱해둬서 성능 최적화 진행
- 추후 가능한 모든 사이트들을 이와 같은 구조로 캐싱하도록 처리
@Capoomaru Capoomaru changed the title Refactor/BE/#419: ThemeController에 캐싱 적용 Refactor/BE/#419: ThemeController에 캐싱 적용 & 크롤러 캐싱 성능 최적화 Dec 12, 2023
@Capoomaru Capoomaru marked this pull request as ready for review December 12, 2023 19:12
@Capoomaru Capoomaru added this to the 성능최적화 milestone Dec 13, 2023
Copy link
Collaborator

@JEM1224 JEM1224 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

캐싱 고수시네요..!!👍👍👍👍 배우고갑니다~~

@Capoomaru Capoomaru merged commit 58af359 into dev Dec 13, 2023
@Capoomaru Capoomaru deleted the Refactor/BE/#419 branch December 13, 2023 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] 캐싱 적용 범위 수정
2 participants