Skip to content

Commit 3cdaa5f

Browse files
committed
[IDLE-000] Jitter 제거 및 지수 백오프로 롤백
1 parent da8b638 commit 3cdaa5f

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

core/data/src/main/java/com/idle/data/repository/ChatRepositoryImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.idle.network.model.chat.ReadMessageRequest
1212
import com.idle.network.model.chat.SendMessageRequest
1313
import com.idle.network.source.ChatDataSource
1414
import com.idle.network.util.MAX_RETRY_ATTEMPTS
15-
import com.idle.network.util.calculateEqualJitter
15+
import com.idle.network.util.calculateBackoffTime
1616
import kotlinx.coroutines.delay
1717
import kotlinx.coroutines.flow.Flow
1818
import kotlinx.coroutines.flow.map
@@ -207,7 +207,7 @@ class ChatRepositoryImpl @Inject constructor(
207207
}.retryWhen { cause, attempt ->
208208
if (cause is IOException && attempt < MAX_RETRY_ATTEMPTS) {
209209
connectWebSocket()
210-
delay(calculateEqualJitter(attempt.toInt()))
210+
delay(calculateBackoffTime(attempt.toInt()))
211211
true
212212
} else {
213213
false

core/network/src/main/java/com/idle/network/source/ChatDataSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.idle.network.model.chat.SendMessageRequest
1414
import com.idle.network.serializer.ChatResponseSerializer
1515
import com.idle.network.util.MAX_RETRY_ATTEMPTS
1616
import com.idle.network.util.MAX_WAIT_TIME
17-
import com.idle.network.util.calculateEqualJitter
17+
import com.idle.network.util.calculateBackoffTime
1818
import com.idle.network.util.safeApiCall
1919
import kotlinx.coroutines.delay
2020
import kotlinx.coroutines.flow.Flow
@@ -87,7 +87,7 @@ class ChatDataSource @Inject constructor(
8787
connectionAttempts = 0
8888
}.recoverCatching { throwable ->
8989
if (connectionAttempts < MAX_RETRY_ATTEMPTS) {
90-
val waitTime = minOf(calculateEqualJitter(connectionAttempts), MAX_WAIT_TIME)
90+
val waitTime = minOf(calculateBackoffTime(connectionAttempts), MAX_WAIT_TIME)
9191
delay(waitTime)
9292
connectionAttempts++
9393
connectWebSocket().getOrThrow()

core/network/src/main/java/com/idle/network/util/BackOff.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@ package com.idle.network.util
22

33
import com.idle.domain.model.CountDownTimer.Companion.TICK_INTERVAL
44
import kotlin.math.pow
5-
import kotlin.random.Random
65

76
const val MAX_RETRY_ATTEMPTS = 5
87
const val MAX_WAIT_TIME = 10_000L
98

10-
fun calculateEqualJitter(attempt: Int): Long {
11-
val baseDelay = calculateBackoffTime(attempt)
12-
val randomJitter = Random.nextLong(0, baseDelay / 2 + 1)
13-
return baseDelay / 2 + randomJitter
14-
}
15-
16-
private fun calculateBackoffTime(attempt: Int): Long = (2.0.pow(attempt) * TICK_INTERVAL).toLong()
9+
fun calculateBackoffTime(attempt: Int): Long = (2.0.pow(attempt) * TICK_INTERVAL).toLong()

0 commit comments

Comments
 (0)