Compare commits
3
Commits
0779e8ed97
...
cfd815cd7c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfd815cd7c | ||
|
|
05cc5a1427 | ||
|
|
8d96f6e3e7 |
+1
-1
@@ -121,7 +121,7 @@ tasks.withType<Test>().configureEach {
|
||||
val heapMiB = TestHeapPolicy.calculateHeapMiB(availableBytes, maxParallelForks, maxWorkers)
|
||||
maxHeapSize = "${heapMiB}m"
|
||||
logger.lifecycle(
|
||||
"Test heap: available estimate={} MiB, workers={}, maxHeap={} MiB (50% budget, 1 GiB native reserve per worker)",
|
||||
"Test heap: available estimate={} MiB, workers={}, maxHeap={} MiB (50% worker budget, 25% native reserve)",
|
||||
availableBytes / (1024 * 1024),
|
||||
minOf(maxParallelForks, maxWorkers),
|
||||
heapMiB
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
java
|
||||
`kotlin-dsl`
|
||||
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
package buildlogic;
|
||||
|
||||
import com.sun.management.OperatingSystemMXBean;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class TestHeapPolicy {
|
||||
private static final long MIB = 1L << 20;
|
||||
private static final long WORKER_RESERVE_BYTES = 1L << 30;
|
||||
private static final long MINIMUM_HEAP_MIB = 4096;
|
||||
private static final Pattern PAGE_SIZE = Pattern.compile(
|
||||
"Mach Virtual Memory Statistics:\\s*\\(page size of ([0-9]+) bytes\\)"
|
||||
);
|
||||
private static final Pattern PAGE_COUNTER = Pattern.compile("Pages (free|inactive)\\s*:\\s*([0-9]+)\\.?");
|
||||
|
||||
private TestHeapPolicy() {
|
||||
}
|
||||
|
||||
public static long calculateHeapMiB(long availableBytes, int maxParallelForks, int maxWorkers) {
|
||||
if (availableBytes <= 0 || maxParallelForks <= 0 || maxWorkers <= 0) {
|
||||
throw new IllegalArgumentException("Available bytes, maxParallelForks and maxWorkers must be positive");
|
||||
}
|
||||
|
||||
int effectiveWorkers = Math.min(maxParallelForks, maxWorkers);
|
||||
long perWorkerBytes = availableBytes / 2 / effectiveWorkers;
|
||||
long heapMiB = (perWorkerBytes - WORKER_RESERVE_BYTES) / MIB;
|
||||
if (heapMiB < MINIMUM_HEAP_MIB) {
|
||||
throw new IllegalStateException(
|
||||
"Insufficient test memory: availableBytes=" + availableBytes + ", effectiveWorkers=" + effectiveWorkers
|
||||
+ ", minimumHeapMiB=" + MINIMUM_HEAP_MIB + ". Close other applications or reduce workers."
|
||||
);
|
||||
}
|
||||
return heapMiB;
|
||||
}
|
||||
|
||||
public static long readAvailableBytes() {
|
||||
long availableBytes;
|
||||
if (System.getProperty("os.name").startsWith("Mac")) {
|
||||
ProcessBuilder builder = new ProcessBuilder("/usr/bin/vm_stat").redirectErrorStream(true);
|
||||
builder.environment().put("LC_ALL", "C");
|
||||
try {
|
||||
Process process = builder.start();
|
||||
try (
|
||||
InputStream output = process.getInputStream();
|
||||
InputStream error = process.getErrorStream();
|
||||
OutputStream input = process.getOutputStream()
|
||||
) {
|
||||
if (!process.waitFor(5, TimeUnit.SECONDS)) {
|
||||
throw new IllegalStateException("vm_stat did not finish within 5 seconds");
|
||||
}
|
||||
if (process.exitValue() != 0) {
|
||||
throw new IllegalStateException("vm_stat failed with exit code " + process.exitValue());
|
||||
}
|
||||
availableBytes = parseMacVmStat(new String(output.readAllBytes(), StandardCharsets.US_ASCII));
|
||||
} finally {
|
||||
process.destroyForcibly();
|
||||
}
|
||||
} catch (InterruptedException failure) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Interrupted while reading available memory with vm_stat", failure);
|
||||
} catch (IOException failure) {
|
||||
throw new IllegalStateException("Unable to read available memory with vm_stat", failure);
|
||||
}
|
||||
} else {
|
||||
OperatingSystemMXBean operatingSystem = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
|
||||
if (operatingSystem == null) {
|
||||
throw new IllegalStateException("OperatingSystemMXBean free-memory observation is unavailable");
|
||||
}
|
||||
availableBytes = operatingSystem.getFreeMemorySize();
|
||||
}
|
||||
if (availableBytes <= 0) {
|
||||
throw new IllegalStateException("Available-memory observation must be positive: availableBytes=" + availableBytes);
|
||||
}
|
||||
return availableBytes;
|
||||
}
|
||||
|
||||
static long parseMacVmStat(String output) {
|
||||
long pageSize = -1;
|
||||
long freePages = -1;
|
||||
long inactivePages = -1;
|
||||
try {
|
||||
for (String rawLine : output.lines().toList()) {
|
||||
String line = rawLine.strip();
|
||||
if (line.startsWith("Mach Virtual Memory Statistics")) {
|
||||
Matcher header = PAGE_SIZE.matcher(line);
|
||||
if (pageSize >= 0 || !header.matches()) {
|
||||
throw new IllegalArgumentException("Duplicate or malformed vm_stat page-size header: " + line);
|
||||
}
|
||||
pageSize = Long.parseLong(header.group(1));
|
||||
} else if (line.startsWith("Pages free") || line.startsWith("Pages inactive")) {
|
||||
Matcher counter = PAGE_COUNTER.matcher(line);
|
||||
if (!counter.matches()) {
|
||||
throw new IllegalArgumentException("Malformed vm_stat page counter: " + line);
|
||||
}
|
||||
long pages = Long.parseLong(counter.group(2));
|
||||
if (counter.group(1).equals("free")) {
|
||||
if (freePages >= 0) {
|
||||
throw new IllegalArgumentException("Duplicate vm_stat Pages free counter");
|
||||
}
|
||||
freePages = pages;
|
||||
} else {
|
||||
if (inactivePages >= 0) {
|
||||
throw new IllegalArgumentException("Duplicate vm_stat Pages inactive counter");
|
||||
}
|
||||
inactivePages = pages;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pageSize <= 0 || freePages < 0 || inactivePages < 0) {
|
||||
throw new IllegalArgumentException("vm_stat requires a positive page size and both free and inactive counters");
|
||||
}
|
||||
// Raw free already includes speculative pages; do not subtract or add them separately.
|
||||
return Math.multiplyExact(Math.addExact(freePages, inactivePages), pageSize);
|
||||
} catch (NumberFormatException | ArithmeticException failure) {
|
||||
throw new IllegalArgumentException("vm_stat page size or counters exceed the supported long range", failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package buildlogic
|
||||
|
||||
import com.sun.management.OperatingSystemMXBean
|
||||
import java.io.IOException
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object TestHeapPolicy {
|
||||
private const val MIB = 1L shl 20
|
||||
private const val JVM_MINIMUM_HEAP_MIB = 2L
|
||||
private val PAGE_SIZE = Pattern.compile(
|
||||
"Mach Virtual Memory Statistics:\\s*\\(page size of ([0-9]+) bytes\\)"
|
||||
)
|
||||
private val PAGE_COUNTER = Pattern.compile("Pages (free|inactive)\\s*:\\s*([0-9]+)\\.?")
|
||||
|
||||
@JvmStatic
|
||||
fun calculateHeapMiB(availableBytes: Long, maxParallelForks: Int, maxWorkers: Int): Long {
|
||||
require(availableBytes > 0 && maxParallelForks > 0 && maxWorkers > 0) {
|
||||
"Available bytes, maxParallelForks and maxWorkers must be positive"
|
||||
}
|
||||
|
||||
val effectiveWorkers = minOf(maxParallelForks, maxWorkers)
|
||||
val perWorkerBytes = availableBytes / 2 / effectiveWorkers
|
||||
val nativeReserveBytes = (perWorkerBytes + 3) / 4
|
||||
val heapMiB = (perWorkerBytes - nativeReserveBytes) / MIB
|
||||
check(heapMiB >= JVM_MINIMUM_HEAP_MIB) {
|
||||
"Insufficient test memory: availableBytes=$availableBytes, effectiveWorkers=$effectiveWorkers" +
|
||||
", heapMiB=$heapMiB. JVM requires at least 2 MiB. Close other applications or reduce workers."
|
||||
}
|
||||
return heapMiB
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun readAvailableBytes(): Long {
|
||||
val availableBytes = if (System.getProperty("os.name").startsWith("Mac")) {
|
||||
val builder = ProcessBuilder("/usr/bin/vm_stat").redirectErrorStream(true)
|
||||
builder.environment()["LC_ALL"] = "C"
|
||||
try {
|
||||
val process = builder.start()
|
||||
try {
|
||||
process.inputStream.use { output ->
|
||||
process.errorStream.use {
|
||||
process.outputStream.use {
|
||||
check(process.waitFor(5, TimeUnit.SECONDS)) {
|
||||
"vm_stat did not finish within 5 seconds"
|
||||
}
|
||||
check(process.exitValue() == 0) {
|
||||
"vm_stat failed with exit code ${process.exitValue()}"
|
||||
}
|
||||
parseMacVmStat(String(output.readAllBytes(), StandardCharsets.US_ASCII))
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
process.destroyForcibly()
|
||||
}
|
||||
} catch (failure: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
throw IllegalStateException("Interrupted while reading available memory with vm_stat", failure)
|
||||
} catch (failure: IOException) {
|
||||
throw IllegalStateException("Unable to read available memory with vm_stat", failure)
|
||||
}
|
||||
} else {
|
||||
val operatingSystem = checkNotNull(ManagementFactory.getPlatformMXBean(OperatingSystemMXBean::class.java)) {
|
||||
"OperatingSystemMXBean free-memory observation is unavailable"
|
||||
}
|
||||
operatingSystem.freeMemorySize
|
||||
}
|
||||
check(availableBytes > 0) {
|
||||
"Available-memory observation must be positive: availableBytes=$availableBytes"
|
||||
}
|
||||
return availableBytes
|
||||
}
|
||||
|
||||
internal fun parseMacVmStat(output: String): Long {
|
||||
var pageSize = -1L
|
||||
var freePages = -1L
|
||||
var inactivePages = -1L
|
||||
try {
|
||||
for (rawLine in output.lineSequence()) {
|
||||
val line = rawLine.trim { Character.isWhitespace(it) }
|
||||
if (line.startsWith("Mach Virtual Memory Statistics")) {
|
||||
val header = PAGE_SIZE.matcher(line)
|
||||
require(pageSize < 0 && header.matches()) {
|
||||
"Duplicate or malformed vm_stat page-size header: $line"
|
||||
}
|
||||
pageSize = header.group(1).toLong()
|
||||
} else if (line.startsWith("Pages free") || line.startsWith("Pages inactive")) {
|
||||
val counter = PAGE_COUNTER.matcher(line)
|
||||
require(counter.matches()) { "Malformed vm_stat page counter: $line" }
|
||||
val pages = counter.group(2).toLong()
|
||||
if (counter.group(1) == "free") {
|
||||
require(freePages < 0) { "Duplicate vm_stat Pages free counter" }
|
||||
freePages = pages
|
||||
} else {
|
||||
require(inactivePages < 0) { "Duplicate vm_stat Pages inactive counter" }
|
||||
inactivePages = pages
|
||||
}
|
||||
}
|
||||
}
|
||||
require(pageSize > 0 && freePages >= 0 && inactivePages >= 0) {
|
||||
"vm_stat requires a positive page size and both free and inactive counters"
|
||||
}
|
||||
// Raw free already includes speculative pages; do not subtract or add them separately.
|
||||
return Math.multiplyExact(Math.addExact(freePages, inactivePages), pageSize)
|
||||
} catch (failure: NumberFormatException) {
|
||||
throw IllegalArgumentException("vm_stat page size or counters exceed the supported long range", failure)
|
||||
} catch (failure: ArithmeticException) {
|
||||
throw IllegalArgumentException("vm_stat page size or counters exceed the supported long range", failure)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package buildlogic;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
|
||||
|
||||
class TestHeapPolicyTest {
|
||||
private static final long MIB = 1L << 20;
|
||||
private static final long GIB = 1L << 30;
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldCalculateHeapWithinTheAvailableWorkerBudget() {
|
||||
return Stream.of(
|
||||
dynamicTest("10 GiB reaches the 4096 MiB floor", () ->
|
||||
assertEquals(4096, TestHeapPolicy.calculateHeapMiB(10 * GIB, 1, 1))),
|
||||
dynamicTest("20 GiB supports two workers at the floor", () ->
|
||||
assertEquals(4096, TestHeapPolicy.calculateHeapMiB(20 * GIB, 2, 2))),
|
||||
dynamicTest("13 GiB leaves half and the per-worker reserve", () ->
|
||||
assertEquals(5632, TestHeapPolicy.calculateHeapMiB(13 * GIB, 1, 1))),
|
||||
dynamicTest("max workers caps four requested forks", () ->
|
||||
assertEquals(7168, TestHeapPolicy.calculateHeapMiB(32 * GIB, 4, 2))),
|
||||
dynamicTest("max forks caps four available workers", () ->
|
||||
assertEquals(7168, TestHeapPolicy.calculateHeapMiB(32 * GIB, 2, 4))),
|
||||
dynamicTest("fractional MiB rounds down", () ->
|
||||
assertEquals(5632, TestHeapPolicy.calculateHeapMiB(13 * GIB + 2 * MIB - 1, 1, 1))),
|
||||
dynamicTest("an exact additional MiB is retained", () ->
|
||||
assertEquals(5633, TestHeapPolicy.calculateHeapMiB(13 * GIB + 2 * MIB, 1, 1))),
|
||||
dynamicTest("the largest positive long does not overflow", () ->
|
||||
assertEquals(4_398_046_510_079L, TestHeapPolicy.calculateHeapMiB(Long.MAX_VALUE, 1, 1)))
|
||||
);
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldRejectInsufficientBudgetsWithActionableDiagnostics() {
|
||||
return Stream.of(
|
||||
new long[] {10 * GIB - 1, 1, 1},
|
||||
new long[] {20 * GIB - 1, 4, 2},
|
||||
new long[] {1, 1, 1},
|
||||
new long[] {GIB, 1, 1},
|
||||
new long[] {2 * GIB, 1, 1},
|
||||
new long[] {8 * GIB, 1, 1}
|
||||
).map(input -> dynamicTest(Arrays.toString(input), () -> {
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, () ->
|
||||
TestHeapPolicy.calculateHeapMiB(input[0], (int) input[1], (int) input[2]));
|
||||
|
||||
String message = failure.getMessage();
|
||||
assertAll(
|
||||
() -> assertTrue(message.contains("availableBytes=" + input[0]), message),
|
||||
() -> assertTrue(message.contains("effectiveWorkers=" + Math.min(input[1], input[2])), message),
|
||||
() -> assertTrue(message.contains("minimumHeapMiB=4096"), message),
|
||||
() -> assertTrue(message.contains("Close other applications"), message),
|
||||
() -> assertTrue(message.contains("reduce workers"), message)
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldRejectNonpositiveAvailabilityOrWorkerLimits() {
|
||||
return Stream.of(
|
||||
new long[] {0, 1, 1},
|
||||
new long[] {-1, 1, 1},
|
||||
new long[] {Long.MIN_VALUE, 1, 1},
|
||||
new long[] {10 * GIB, 0, 1},
|
||||
new long[] {10 * GIB, -1, 1},
|
||||
new long[] {10 * GIB, Integer.MIN_VALUE, 1},
|
||||
new long[] {10 * GIB, 1, 0},
|
||||
new long[] {10 * GIB, 1, -1},
|
||||
new long[] {10 * GIB, 1, Integer.MIN_VALUE}
|
||||
).map(input -> dynamicTest(Arrays.toString(input), () ->
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
TestHeapPolicy.calculateHeapMiB(input[0], (int) input[1], (int) input[2]))));
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldParseOnlyRawFreeAndInactivePages() {
|
||||
return Stream.of(
|
||||
dynamicTest("4K pages ignore speculative and file-backed counts", () ->
|
||||
assertEquals(2_371_584, TestHeapPolicy.parseMacVmStat("""
|
||||
Mach Virtual Memory Statistics: (page size of 4096 bytes)
|
||||
Pages free: 123.
|
||||
Pages speculative: 100.
|
||||
Pages inactive: 456.
|
||||
File-backed pages: 999.
|
||||
"""))),
|
||||
dynamicTest("16K pages accept reordered counters and whitespace", () ->
|
||||
assertEquals(81_920, TestHeapPolicy.parseMacVmStat("""
|
||||
Mach Virtual Memory Statistics: (page size of 16384 bytes)
|
||||
Pages inactive : 3.
|
||||
Pages active: 999.
|
||||
Pages free:\t2.
|
||||
"""))),
|
||||
dynamicTest("both raw counters may be zero", () ->
|
||||
assertEquals(0, TestHeapPolicy.parseMacVmStat(vmStat("4096", "0", "0")))),
|
||||
dynamicTest("counters need not have trailing periods", () ->
|
||||
assertEquals(20_480, TestHeapPolicy.parseMacVmStat(
|
||||
vmStat("4096", "2", "3").replace(".\n", "\n")))),
|
||||
dynamicTest("the largest representable byte count remains valid", () ->
|
||||
assertEquals(Long.MAX_VALUE, TestHeapPolicy.parseMacVmStat(vmStat("1", "9223372036854775806", "1"))))
|
||||
);
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldRejectMissingDuplicateMalformedNegativeOrOverflowingVmStatFields() {
|
||||
String valid = vmStat("4096", "2", "3");
|
||||
return Stream.of(
|
||||
"",
|
||||
"Pages free: 2.\nPages inactive: 3.\n",
|
||||
"page size of 4096 bytes\nPages free: 2.\nPages inactive: 3.\n",
|
||||
valid.replace("Pages free: 2.\n", ""),
|
||||
valid.replace("Pages inactive: 3.\n", ""),
|
||||
valid + "Pages free: 2.\n",
|
||||
valid + "Pages inactive: 3.\n",
|
||||
valid + "Mach Virtual Memory Statistics: (page size of 4096 bytes)\n",
|
||||
valid + "Pages free: broken.\n",
|
||||
vmStat("4096", "-1", "3"),
|
||||
vmStat("4096", "2", "-1"),
|
||||
vmStat("-4096", "2", "3"),
|
||||
vmStat("0", "2", "3"),
|
||||
vmStat("invalid", "2", "3"),
|
||||
vmStat("4096", "2x", "3"),
|
||||
vmStat("4096", "2", "3.5"),
|
||||
valid.replace("Pages free:", "Pages free"),
|
||||
valid.replace("bytes)", "bytes) trailing"),
|
||||
vmStat("9223372036854775808", "2", "3"),
|
||||
vmStat("4096", "9223372036854775808", "3"),
|
||||
vmStat("1", "9223372036854775807", "1"),
|
||||
vmStat("4096", "2251799813685248", "0")
|
||||
).map(output -> dynamicTest("rejects " + output.replace('\n', ' '), () ->
|
||||
assertThrows(IllegalArgumentException.class, () -> TestHeapPolicy.parseMacVmStat(output))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReadPositiveAvailabilityFromTheCurrentOperatingSystem() {
|
||||
assertTrue(TestHeapPolicy.readAvailableBytes() > 0);
|
||||
}
|
||||
|
||||
private static String vmStat(String pageSize, String free, String inactive) {
|
||||
return "Mach Virtual Memory Statistics: (page size of " + pageSize + " bytes)\n"
|
||||
+ "Pages free: " + free + ".\nPages inactive: " + inactive + ".\n";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package buildlogic
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertAll
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.DynamicTest
|
||||
import org.junit.jupiter.api.DynamicTest.dynamicTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestFactory
|
||||
|
||||
class TestHeapPolicyTest {
|
||||
@TestFactory
|
||||
fun shouldCalculateHeapWithinTheAvailableWorkerBudget(): List<DynamicTest> = listOf(
|
||||
dynamicTest("the reported Jenkins availability runs below the former fixed floor") {
|
||||
assertEquals(879L, TestHeapPolicy.calculateHeapMiB(2_460_004_352L, 1, 1))
|
||||
},
|
||||
dynamicTest("1 GiB reserves native memory proportionally") {
|
||||
assertEquals(384L, TestHeapPolicy.calculateHeapMiB(GIB, 1, 1))
|
||||
},
|
||||
dynamicTest("2 GiB does not lose the whole worker budget to a fixed reserve") {
|
||||
assertEquals(768L, TestHeapPolicy.calculateHeapMiB(2 * GIB, 1, 1))
|
||||
},
|
||||
dynamicTest("8 GiB permits a heap below 4 GiB") {
|
||||
assertEquals(3072L, TestHeapPolicy.calculateHeapMiB(8 * GIB, 1, 1))
|
||||
},
|
||||
dynamicTest("10 GiB scales without a policy floor") {
|
||||
assertEquals(3840L, TestHeapPolicy.calculateHeapMiB(10 * GIB, 1, 1))
|
||||
},
|
||||
dynamicTest("20 GiB is shared between two workers") {
|
||||
assertEquals(3840L, TestHeapPolicy.calculateHeapMiB(20 * GIB, 2, 2))
|
||||
},
|
||||
dynamicTest("13 GiB leaves half and a proportional native reserve") {
|
||||
assertEquals(4992L, TestHeapPolicy.calculateHeapMiB(13 * GIB, 1, 1))
|
||||
},
|
||||
dynamicTest("max workers caps four requested forks") {
|
||||
assertEquals(6144L, TestHeapPolicy.calculateHeapMiB(32 * GIB, 4, 2))
|
||||
},
|
||||
dynamicTest("max forks caps four available workers") {
|
||||
assertEquals(6144L, TestHeapPolicy.calculateHeapMiB(32 * GIB, 2, 4))
|
||||
},
|
||||
dynamicTest("fractional MiB rounds down") {
|
||||
assertEquals(4992L, TestHeapPolicy.calculateHeapMiB(13 * GIB + 2 * MIB, 1, 1))
|
||||
},
|
||||
dynamicTest("an exact proportional increase is retained") {
|
||||
assertEquals(4995L, TestHeapPolicy.calculateHeapMiB(13 * GIB + 8 * MIB, 1, 1))
|
||||
},
|
||||
dynamicTest("one byte below the proportional increase rounds down") {
|
||||
assertEquals(4994L, TestHeapPolicy.calculateHeapMiB(13 * GIB + 8 * MIB - 1, 1, 1))
|
||||
},
|
||||
dynamicTest("the JVM technical minimum is not replaced with an application floor") {
|
||||
assertEquals(2L, TestHeapPolicy.calculateHeapMiB(5_592_406, 1, 1))
|
||||
},
|
||||
dynamicTest("the JVM technical minimum accounts for two workers") {
|
||||
assertEquals(2L, TestHeapPolicy.calculateHeapMiB(11_184_812, 2, 2))
|
||||
},
|
||||
dynamicTest("the largest positive long does not overflow") {
|
||||
assertEquals(3_298_534_883_327L, TestHeapPolicy.calculateHeapMiB(Long.MAX_VALUE, 1, 1))
|
||||
}
|
||||
)
|
||||
|
||||
@TestFactory
|
||||
fun shouldRejectOnlyBudgetsTooSmallToStartTheJvm(): List<DynamicTest> = listOf(
|
||||
Triple(5_592_405L, 1, 1),
|
||||
Triple(11_184_811L, 4, 2),
|
||||
Triple(1L, 1, 1),
|
||||
Triple(MIB, 1, 1),
|
||||
Triple(2 * MIB, 1, 1),
|
||||
Triple(4 * MIB, 1, 1)
|
||||
).map { (available, forks, workers) ->
|
||||
dynamicTest("[$available, $forks, $workers]") {
|
||||
val failure = assertThrows(IllegalStateException::class.java) {
|
||||
TestHeapPolicy.calculateHeapMiB(available, forks, workers)
|
||||
}
|
||||
val message = requireNotNull(failure.message)
|
||||
assertAll(
|
||||
{ assertTrue(message.contains("availableBytes=$available"), message) },
|
||||
{ assertTrue(message.contains("effectiveWorkers=${minOf(forks, workers)}"), message) },
|
||||
{ assertTrue(message.contains("JVM requires at least 2 MiB"), message) },
|
||||
{ assertTrue(message.contains("Close other applications"), message) },
|
||||
{ assertTrue(message.contains("reduce workers"), message) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
fun shouldRejectNonpositiveAvailabilityOrWorkerLimits(): List<DynamicTest> = listOf(
|
||||
Triple(0L, 1, 1),
|
||||
Triple(-1L, 1, 1),
|
||||
Triple(Long.MIN_VALUE, 1, 1),
|
||||
Triple(10 * GIB, 0, 1),
|
||||
Triple(10 * GIB, -1, 1),
|
||||
Triple(10 * GIB, Int.MIN_VALUE, 1),
|
||||
Triple(10 * GIB, 1, 0),
|
||||
Triple(10 * GIB, 1, -1),
|
||||
Triple(10 * GIB, 1, Int.MIN_VALUE)
|
||||
).map { (available, forks, workers) ->
|
||||
dynamicTest("[$available, $forks, $workers]") {
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
TestHeapPolicy.calculateHeapMiB(available, forks, workers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
fun shouldParseOnlyRawFreeAndInactivePages(): List<DynamicTest> = listOf(
|
||||
dynamicTest("4K pages ignore speculative and file-backed counts") {
|
||||
assertEquals(
|
||||
2_371_584L,
|
||||
TestHeapPolicy.parseMacVmStat(
|
||||
"""
|
||||
Mach Virtual Memory Statistics: (page size of 4096 bytes)
|
||||
Pages free: 123.
|
||||
Pages speculative: 100.
|
||||
Pages inactive: 456.
|
||||
File-backed pages: 999.
|
||||
""".trimIndent()
|
||||
)
|
||||
)
|
||||
},
|
||||
dynamicTest("16K pages accept reordered counters and whitespace") {
|
||||
assertEquals(
|
||||
81_920L,
|
||||
TestHeapPolicy.parseMacVmStat(
|
||||
" Mach Virtual Memory Statistics: (page size of 16384 bytes)\n" +
|
||||
" Pages inactive : 3.\nPages active: 999.\nPages free:\t2.\n"
|
||||
)
|
||||
)
|
||||
},
|
||||
dynamicTest("both raw counters may be zero") {
|
||||
assertEquals(0L, TestHeapPolicy.parseMacVmStat(vmStat("4096", "0", "0")))
|
||||
},
|
||||
dynamicTest("counters need not have trailing periods") {
|
||||
assertEquals(20_480L, TestHeapPolicy.parseMacVmStat(vmStat("4096", "2", "3").replace(".\n", "\n")))
|
||||
},
|
||||
dynamicTest("the largest representable byte count remains valid") {
|
||||
assertEquals(Long.MAX_VALUE, TestHeapPolicy.parseMacVmStat(vmStat("1", "9223372036854775806", "1")))
|
||||
}
|
||||
)
|
||||
|
||||
@TestFactory
|
||||
fun shouldRejectMissingDuplicateMalformedNegativeOrOverflowingVmStatFields(): List<DynamicTest> {
|
||||
val valid = vmStat("4096", "2", "3")
|
||||
return listOf(
|
||||
"",
|
||||
"Pages free: 2.\nPages inactive: 3.\n",
|
||||
"page size of 4096 bytes\nPages free: 2.\nPages inactive: 3.\n",
|
||||
valid.replace("Pages free: 2.\n", ""),
|
||||
valid.replace("Pages inactive: 3.\n", ""),
|
||||
valid + "Pages free: 2.\n",
|
||||
valid + "Pages inactive: 3.\n",
|
||||
valid + "Mach Virtual Memory Statistics: (page size of 4096 bytes)\n",
|
||||
valid + "Pages free: broken.\n",
|
||||
vmStat("4096", "-1", "3"),
|
||||
vmStat("4096", "2", "-1"),
|
||||
vmStat("-4096", "2", "3"),
|
||||
vmStat("0", "2", "3"),
|
||||
vmStat("invalid", "2", "3"),
|
||||
vmStat("4096", "2x", "3"),
|
||||
vmStat("4096", "2", "3.5"),
|
||||
valid.replace("Pages free:", "Pages free"),
|
||||
valid.replace("bytes)", "bytes) trailing"),
|
||||
vmStat("9223372036854775808", "2", "3"),
|
||||
vmStat("4096", "9223372036854775808", "3"),
|
||||
vmStat("1", "9223372036854775807", "1"),
|
||||
vmStat("4096", "2251799813685248", "0")
|
||||
).map { output ->
|
||||
dynamicTest("rejects ${output.replace('\n', ' ')}") {
|
||||
assertThrows(IllegalArgumentException::class.java) { TestHeapPolicy.parseMacVmStat(output) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldReadPositiveAvailabilityFromTheCurrentOperatingSystem() {
|
||||
assertTrue(TestHeapPolicy.readAvailableBytes() > 0)
|
||||
}
|
||||
|
||||
private fun vmStat(pageSize: String, free: String, inactive: String): String =
|
||||
"Mach Virtual Memory Statistics: (page size of $pageSize bytes)\n" +
|
||||
"Pages free: $free.\nPages inactive: $inactive.\n"
|
||||
|
||||
companion object {
|
||||
private const val MIB = 1_048_576L
|
||||
private const val GIB = 1_073_741_824L
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
- 작성일: 2026-11-18
|
||||
- 기준: [prd.md](prd.md)
|
||||
- 상태: P4 구현·경계/실제 worker/부족 예산/lint 검증·리뷰 승인·정리 완료. 전체 테스트 재실행은 미수행.
|
||||
- 상태: P6 buildSrc Kotlin 통일, 58개 정책/33개 focused/lint/API/리뷰 검증 및 정리 완료. 실제 Jenkins와 전체 suite 재실행은 미수행.
|
||||
- 활성 Goal: 없음
|
||||
|
||||
## P1-T1: 실패 원인 재현과 최소 테스트 수정
|
||||
@@ -197,3 +197,46 @@
|
||||
- 임시 JVM 관측 probe, 부족 예산 init script와 실행 노트를 삭제하고 owned root를 정리한다. 계산식/검증 결과는 이 문서에 남긴다. 앱 코드 및 기존 테스트 파일은 P4에서 수정하지 않았다.
|
||||
- 최종 독립 리뷰 APPROVE: raw free+inactive 계산, 예산/worker cap/내림/4GiB 하한, parser 오류와 프로세스 정리, doFirst 연결 및 별도 buildSrc 테스트 범위를 확인했다. 비macOS와 강제 timeout/interruption은 미검증으로 유지한다.
|
||||
- 소유 임시 root 삭제와 부재 확인 완료. 추가 재검증 없이 종료하며 commit/push는 수행하지 않았다.
|
||||
|
||||
## P5: 고정 힙 하한·예약량 제거
|
||||
- 시작 조건: 사용자 승인과 Jenkins 오류 `availableBytes=2460004352, effectiveWorkers=1, minimumHeapMiB=4096`.
|
||||
- 대상 파일: `buildSrc/src/main/java/buildlogic/TestHeapPolicy.java`, `buildSrc/src/test/java/buildlogic/TestHeapPolicyTest.java`, 루트 `build.gradle.kts` 로그, 실행 가이드와 기존 문서.
|
||||
- 정책 변경: F=`min(maxParallelForks,maxWorkers)`, P=`floor(floor(A/2)/F)`, native reserve=`ceil(P/4)`, heapMiB=`floor((P-native reserve)/1MiB)`. 고정 1GiB 차감과 4GiB 정책 하한을 제거한다. 양수 입력·overflow 안전성은 유지한다.
|
||||
- 기술 한계 관측: 로컬 Java17에서 `java -Xmx2m -version`은 성공하고 `java -Xmx1m -version`은 `Too small maximum heap`로 실패했다. 따라서 2MiB 미만만 JVM 실행 불가로 거부하며 상향 보정하지 않는다.
|
||||
- [x] Jenkins 실제 값, sub-GiB/4GiB 미만 예산, worker 분배, rounding과 JVM 극소 경계의 새 계약을 테스트에서 먼저 RED 확인.
|
||||
- [x] 비율 계산 구현 후 전체 buildSrc 정책 테스트 GREEN.
|
||||
- [x] 실제 root worker에 동적 Xmx 전달, script lint·단일 리뷰 확인.
|
||||
- [x] 현재 정책/미검증 범위 문서와 소유 임시 자원 정리.
|
||||
- 실제 Jenkins/AWS 실행, 전체 앱 suite, OS 메모리 조회 변경은 범위 밖이다. 이번 회귀는 4GiB 사전 거부를 해결하며 작은 힙에서 모든 테스트가 통과한다고 보장하지 않는다.
|
||||
- RED: `./gradlew --no-daemon --offline -p buildSrc test --tests 'buildlogic.TestHeapPolicyTest' --console=plain`, exit 1/8초. 58개 중 21개 실패. 실제 Jenkins 값과 1/2/8GiB 입력은 기존 fixed floor 예외를 재현했고, 다른 예산/반올림은 새 비율 계약과 불일치했다. 기존 parser/invalid-input 검사들은 그대로 유지했다.
|
||||
- 최소 구현: 1GiB 상수를 없애고 `ceil(perWorkerBytes/4)`를 native reserve로 사용한다. 4GiB 정책 하한 대신 JVM 실행 가능 여부만 검사한다. root 로그와 실행 가이드도 비율 정책으로 갱신했다.
|
||||
- GREEN: 같은 buildSrc focused 명령 exit 0/8초, 58 tests/0 failures/0 errors/0 skipped. Jenkins 제공값 2,460,004,352 bytes가 879MiB를 반환함을 검증했다.
|
||||
- 실제 root 검증: `./gradlew --no-daemon --offline --max-workers=1 ktlintKotlinScriptCheck test --tests '*CodePointTextSplitterTest' --info --console=plain`, exit 0/9분 11초. buildSrc 변경에 따른 기존 Kotlin/KAPT 재컴파일을 포함했다. CodePointTextSplitterTest 33개 통과와 script lint 성공 확인. 기존 애플리케이션/테스트 컴파일 경고는 숨기거나 변경하지 않았다.
|
||||
- task 시작 시 관측 13,160MiB, worker 1개, 선택 4,935MiB였고 실제 worker 명령 `-Xmx4935m`과 일치했다. 이 로컬 실행을 Jenkins 노드의 실행 결과로 해석하지 않는다.
|
||||
- 독립 P5 리뷰 APPROVE. 고정 4GiB·1GiB 값 제거, 비율 예약의 overflow 안전성, 실제 Jenkins 입력과 sub-GiB/rounding 경계, OS reader/기존 보호 설정 유지 및 작은 힙의 한계를 확인했다.
|
||||
- `git diff --check` 통과, 소유 테스트 worker 없음 확인. 실행 노트·owned temp root 삭제 및 부재 확인 후 종료한다. commit/push는 수행하지 않았다.
|
||||
|
||||
## P6: buildSrc Kotlin 통일
|
||||
- 사용자 승인에 따른 언어 전환이며 정책 변경이 아니다. P5의 Java 58개 GREEN을 baseline으로 사용한다.
|
||||
- 의존 경계: root build.gradle.kts → TestHeapPolicy public static calculateHeapMiB/readAvailableBytes. parser는 buildSrc 테스트에서만 호출한다. 앱 코드 의존은 없다.
|
||||
- 변경 파일: `buildSrc/build.gradle.kts`, Java helper/test를 각각 `buildSrc/src/main/kotlin/buildlogic/TestHeapPolicy.kt`, `buildSrc/src/test/kotlin/buildlogic/TestHeapPolicyTest.kt`로 이동, 기존 작업 문서와 사용법 필요 부분.
|
||||
- 플러그인: Gradle 버전에 맞는 `kotlin-dsl`, Java toolchain 17, 기존 JUnit 5.8.2 유지. 앱 Kotlin 1.6.21은 변경하지 않는다. 로컬에 kotlin-dsl 플러그인이 캐시돼 있지 않아 최초 의존성 해석은 네트워크가 필요할 수 있다.
|
||||
- [x] Kotlin 전환과 Java 중복 제거. 모든 동작·케이스 보존.
|
||||
- [x] buildSrc clean focused test에서 58/58 통과, Kotlin 소스 lint와 public JVM signature 확인.
|
||||
- [x] root Gradle에서 helper를 호출하고 선택된 Xmx가 실제 worker에 전달되는지 확인.
|
||||
- [x] 독립 리뷰, 문서 기록, 소유 임시 자원 정리.
|
||||
- `javap` baseline: `public static long calculateHeapMiB(long,int,int)`, `public static long readAvailableBytes()`. 기존 parser는 Java package-private이다. Kotlin에서는 module 내부로 한정한다.
|
||||
- Java baseline XML: 58 tests/0 failures, 정렬한 testcase 이름 JSON의 SHA-256 `6ba55b03a872659fedbca5419274eeaf42b38c2e219cd01fa34725f7b2447642`. 언어 이동 후 case 보존 확인에만 사용하며 구현 의미는 실제 assertion과 리뷰로 대조한다.
|
||||
- `./gradlew --no-daemon -p buildSrc help --console=plain` exit 0/52초. 새 kotlin-dsl 플러그인 해석과 Java17/JUnit 설정 로딩을 확인했다. 앱 Kotlin 플러그인 버전은 유지했다.
|
||||
- buildSrc의 새 Kotlin 소스도 검증하도록 루트와 동일한 ktlint 11.5.0 플러그인을 해당 build에 적용한다. 테스트와 정책의 포맷 검사 범위를 빠뜨리지 않으며 앱 의존성은 바꾸지 않는다.
|
||||
- `./gradlew --no-daemon -p buildSrc clean test --tests 'buildlogic.TestHeapPolicyTest' ktlintCheck --console=plain` exit 0/52초. Kotlin 컴파일 후 58 tests/0 failures/0 errors/0 skipped와 buildSrc의 script/main/test lint 통과. compileJava/compileTestJava NO-SOURCE로 이전 Java 산출물에 의존하지 않음을 확인했다.
|
||||
- 변환 후 testcase 이름 digest는 baseline과 동일하다. `javap -classpath buildSrc/build/classes/kotlin/main buildlogic.TestHeapPolicy`는 `.kt`에서 생성된 두 public static 메서드를 확인했다. parser는 internal 메서드로 컴파일된다.
|
||||
- root 연결: `./gradlew --no-daemon --offline --max-workers=1 ktlintKotlinScriptCheck test --tests '*CodePointTextSplitterTest' --info --console=plain`, exit 0/11분 32초. buildSrc classpath 변경에 따른 기존 Kotlin/KAPT 재컴파일을 포함한다. 기존 컴파일 경고는 변경하거나 숨기지 않았다. CodePointTextSplitterTest 33개, root script lint 통과.
|
||||
- 실제 root task 로그는 가용 추정 12,099MiB/worker1/선택4,537MiB이고 worker 명령에 `-Xmx4537m`이 전달됐다. Java→Kotlin 이동 후에도 기존 public 호출과 실행 시 산정 연결이 작동했다.
|
||||
- 독립 P6 리뷰 APPROVE: 계산식/OS reader/parser·예외·프로세스 종료와 58개 case 보존, static API 및 buildSrc Kotlin 설정을 확인했다. `git diff --check` 통과, 소유 테스트 worker 없음 확인. 노트와 owned temp root를 제거했다.
|
||||
- P6에서 전체 앱 테스트나 실제 Jenkins/AWS 실행은 수행하지 않았다. commit/push도 수행하지 않았다. 기존 P5의 비율 정책과 앱 Kotlin 1.6.21은 유지했다.
|
||||
|
||||
## 커밋 전 검증 (2026-11-19)
|
||||
- 사용자 `/commit-with-validation` 요청으로 P5/P6 변경을 커밋한다.
|
||||
- `./gradlew --no-daemon --offline -p buildSrc test --tests 'buildlogic.TestHeapPolicyTest' --rerun ktlintCheck --console=plain` exit 0/9초. 정책 테스트를 재실행해 XML의 58 tests/0 failures/0 errors/0 skipped를 확인했다. buildSrc lint는 UP-TO-DATE였다.
|
||||
- 이번 커밋 검증에서 root focused test와 실제 Jenkins/AWS 실행은 반복하지 않았다. 전체 앱 테스트도 미실행이며 사용자 실행 명령은 `./gradlew test`다.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 번역 및 관리자 오디오 테스트 수정
|
||||
|
||||
- 작성일: 2026-11-18
|
||||
- 상태: P4 자동 힙 구현·51개 경계 테스트·실제 worker/부족 예산 검증·리뷰 승인·정리 완료. P4 후 전체 재실행은 미수행.
|
||||
- 상태: P6 buildSrc Kotlin 통일 완료. 정책 58개/focused 33개/lint/API/리뷰 통과. 실제 Jenkins와 전체 suite는 P6 후 미실행.
|
||||
- 구현 계획: [plan-task.md](plan-task.md)
|
||||
|
||||
## 목표와 범위
|
||||
@@ -37,3 +37,15 @@
|
||||
- OS의 현재 메모리 관측값에 안전 여유와 JVM 힙 외 메모리 예산을 남기고 동시 worker 수로 나눈다. 기존에 검증한 4GiB를 보수적 실행 하한으로 유지하며, 하한 미달 또는 유효한 관측 불가 시 worker 시작 전에 이유를 알리고 중단한다. 하한은 수학적으로 입증된 최소 필요량이라는 뜻이 아니다.
|
||||
- macOS JDK의 free-only 값은 전체 가용량이 아니므로 회수 가능한 메모리 추정 규칙을 출처와 함께 명시한다. 실행 도중 가용량 변화에 따른 실시간 heap 재조정이나 무제한 할당은 제외한다.
|
||||
- 기존 cache 4개, 50클래스 worker 교체, 동시 worker 1개는 유지한다. 운영 코드 변경, commit/push는 제외한다.
|
||||
|
||||
## 추가 승인: 고정 하한과 고정 예약량 제거
|
||||
- Jenkins가 보고한 `availableBytes=2460004352`를 4GiB 하한 때문에 거부한 뒤, 사용자가 하한도 고정하지 말고 현재 관측값으로 결정하도록 승인했다.
|
||||
- 4GiB 정책 하한과 worker당 고정 1GiB 예약을 제거한다. 전체 관측값의 50%를 worker에 배분하고 그 예산의 25%를 힙 외 용도로 남겨, 나머지 75%를 힙 상한으로 사용한다. worker 수와 MiB 내림을 유지한다.
|
||||
- 정책상의 최소 힙을 임의로 올려 할당하지 않는다. 현재 JDK가 실행 자체를 거부하는 1MiB 이하만 명시적으로 거부한다. 이는 앱 테스트의 필요 힙을 보장하는 하한이 아니다.
|
||||
- OS 관측 구현·기존 cache/fork/parallel 설정은 유지한다. Linux MemAvailable/cgroup 관측 변경, 운영 코드·commit·push는 이번 범위에 포함하지 않는다.
|
||||
|
||||
## 추가 승인: buildSrc Kotlin 통일
|
||||
- 사용자가 힙 정책과 테스트를 프로젝트 관례에 맞게 Kotlin으로 통일하도록 승인했다.
|
||||
- Java helper/test를 Kotlin 소스로 이동하고 중복 Java 파일을 제거한다. 현재 P5 계산식·OS 관측·오류·자원 정리와 58개 테스트 케이스를 보존한다.
|
||||
- buildSrc에는 Gradle 8.1.1에 맞는 `kotlin-dsl`을 적용하고 Java 17/JUnit 5.8.2를 유지한다. 앱의 Kotlin 1.6.21 버전과 운영 코드, root Test 정책은 변경하지 않는다.
|
||||
- public static 호출 호환성과 실제 루트 Gradle 연결을 검증한다. commit/push와 전체 앱 suite 자동 실행은 제외한다.
|
||||
|
||||
@@ -46,14 +46,16 @@
|
||||
|
||||
## 테스트 메모리와 진행 진단
|
||||
- IntelliJ의 `Build, Execution, Deployment > Build Tools > Gradle > Run tests using`을 `Gradle`로 맞추면 CLI와 같은 테스트 JVM 설정을 사용한다. IDE 자체 JUnit runner는 Gradle의 heap/worker 설정을 적용하지 않는다.
|
||||
- 테스트 JVM heap은 Test task 실행 직전에 가용 메모리로 계산한다. 가용 추정의 50%를 유효 동시 worker 수(`min(maxParallelForks, maxWorkers)`)로 나누고 worker마다 힙 외 1GiB를 남긴 뒤 MiB 단위로 내린 값을 명시적 `maxHeapSize`로 전달한다. 계산값이 4GiB 미만이면 올려 할당하지 않고 worker 시작 전에 실패한다. 4GiB는 기존 검증을 유지하는 보수적 실행 하한이며, 실제 최소 필요량을 증명한 수치는 아니다.
|
||||
- 테스트 JVM heap은 Test task 실행 직전에 가용 메모리로 계산한다. 가용 추정의 50%를 유효 동시 worker 수(`min(maxParallelForks, maxWorkers)`)로 나누고, 그 worker 예산의 25%를 힙 외 용도로 남긴다. 나머지 75%를 MiB 단위로 내려 명시적 `maxHeapSize`로 전달한다. 고정 4GiB 정책 하한이나 고정 1GiB 예약은 사용하지 않는다. 단, JVM 실행 자체가 불가능한 2MiB 미만 결과는 상향 보정하지 않고 명시적으로 거부한다.
|
||||
- macOS 가용 추정은 `vm_stat`의 `(Pages free + Pages inactive) × page size`이며 speculative/file-backed를 별도로 더하지 않는다. 다른 OS는 JDK의 free-memory 관측값을 보수적으로 사용하므로 회수 가능한 캐시를 충분히 반영하지 못할 수 있다. 가용 추정은 OS의 할당 보장이 아니며 다른 앱의 이후 사용량도 예측하지 못한다.
|
||||
- 콘솔의 `Test heap:`에서 관측값·유효 worker 수·선택한 상한을 확인한다. task 시작 때 한 번 계산하며 교체된 worker도 동일한 상한을 사용한다. 메모리 부족 오류가 나면 다른 프로그램/중복 테스트를 정리한 뒤 다시 실행한다. 기존 `maxHeapSize`만 지워 Gradle 기본 512MB로 돌아가거나, 비율 옵션만 추가하는 방식은 사용하지 않는다.
|
||||
- 예를 들어 관측값 2,460,004,352 bytes와 worker 1개는 879MiB 힙을 선택한다. 4GiB 미만이라는 이유만으로 중단하지 않지만, 선택된 예산이 앱 테스트의 실제 메모리 요구량보다 작으면 JVM에서 OOM이 발생할 수 있다. 계산 성공을 전체 테스트 통과 보장으로 해석하지 않는다.
|
||||
- 동시 worker 1개, Spring context 캐시 최대 4개, 50개 테스트 클래스마다 worker 교체는 유지한다. 클래스 수 기준이므로 단일 클래스의 과도한 사용까지 방지하지는 않는다. Gradle daemon heap과 테스트 worker heap은 별개다. 같은 저장소의 전체 테스트를 IDE와 CLI/에이전트에서 동시에 시작하지 않는다.
|
||||
- 실행 콘솔의 `Test class:`는 클래스 시작 위치이며 완료 또는 성공 표시가 아니다. 최종 종료 코드와 `build/test-results/test/`의 해당 실행 XML을 함께 확인한다.
|
||||
- GC 로그는 `build/test-gc/<task 이름>/gc-<PID>.log`에 기록한다. PID별 10MB 파일과 회전 로그 최대 3개를 사용한다. 오래된 실행 로그는 조사 후 정리한다.
|
||||
- 후반에 진행이 멈추면 해당 worker PID의 `jstat -gcutil <PID>`와 GC 로그를 확인한다. Old 사용률이 높고 Full GC 시간만 증가하는 상태에서는 실행 제한만 늘리지 않는다. 타인이 시작한 worker는 승인 없이 종료하지 않는다.
|
||||
- 힙 예산 build logic를 변경하면 `./gradlew --no-daemon -p buildSrc test --tests 'buildlogic.TestHeapPolicyTest'`로 산정·파싱 경계를 검증한다. 이 테스트는 애플리케이션의 root `test`와 별도이며, 일반 root 실행에서 buildSrc 컴파일만 됐다고 테스트까지 통과한 것으로 보지 않는다.
|
||||
- 힙 정책과 테스트는 `buildSrc/src/main/kotlin/buildlogic/TestHeapPolicy.kt`, `buildSrc/src/test/kotlin/buildlogic/TestHeapPolicyTest.kt`에 둔다. buildSrc는 Gradle 버전에 맞는 `kotlin-dsl`과 Java 17 toolchain을 사용하며 앱의 Kotlin 버전과 별도로 관리한다. 해당 Kotlin 소스의 포맷 검사는 `./gradlew --no-daemon -p buildSrc ktlintCheck`로 실행한다.
|
||||
|
||||
## AWS 의존성 확인
|
||||
|
||||
|
||||
Reference in New Issue
Block a user