struct Amber::Server::GrowHeapToStartingSize

Overview

Grows the garbage collector's heap to the starting size an app sets in server.gc_initial_heap_mib, before the server takes its first request.

Boehm GC starts with a heap of a few hundred KiB and decides how often to collect from the heap it has, so a server that starts small collects often under load until the heap has grown. A starting heap of a few tens of MiB removes that early collection cost; memory the program never touches is reserved address space, not resident memory.

It only grows the heap: a heap that is already at least that large, for example because GC_INITIAL_HEAP_SIZE was set, is left as it is.

Amber::Server::GrowHeapToStartingSize.new(starting_heap_mib: 32).perform
GC.stats.heap_size # => at least 33_554_432

Defined in:

amber/server/grow_heap_to_starting_size.cr

Constant Summary

BYTES_PER_MIB = 1048576_u64

Constructors

Instance Method Summary

Constructor Detail

def self.new(starting_heap_mib : Int32) #

[View source]

Instance Method Detail

def perform : UInt64 #

Returns how many bytes the heap grew by. That is 0 when no starting size is set, when the heap is already that large, when the program is built without a collector (-Dgc_none), and when the collector could not obtain the memory, which is logged as a warning.


[View source]
def starting_heap_mib : Int32 #

[View source]