Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions spec/commands/new_command_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ describe AmberCLI::Commands::NewCommand do
production["session"]["expires"].as_i.should eq(1_209_600)
production["static"]["headers"]["Cache-Control"].as_s.should eq("no-cache")

AmberCLI::Commands::NewCommand::GC_INITIAL_HEAP_MIB.should be > 0
%w[development test production].each do |environment_name|
environment = YAML.parse(File.read(File.join(destination, "config/environments/#{environment_name}.yml")))
environment["server"]["gc_initial_heap_mib"].as_i.should eq(AmberCLI::Commands::NewCommand::GC_INITIAL_HEAP_MIB)
end
File.read(File.join(destination, "README.md")).should contain("server.gc_initial_heap_mib")

routes = File.read(File.join(destination, "config/routes.cr"))
lean_block = routes[routes.index!("pipeline :lean_read do")...routes.index!("pipeline :web do")]
lean_block.should contain("Amber::Pipe::Error.new")
Expand Down
13 changes: 13 additions & 0 deletions src/amber_cli/commands/new_command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ module AmberCLI::Commands
VALID_DATABASES = %w[pg mysql sqlite]
VALID_TEMPLATES = %w[ecr]

# Starting garbage-collector heap, in MiB, written to `server.gc_initial_heap_mib`
# in every generated environment file. 16 MiB is the smallest starting heap that
# kept POST p50 at or below beta.10 in a generated app (4 and 8 MiB did not); it
# adds about 8 MiB of peak memory on a small JSON route.
GC_INITIAL_HEAP_MIB = 16

getter database : String = "sqlite"
getter template : String = "ecr"
getter app_type : String = "web"
Expand Down Expand Up @@ -504,6 +510,10 @@ only the error and security-header pipes. Forms and anything else that needs a
session stay on the `web` pipeline, with the session, flash and CSRF pipes. To
give a page a session, move its route to `routes :web`.

The garbage collector starts with a #{GC_INITIAL_HEAP_MIB} MiB heap (`server.gc_initial_heap_mib`
in `config/environments/*.yml`, or `AMBER_SERVER_GC_INITIAL_HEAP_MIB`), so a busy server
does not collect over and over while its heap grows. 0 keeps the collector's own size.

Production writes no per-request log line. The edge proxy keeps access logs. The
`Amber::Pipe::Logger` lines in `config/routes.cr` show where to turn it back on.

Expand Down Expand Up @@ -784,6 +794,9 @@ server:
host: #{host}
port: 3000
secret_key_base: "#{secret}"
# The garbage collector starts with this much heap (MiB), so a busy server does not
# collect over and over while its heap grows. 0 keeps the collector's own few hundred KiB.
gc_initial_heap_mib: #{GC_INITIAL_HEAP_MIB}

database:
url: "#{database_url}"
Expand Down
Loading