Skip to content

Commit 4acd6f4

Browse files
committed
Increase compose service default memory
1 parent 5976f38 commit 4acd6f4

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

Plugins/container-compose/Sources/Core/Orchestrator/Orchestrator.swift

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ public struct DefaultVolumePopulator: VolumePopulator {
527527
/// )
528528
/// ```
529529
public actor Orchestrator {
530+
static let defaultServiceMemoryInBytes: UInt64 = 6144.mib()
531+
530532
public enum PullPolicy: String, Sendable {
531533
case always
532534
case missing
@@ -1276,22 +1278,7 @@ public actor Orchestrator {
12761278
if let cpus = service.cpus {
12771279
config.resources.cpus = Int(cpus) ?? 4
12781280
}
1279-
if let memStr = service.memory, !memStr.isEmpty {
1280-
do {
1281-
if memStr.lowercased() == "max" {
1282-
// Treat "max" as no override: keep the runtime/default value (set below if needed).
1283-
// Intentionally do nothing here.
1284-
} else {
1285-
let res = try Parser.resources(cpus: nil, memory: memStr)
1286-
if let bytes = res.memoryInBytes as UInt64? { config.resources.memoryInBytes = bytes }
1287-
}
1288-
} catch {
1289-
log.warning("Invalid memory value '\\(memStr)'; using default. Error: \\(error)")
1290-
}
1291-
} else {
1292-
// Safer default for dev servers (was 1 GiB)
1293-
config.resources.memoryInBytes = 2048.mib()
1294-
}
1281+
config.resources.memoryInBytes = resolvedMemoryLimit(for: service)
12951282

12961283
labels["com.apple.container.compose.config-hash"] = computeConfigHash(
12971284
project: project,
@@ -1307,6 +1294,27 @@ public actor Orchestrator {
13071294
return config
13081295
}
13091296

1297+
func resolvedMemoryLimit(for service: Service) -> UInt64 {
1298+
guard let memStr = service.memory, !memStr.isEmpty else {
1299+
return Self.defaultServiceMemoryInBytes
1300+
}
1301+
1302+
do {
1303+
if memStr.lowercased() == "max" {
1304+
return Self.defaultServiceMemoryInBytes
1305+
}
1306+
1307+
let res = try Parser.resources(cpus: nil, memory: memStr)
1308+
if let bytes = res.memoryInBytes as UInt64? {
1309+
return bytes
1310+
}
1311+
} catch {
1312+
log.warning("Invalid memory value '\\(memStr)'; using default. Error: \\(error)")
1313+
}
1314+
1315+
return Self.defaultServiceMemoryInBytes
1316+
}
1317+
13101318
private func publishSpec(from port: PortMapping) -> String {
13111319
let protoSuffix = port.portProtocol == "tcp" ? "" : "/\(port.portProtocol)"
13121320
if let hostIP = port.hostIP, !hostIP.isEmpty {

Plugins/container-compose/Tests/ComposeTests/OrchestratorBuildTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ struct OrchestratorBuildTests {
164164
#expect(networking.attachments[0].options.hostname == "service-1.compose.test.")
165165
}
166166

167+
@Test
168+
func testResolvedMemoryLimitDefaultsToSixGiBWhenUnspecified() async throws {
169+
let orchestrator = Orchestrator(log: log)
170+
let service = Service(name: "frontend", image: "resq-fullstack:dev")
171+
172+
let memory = await orchestrator.resolvedMemoryLimit(for: service)
173+
174+
#expect(memory == 6144.mib())
175+
}
176+
177+
@Test
178+
func testResolvedMemoryLimitUsesExplicitComposeValue() async throws {
179+
let orchestrator = Orchestrator(log: log)
180+
let service = Service(name: "frontend", image: "resq-fullstack:dev", memory: "2g")
181+
182+
let memory = await orchestrator.resolvedMemoryLimit(for: service)
183+
184+
#expect(memory == 2048.mib())
185+
}
186+
167187
@Test
168188
func testOrchestratorCleanupFunctionality() async throws {
169189
// Test that the orchestrator can be created and basic functionality works

0 commit comments

Comments
 (0)