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

Feature/allocation retention queue size based on max memory jvm value epmdj 10655 #162

Draft
wants to merge 4 commits into
base: merge/v0.9.0
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,7 @@ class IntervalCoverageSender(
private val intervalMs: Long,
private var coverageTransport: CoverageTransport = StubTransport(),
private val inMemoryRetentionQueue: RetentionQueue = InMemoryRetentionQueue(
totalSizeByteLimit = try {
DataSize.parse(JvmModuleConfiguration.getCoverageRetentionLimit())
.toUnit(ByteUnit.BYTE)
.value
.toBigInteger()
} catch (e: ParseException) {
logger.warn { "Catch exception while parsing CoverageRetentionLimit. Exception: ${e.message}" }
BigInteger.valueOf(1024 * 1024 * 512)
}
totalSizeByteLimit = getMaxQueueByteSize(logger)
),
private val collectProbes: () -> Sequence<ExecDatum> = { emptySequence() }
) : CoverageSender {
Expand Down Expand Up @@ -115,3 +107,24 @@ class IntervalCoverageSender(
}
}
}

private fun getMaxQueueByteSize(logger: KLogger): BigInteger {
val maxMemory = Runtime.getRuntime().maxMemory()
// If there is no inherent max limit, then the value Long.MAX_VALUE will be returned from maxMemory().
if (maxMemory != Long.MAX_VALUE) {
val percentage = 0.1
logger.warn { "CoverageRetentionLimit will be skipped." }
return (maxMemory * percentage).toLong().toBigInteger()
} else {
val retentionLimit = JvmModuleConfiguration.getCoverageRetentionLimit()
try {
return DataSize.parse(retentionLimit)
.toUnit(ByteUnit.BYTE)
.value
.toBigInteger()
} catch (e: ParseException) {
logger.warn { "Catch exception while parsing CoverageRetentionLimit. Exception: ${e.message}" }
return BigInteger.valueOf(1024 * 1024 * 512)
}
}
}