From 3495132a92169fd39bf1ba25a1cb61e76525c9cb Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Sun, 27 Oct 2024 20:28:04 +0530 Subject: [PATCH] logger: inc the batch size for console logs --- .../com/celzero/bravedns/service/NetLogTracker.kt | 11 +++++++++-- .../java/com/celzero/bravedns/util/NetLogBatcher.kt | 5 ++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/celzero/bravedns/service/NetLogTracker.kt b/app/src/main/java/com/celzero/bravedns/service/NetLogTracker.kt index c60b49a1..6cbd55b5 100644 --- a/app/src/main/java/com/celzero/bravedns/service/NetLogTracker.kt +++ b/app/src/main/java/com/celzero/bravedns/service/NetLogTracker.kt @@ -69,6 +69,11 @@ internal constructor( private var rrBatcher: NetLogBatcher? = null private var consoleLogBatcher: NetLogBatcher? = 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 @@ -85,11 +90,12 @@ internal constructor( serializer("restart", looper) { // create new batchers on every new scope as their lifecycle is tied to the scope - val b1 = NetLogBatcher("dns", looper, dnsdb::insertBatch) + val b1 = NetLogBatcher("dns", looper, logBatchSize, dnsdb::insertBatch) val b2 = NetLogBatcher( "ip", looper, + logBatchSize, ipdb::insertBatch, ipdb::updateBatch ) @@ -97,11 +103,12 @@ internal constructor( NetLogBatcher( "rr", looper, + logBatchSize, ipdb::insertRethinkBatch, ipdb::updateRethinkBatch ) val b4 = - NetLogBatcher("console", consoleLogLooper, consoleLogDb::insertBatch) + NetLogBatcher("console", consoleLogLooper, consoleLogBatchSize, consoleLogDb::insertBatch) b1.begin(s) b2.begin(s) diff --git a/app/src/main/java/com/celzero/bravedns/util/NetLogBatcher.kt b/app/src/main/java/com/celzero/bravedns/util/NetLogBatcher.kt index 839aca30..9f31f42c 100644 --- a/app/src/main/java/com/celzero/bravedns/util/NetLogBatcher.kt +++ b/app/src/main/java/com/celzero/bravedns/util/NetLogBatcher.kt @@ -35,8 +35,9 @@ import kotlinx.coroutines.withContext class NetLogBatcher( private val tag: String, private val looper: CoroutineDispatcher, + private val batchSize: Int, private val processor: suspend (List) -> Unit, - private val updator: suspend (List) -> Unit = { _ -> } + private val updator: suspend (List) -> Unit = { _ -> }, ) { companion object { private const val DEBUG = true @@ -49,8 +50,6 @@ class NetLogBatcher( 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