Repository navigation
Add server.gc_initial_heap_mib to start the GC heap at a set size - #1452
Conversation
The server grows Boehm GC's heap to server.gc_initial_heap_mib MiB in each server process before it takes requests (GC_expand_hp, part of bdwgc's public API). 0, the default, keeps the collector's own starting size. AMBER_SERVER_GC_INITIAL_HEAP_MIB overrides it, and validate! rejects a negative value.
|
Heap sweep result (generated |
What
A typed server setting,
server.gc_initial_heap_mib(default 0), with theAMBER_SERVER_GC_INITIAL_HEAP_MIBoverride.Amber::Server#startgrows Boehm GC's heap to that many MiB before it takes requests, in every server process (workers started byrunreachstarttoo).Amber::Server::GrowHeapToStartingSizecallsGC_expand_hpfor the missing bytes. Crystal'sLibGCdoes not bind it, so Amber binds it in its ownlib LibAmberGC(no change to stdlib).GC_expand_hpis part of bdwgc's public API ingc.hon macOS, Linux and Windows; libgc is already linked by the runtime. Under-Dgc_nonethe step does nothing.GC_INITIAL_HEAP_SIZEis set) is left alone, and 0 keeps the collector's own starting size, so existing apps see no change.validate!rejects a negative value.docs/guides/configuration.md(server section, validation rules, env table).Why
A full-app A/B of a generated
amber new -d sqliteapp (beta.10 against the beta.11 PR set) showed POST /posts p50 +0.119 ms (2.088 -> 2.207 ms) while peak memory fell from 234 MiB to 25 MiB: the beta.11 app collects a small heap more often. With a 256 MiB starting heap on both sides, beta.11 won every POST metric. The amber_cli companion PR (amberframework/amber_cli#56) writesgc_initial_heap_mib: 16into every generated environment file; the heap sweep that picks 16 MiB is summarized there and in a comment here.Specs
spec/amber/server/grow_heap_to_starting_size_spec.cr: grows the heap to the starting size; leaves a heap that is already large enough; does nothing for 0.server_config_spec.cr: default 0, YAML read, negative value rejected, 0 accepted.env_override_spec.cr:AMBER_SERVER_GC_INITIAL_HEAP_MIB.Local (crystal-alpha 1.21.0, macOS arm64): the three spec files pass (95 examples, 0 failures);
scripts/check_beta_contract.shpasses;crystal tool format --checkis clean; the spec compiles with-Dgc_none.The CHANGELOG line belongs in the beta.11 section that #1451 starts, so it is left out here to avoid a conflict.