Skip to content

Commit

Permalink
logger: inc the batch size for console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainmohd-a committed Oct 27, 2024
1 parent 096eeb4 commit 3495132
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/com/celzero/bravedns/service/NetLogTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ internal constructor(
private var rrBatcher: NetLogBatcher<RethinkLog, ConnectionSummary>? = null
private var consoleLogBatcher: NetLogBatcher<ConsoleLog, Nothing>? = null

// dispatch buffer to consumer if greater than batch size for dns, ip and rr logs
private val logBatchSize = 20
// dispatch buffer to consumer if greater than batch size, for console logs
private val consoleLogBatchSize = 100

// a single thread to run sig and batch co-routines in;
// to avoid use of mutex/semaphores over shared-state
// looper is never closed / cancelled and is always active
Expand All @@ -85,23 +90,25 @@ internal constructor(
serializer("restart", looper) {

// create new batchers on every new scope as their lifecycle is tied to the scope
val b1 = NetLogBatcher<DnsLog, Nothing>("dns", looper, dnsdb::insertBatch)
val b1 = NetLogBatcher<DnsLog, Nothing>("dns", looper, logBatchSize, dnsdb::insertBatch)
val b2 =
NetLogBatcher<ConnectionTracker, ConnectionSummary>(
"ip",
looper,
logBatchSize,
ipdb::insertBatch,
ipdb::updateBatch
)
val b3 =
NetLogBatcher<RethinkLog, ConnectionSummary>(
"rr",
looper,
logBatchSize,
ipdb::insertRethinkBatch,
ipdb::updateRethinkBatch
)
val b4 =
NetLogBatcher<ConsoleLog, Nothing>("console", consoleLogLooper, consoleLogDb::insertBatch)
NetLogBatcher<ConsoleLog, Nothing>("console", consoleLogLooper, consoleLogBatchSize, consoleLogDb::insertBatch)

b1.begin(s)
b2.begin(s)
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/celzero/bravedns/util/NetLogBatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import kotlinx.coroutines.withContext
class NetLogBatcher<T, V>(
private val tag: String,
private val looper: CoroutineDispatcher,
private val batchSize: Int,
private val processor: suspend (List<T>) -> Unit,
private val updator: suspend (List<V>) -> Unit = { _ -> }
private val updator: suspend (List<V>) -> Unit = { _ -> },
) {
companion object {
private const val DEBUG = true
Expand All @@ -49,8 +50,6 @@ class NetLogBatcher<T, V>(
private val nsig = CoroutineName(tag + "Signal")
private val ncons = CoroutineName(tag + "Consumer") // writes batches to db
private val closed = AtomicBoolean(false)
// dispatch buffer to consumer if greater than batch size
private val batchSize = 20

// no of batch-sized buffers to hold in a channel
private val qsize = 2
Expand Down

0 comments on commit 3495132

Please sign in to comment.