-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor/#34 주차장 데이터 삽입 성능개선 및 외부 api 장애 발생시 처리 로직 추가 #86
The head ref may contain hidden characters: "Refactor/#34_\uC8FC\uCC28\uC7A5_\uB370\uC774\uD130_\uC0BD\uC785_\uC131\uB2A5\uAC1C\uC120"
Conversation
…삽입_성능개선 # Conflicts: # app-scheduler/src/main/java/com/parkingcomestrue/external/scheduler/ParkingUpdateScheduler.java # app-scheduler/src/test/java/com/parkingcomestrue/external/scheduler/ParkingUpdateSchedulerTest.java
Test Results135 tests 135 ✅ 14s ⏱️ Results for commit 879a941. ♻️ This comment has been updated with latest results. |
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.
건호형 고생하셨습니당!_!
private final double MIN_TOTAL_COUNT; | ||
|
||
private double totalCount; | ||
private double errorCount; | ||
private boolean isClosed; |
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.
double
인 이유가 있을까요? 정수형 같아보여서용!
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.
그렇네여.. 수정했습니다!
public synchronized void countUp() { | ||
totalCount++; | ||
} | ||
|
||
public synchronized void errorCountUp() { | ||
totalCount++; | ||
errorCount++; | ||
} |
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.
synchronized
keyword vs AtomicInteger
어떤 차이가 있고 성능적으로 차이가 날까요?
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.
서버 한대 상황에서 synchronized
를 사용하면 간단할거 같아서 이렇게 적용했는데
찾아보니 AtomicInteger
를 사용하면 락 없이도 여러 스레드에서 사용할 수 있네요!
AtomicInteger
로 수정했습니다~!
public class AsyncApiExecutor { | ||
|
||
private static final ExecutorService executorService = Executors.newFixedThreadPool(100, (Runnable r) -> { | ||
Thread thread = new Thread(r); | ||
thread.setDaemon(true); | ||
return thread; | ||
} | ||
); | ||
|
||
public static <U> CompletableFuture<U> executeAsync(Supplier<U> supplier) { | ||
return CompletableFuture.supplyAsync(supplier::get, executorService); | ||
} | ||
} |
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.
해당 부분 configuration
으로 정의하고 bean
으로 써도 되지 않을까요?
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.
좋습니다~!
public void saveAllWithBulk(List<Parking> parkingLots) { | ||
String sql = "INSERT INTO parking " | ||
+ "(base_fee, base_time_unit, extra_fee, extra_time_unit, day_maximum_fee, " | ||
+ "capacity, current_parking, " | ||
+ "holiday_begin_time, holiday_end_time, holiday_free_begin_time, holiday_free_end_time, " | ||
+ "saturday_begin_time, saturday_end_time, saturday_free_begin_time, saturday_free_end_time, " | ||
+ "weekday_begin_time, weekday_end_time, weekday_free_begin_time, weekday_free_end_time, " | ||
+ "created_at, updated_at, " | ||
+ "address, name, tel, operation_type, parking_type, pay_types, location) " | ||
+ "VALUES " | ||
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ST_GeomFromText(?))"; | ||
|
||
jdbcTemplate.batchUpdate( | ||
sql, | ||
parkingLots, | ||
parkingLots.size(), | ||
PARKING_PARAMETERIZED_PREPARED_STATEMENT_SETTER | ||
); |
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.
굿 이네요 이런식으로 많이 배치인서트 하는 것 같아요
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.
근데 이렇게 하면 문자열이 문자열 풀에 넣어서 쓸때 마다 가져다 쓰나요? 아니면 항상 힙에 새로 할당하나요 ?
- 연산이 들어가 있어서 궁금하네요.
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.
- 이어지는것들이 새로운 String 변수로 만들어진다고 해도 처음 생성된 다음에는 다 풀에서 가져올거같은 느낌적인 느낌이 드는데요
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.
전체 다 합쳐진 sql은 풀에 들어가서 새로 생성하진 않네유
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.
고생하셨슴다~
this.totalCount = 0; | ||
this.errorCount = 0; | ||
this.isClosed = false; | ||
} |
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.
얘네는 private double totalCount = 0;
이렇게 선언해도 무방할듯하네요. 이렇게 가도 좋습니다~
public boolean isErrorRateOverThan(double errorRate) { | ||
if (totalCount < MIN_TOTAL_COUNT) { | ||
return false; | ||
} | ||
double currentErrorRate = errorCount / totalCount; | ||
return currentErrorRate >= errorRate; | ||
} |
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.
요 부분에서 사용하는 totalCount 를 다른 메서드에서 조작하기 때문에 syncronized 하게 실행해도 괜찮을거같네요.
예를 들어, if 문을 통과하고 return false;
를 하기 전에 다른 스레드에서 countUp 을 호출하는 경우??
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.
해당 케이스를 생각 못했네유..
synchronized
키워드 대신 AtomicInteger
이점이 많은 거 같아서 요걸로 수정했습니다.
errorCount++; | ||
} | ||
|
||
public void reset() { |
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.
요게 서킷 open 하는 역할인가요??
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.
넴 초기(정상) 상태로 돌리는 용도입니다
@Around("@annotation(annotation)") | ||
public Object around(ProceedingJoinPoint proceedingJoinPoint, CircuitBreaker annotation) { | ||
ApiCounter apiCounter = getApiCounter(proceedingJoinPoint, annotation.minTotalCount()); | ||
if (apiCounter.isClosed()) { |
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.
제가 알기론 close 가 정상상태로 알고 있습니다. 그래서 isOpen() 이 일반적인 서킷브레이커 패턴에서 사용하는 네이밍일거같슴다
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.
오홍 그렇네요! 수정했습니다~
- close 대신 open 이라는 네이밍으로 변경
👍관련 이슈
🤔세부 내용
🫵리뷰 중점사항