-
Notifications
You must be signed in to change notification settings - Fork 0
자동매매 성능 개선 #27
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
자동매매 성능 개선 #27
Conversation
… feat/#23-enhance-auto-trading
* feat: Redisson 라이브러리를 활용하여 분산락 적용 * refactor: 양방향 연관관계 제거
* feat: 이벤트 기반 병렬 처리로 개선 및 스레드풀 커넥션풀 튜닝
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.
Pull Request Overview
Enhances the auto-trading module’s throughput and reliability by replacing DB locks with Redis‐based distributed locks, introducing event-driven order processing, and tuning async/threadpool configurations.
- Replace pessimistic “FOR UPDATE” locks with a custom
@DistributedLockmechanism - Publish auto-trade operations as async Spring events instead of inline try/catch loops
- Tune thread-pool sizes and add Prometheus/Grafana monitoring integrations
Reviewed Changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/tradin/module/users/account/implement/AccountProcessor.java | Simplify account + USDT balance creation flow |
| src/main/java/com/tradin/module/users/account/domain/Account.java | Remove old balance/subscription/position collections |
| src/main/java/com/tradin/module/strategy/subscription/service/SubscriptionService.java | Drop DB-level “for update” lock in validation |
| src/main/java/com/tradin/module/strategy/subscription/implement/SubscriptionProcessor.java | Remove direct account–subscription link |
| src/main/java/com/tradin/module/strategy/subscription/domain/repository/impl/SubscriptionQueryRepositoryImpl.java | Refactor subscription lookup query |
| src/main/java/com/tradin/module/strategy/strategy/service/StrategyService.java | Add same-position guard and event publishing |
| src/main/java/com/tradin/module/futures/position/implement/FuturesPositionReader.java | Rename query method, remove pessimistic lock |
| src/main/java/com/tradin/module/futures/position/implement/FuturesPositionProcessor.java | Drop unused entity associations, inject EM |
| src/main/java/com/tradin/module/futures/position/domain/repository/impl/FuturesPositionQueryRepositoryImpl.java | Rename method, remove lock-mode usage |
| src/main/java/com/tradin/module/futures/position/domain/FuturesPositionQueryRepository.java | Update interface to match new method |
| src/main/java/com/tradin/module/futures/order/implement/FuturesOrderProcessor.java | Introduce @DistributedLock on order APIs |
| src/main/java/com/tradin/module/futures/order/event/AutoTradeEventHandler.java | New async handler for AutoTradeEvent |
| src/main/java/com/tradin/module/futures/order/event/AutoTradeEvent.java | Define application event payload |
| src/main/java/com/tradin/common/utils/CustomSpringELParser.java | Utility for evaluating SpEL in lock keys |
| src/main/java/com/tradin/common/exception/ExceptionType.java | Add lock‐related and same-position exceptions |
| src/main/java/com/tradin/common/config/RedissonConfiguration.java | Bean for RedissonClient using application props |
| src/main/java/com/tradin/common/config/AsyncConfiguration.java | Define tradeExecutor thread-pool bean |
| src/main/java/com/tradin/common/aop/DistributedLockAop.java | Aspect for @DistributedLock support |
| src/main/java/com/tradin/common/aop/AopForTransaction.java | Wraps joinpoints in new transactions |
| src/main/java/com/tradin/common/annotation/DistributedLock.java | Annotation definition for distributed lock |
Comments suppressed due to low confidence (1)
src/main/java/com/tradin/module/strategy/subscription/service/SubscriptionService.java:124
- [nitpick] By removing the DB-level pessimistic lock (
forUpdate) here, this check can race under high concurrency. Consider applying a transactional lock or the same distributed-lock mechanism to prevent duplicate subscriptions.
futuresPositionReader.findOpenFuturesPositionByAccountAndCoinType(accountId, coinType)
| * 1. 기존 포지션 조회 (신규 주문인 경우 SKIP) 2. 반대 매매 주문 3. 포지션 청산 (시장가) 4. USDT 수익 정산 | ||
| * 기존 포지션 정리 - 1. 기존 포지션 조회 (신규 주문인 경우 SKIP) 2. 반대 매매 주문 3. 포지션 청산 (시장가) 4. USDT 수익 정산 | ||
| */ | ||
| @DistributedLock( |
Copilot
AI
May 17, 2025
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.
The closeExistPosition method is annotated with fallbackMethod = "handleLockFailure", but its signature only takes (Strategy, Account) while handleLockFailure expects (Strategy, Account, Position). This mismatch will cause the fallback to not be found at runtime; adjust the fallback signature or define a separate fallback for closeExistPosition.
|
|
||
| private final FuturesOrderProcessor futuresOrderProcessor; | ||
|
|
||
| @Async |
Copilot
AI
May 17, 2025
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.
The @Async annotation uses the default executor. To leverage the configured tradeExecutor pool and avoid unbounded thread creation, specify @Async("tradeExecutor").
| @Async | |
| @Async("tradeExecutor") |
| private final EntityManager entityManager; | ||
|
|
Copilot
AI
May 17, 2025
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.
The EntityManager field is injected but never used in this class. Consider removing the field and its import to clean up unused dependencies.
| private final EntityManager entityManager; |
| executor.setMaxPoolSize(30); //최대 쓰레드 풀 사이즈 | ||
| executor.setQueueCapacity(50); //쓰레드가 모두 사용중인 경우 큐에 쌓여있는 요청의 최대 갯수 | ||
| executor.setThreadNamePrefix("TRADIN-ASYNC-"); //쓰레드 이름 접두사 | ||
| executor.setCorePoolSize(16); |
Copilot
AI
May 17, 2025
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.
The tradeExecutor bean only sets corePoolSize and threadNamePrefix. It’s recommended to also configure maxPoolSize and queueCapacity to prevent potential queue backlogs or thread saturation.
| executor.setCorePoolSize(16); | |
| executor.setCorePoolSize(16); | |
| executor.setMaxPoolSize(32); // Allow the pool to grow under high load | |
| executor.setQueueCapacity(100); // Limit the task queue size |
변경사항
상세내용
연관 이슈