-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
13-6 [BE] [Fix] Request batcher 로직 수정 #89
Conversation
sort할 경우 요청 당 너무 많은 시간이 소요된다.
http timeout 60초로 변경(crossref가 결과를 주기까지 꽤 오랜 시간이 걸림, 재요청했을 때 빠를 것임을 기대할 수 없음), keyword set과 queue에 push하는 로직을 분리(doi도 keyword로 취급하는 중)
too many request가 너무 자주 발생 -> batch 단위 절반으로 수정, 428 발생시, RESTART_INTERVAL 만큼 batch 중지
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 이해한 것이 맞다면 현재 setInterval을 통해 runBatch를 주기적으로 실행하고, Batcher라는 클래스에 내부적으로 blocked와 실행 여부를 변수로 관리하는 듯 합니다.
이를 통해 실행할 때마다 blocked와 running 여부를 체크 하고 실행을 하는 것으로 보입니다.
(blocked와 running 이 true이면 return)
이는 큐에서 전의 요청이 정상적으로 response를 받고 Too Many Request를 피하기 위한 방법으로 이해를 했는데
blocked와 running 여부를 매번 확인하는 것이 아니라 그냥 외부 api를 요청하고 await 후 response를 받은 후에 해당 response의 유효성을 검증하는 방식을 적용할 수 없나요?
리뷰 요청 사항
일반적인 DB라면 N+1 문제에 해당한다고 생각합니다.
그러나 엘라스틱서치에서는 해당하는지는 좀 더 학습이 필요하다 생각되네요
inverted index의 특징을 생각하면 apple이라는 키워드로 단순히 get 요청을 했을때는 apple이 들어간 데이터의 인덱스를 모두 가지고 있으니, N+1의 문제가 발생하지 않지만,
한 논문에 대한 ref목록의 doi 들로 get 요청을 하면 n개의 doi 키워드로 검색을 하면 당연히 n번의 get요청이 들어갈 것이라 생각합니다.
=> N+1이 발생하겠네요
하지만 elasticsearch의 multi math query를 사용하면 성능이 향상된다는 글이 있네요.
https://stackoverflow.com/questions/62318268/multi-match-query-and-the-scoring-calculation-in-elasticsearch
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
this.doiBatcher.pushToQueue(0, v.depth + 1, -1, false, v.doi); | ||
}); | ||
batchSearchQueue(batchSize = SEARCH_BATCH_SIZE) { | ||
this.searchBatcher.runBatch(batchSize); | ||
} | ||
|
||
@Interval(TIME_INTERVAL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분의 경우 없어도 Interval 이 정상 작동하긴 했었는데, 이렇게 명시하는 이유가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 batchSearchQueue
가 있는 이유를 물어보신걸까요??
가끔씩 crossref가 응답을 빠르게 해주는 경우가 있어서요, 이 친구가 빠른 속도로 응답해버릴 때, 응답이 올 때마다 다음 요청을 보내는 식으로 하면 rate limit이 걸릴 수 있겠더라구요. (ex doi로 검색할 때) |
개요
작업사항
Dockerfile
BE / FE 수정 (npm i -> npm ci) [CI/CD] BE 이미지 Docker build시 Fail 하는 현상 #87TIME_INTERVAL
을 3초에서 1초로 줄이고, batch 한 단위가 끝나야만 다음 batch를 실행할 수 있도록 함RESTART_INTERVAL
만큼 요청을 보내지 않음 (Batcher 내부에 block 변수를 static하게 선언)/search/stat
에서 서버의 batch queue 상태와, elasticsearch db 상태를 확인할 수 있음 (debug 용)리뷰 요청사항