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

AtomicCounter 테스트 #33

Closed
ooMia opened this issue Apr 3, 2024 · 0 comments · Fixed by #32
Closed

AtomicCounter 테스트 #33

ooMia opened this issue Apr 3, 2024 · 0 comments · Fixed by #32
Assignees
Labels
bug Something isn't working

Comments

@ooMia
Copy link
Contributor

ooMia commented Apr 3, 2024

Describe the bug

#32 에 AtomicCounterTest에서 아래 그림처럼 카운트 횟수를 지정하는 totalCount를 Integer.MAX_VALUE로 하면 Out Of Memory가 뜨는 문제가 발생합니다.

image
Caused by: java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.concurrent.AbstractExecutorService.newTaskFor(AbstractExecutorService.java:98)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:122)
	at com.thread.concurrency.AtomicCounterTest.여러_더하기_수행_Executor(AtomicCounterTest.java:37)
	at java.base/java.lang.invoke.LambdaForm$DMH/0x000000a000288800.invokeVirtual(LambdaForm$DMH)
	at java.base/java.lang.invoke.LambdaForm$MH/0x000000a000190800.invoke(LambdaForm$MH)
	at java.base/java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder)

To Reproduce
Steps to reproduce the behavior:

  1. Go to src/test/java/com/thread/concurrency/AtomicCounterTest.java
  2. totalCount를 Integer.MAX_VALUE로 변경
  3. 테스트 실행
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Originally posted by @haxr369 in #32 (comment)

@ooMia ooMia added the bug Something isn't working label Apr 3, 2024
@ooMia ooMia added this to the 스레드 동시성 제어 milestone Apr 3, 2024
@ooMia ooMia linked a pull request Apr 3, 2024 that will close this issue
1 task
ooMia added a commit that referenced this issue Apr 5, 2024
## 개요

- 새롭게 정의한 `ConcurrentBatchCounter` 인터페이스에 대한 구현체

## 변경 사항

- [x] ✨ Feat : `ConcurrentBatchingCounter`
- [x] ✨ Feat : `ConcurrentParameterizedBatchingCounter`

## 추가 정보

- 스레드 별 고유 ID로 분리하여 안정성 확보
#### `ConcurrentParameterizedBatchingCounter`
- 임의의 Integer를 받는 식으로 구현
   - 배열의 크기가 커지면 메모리 이슈 발생
   - 내부 기준에 따라 `flush`하여 해결
#### `ConcurrentBatchingCounter`
- YAGNI 원칙에 의거하여 최적의 구현체 고안
   - LongAdder로 연산 속도 개선
#### 테스트
- Virtual Thread와 OS Thread, 그리고 Sync/Async 각각의 방식으로 시도
   - 두 경우 모두 싱글 스레드 동작이 약 4배 빠름 (평균 10초)
   - OS Thread는 Thread 수에 비례하여 생성 오버헤드 증가
   - Virtual Thread는 수와 관계없이 일정 (평균 40초)

### 관련 이슈
Closes #33
@ooMia ooMia closed this as completed Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants