Skip to content
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

api : /velog-stats Response Time, too long #1

Open
60jong opened this issue Feb 15, 2023 · 4 comments
Open

api : /velog-stats Response Time, too long #1

60jong opened this issue Feb 15, 2023 · 4 comments
Labels
question Further information is requested

Comments

@60jong
Copy link
Owner

60jong commented Feb 15, 2023

api : /velog-stats 응답 시간이 너무 길어 (보통 4초 이상) github에서 이미지를 불러오다가 error fetching resource 발생

  • GitHub README에 이미지 생성 api(/velog-stats) 로 이미지 생성 요청

  • GitHub에서는 camo를 활용해 이미지 프록시를 제공함.

    • GitHub서버에서는 이미지 프록시를 위해 entire 이미지가 필요)
    • 이미지 load에 time-limit이 존재함
    • 내 서버는 time limit을 초과함

스크린샷 2023-04-16 143348

@60jong 60jong added the question Further information is requested label Feb 15, 2023
@60jong
Copy link
Owner Author

60jong commented Feb 15, 2023

1st Solution

내 서버에 statsView 이미지가 존재 X

  • 이미지 생성 후, 이미지 리턴

내 서버에 statsView 이미지가 존재 O

  • 이미지 리턴 후, 이미지 삭제

Flow

  • 처음 api 호출 시에, 내 서버에 이미지 존재 X -> 이미지 생성 후, 리턴하는 도중에 GitHub time-limit으로 이미지 프록시 X

  • 이젠 내 서버에 이미지가 존재하기에, GitHub에서 api 호출 시에, 이미지 바로 리턴 가능

  • 추후 이미지의 업데이트를 위해, 이미지 리턴 후 삭제

@60jong
Copy link
Owner Author

60jong commented Feb 15, 2023

2nd Solution

내 서버의 응답 시간을 줄이는 방식을 찾아야 함.

@60jong
Copy link
Owner Author

60jong commented Mar 17, 2023

3nd Solution

  • 찾은 문제 상황
    게시글의 조회수를 검색하기 위해서는 postId 하나마다 검색을 해야하는데, 모든 postId에 대해 하나씩 요청하니 overhead가 너무 많이 발생!!

따라서 조회수를 조회하는 query를 묶어서 한 번에 요청하는 GraphQL Batching을 활용

  • 시행착오 결과, velog의 GraphQL Batching max size는 32

Batching 이전

스크린샷 2023-04-16 143348

Batching 이후

스크린샷 2023-04-16 140620

7,930ms -> 565ms 로 약 14배의 성능 향상

@60jong
Copy link
Owner Author

60jong commented Dec 27, 2023

# 1개의 query씩 요청

finding all post id : 163 ms
finding total visitors : 4100 ms

# 32-batch query 요청 
finding all post id : 191 ms
finding total visitors : 519 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant