Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make puma default webserver #481

Merged
merged 3 commits into from
Oct 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ cd /var/vcap/packages/cloud_controller_ng/cloud_controller_ng
export RUBYOPT='--yjit'
<% end %>

<% if link("cloud_controller_internal").p('cc.experimental.use_jemalloc_memory_allocator') %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so
<% end %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so

exec bundle exec rake deployment_updater:start
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ cd /var/vcap/packages/cloud_controller_ng/cloud_controller_ng
export RUBYOPT='--yjit'
<% end %>

<% if link("cloud_controller_internal").p('cc.experimental.use_jemalloc_memory_allocator') %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so
<% end %>

exec bundle exec rake clock:start
22 changes: 9 additions & 13 deletions jobs/cloud_controller_ng/spec
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ provides:
- cc.external_port
- cc.external_protocol
- cc.experimental.use_yjit_compiler
- cc.experimental.use_jemalloc_memory_allocator
- cc.internal_service_hostname
- cc.jobs.enable_dynamic_job_priorities
- cc.log_db_queries
Expand Down Expand Up @@ -224,11 +223,11 @@ provides:
- ssl.skip_cert_verify
- system_domain
- uaa.clients.cc_routing.secret
- cc.experimental.use_puma_webserver
- cc.experimental.use_redis
- cc.app_log_revision
- cc.app_instance_stopping_state
- cc.deprecated_stacks
- cc.temporary_enable_deprecated_thin_webserver

consumes:
- name: database
Expand Down Expand Up @@ -1253,28 +1252,21 @@ properties:
description: "Use Ruby's YJIT compiler when running Cloud Controller API servers and workers. This feature is experimental and not recommended. Please review the drawbacks and benefits of YJIT before enabling."
default: false

cc.experimental.use_jemalloc_memory_allocator:
description: "Enables jemalloc rather than malloc for Cloud Controller API servers and workers; however, it's experimental and not typically recommended, so review its pros and cons before use."
default: false

cc.experimental.use_puma_webserver:
description: "Use Puma in place of Thin as the webserver. This may increase performance as Puma forks Cloud Controller processes to avoid relying on threads"
default: false

cc.experimental.use_redis:
description: "Use co-deployed Valkey (Redis fork) for rate limiting and metrics. If the Puma webserver is enabled, Valkey will automatically be used."
default: false

cc.puma.workers:
description: "Number of workers for Puma webserver."
default: 3
default: 2

cc.puma.max_threads:
description: "Maximum number of threads per Puma webserver worker."
default: 2
default: 10

cc.puma.max_db_connections_per_process:
description: "Maximum database connections for Puma per process (main + Puma workers), if not set the ccng value is used (default)"
description: "Maximum database connections for Puma per process (main + Puma workers)."
default: 10

cc.update_metric_tags_on_rename:
description: "Enable sending a Desired LRP update when an app is renamed"
Expand All @@ -1283,3 +1275,7 @@ properties:
cc.legacy_md5_buildpack_paths_enabled:
description: "Enable legacy MD5 buildpack paths. If disabled, xxhash64 is used for calculating paths in buildpack image layers."
default: false

cc.temporary_enable_deprecated_thin_webserver:
description: "Use deprecated Thin webserver. Please note that when using Thin instead of Puma you miss out on the following benefits: Better resource utilization, well maintained and more performant. Thin will be removed in a future release."
default: false
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ echo 'Finished migrations and seeds'
export RUBYOPT='--yjit'
<% end %>

<% if p('cc.experimental.use_jemalloc_memory_allocator') %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so
<% end %>

exec /var/vcap/packages/cloud_controller_ng/cloud_controller_ng/bin/cloud_controller \
-c /var/vcap/jobs/cloud_controller_ng/config/cloud_controller_ng.yml
2 changes: 0 additions & 2 deletions jobs/cloud_controller_ng/templates/bin/local_worker.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ wait_for_blobstore
export RUBYOPT='--yjit'
<% end %>

<% if p('cc.experimental.use_jemalloc_memory_allocator') %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so
<% end %>

cd /var/vcap/packages/cloud_controller_ng/cloud_controller_ng
exec bundle exec rake "jobs:local[cc_api_worker.<%= spec.job.name %>.<%= spec.index %>.${INDEX}]"
2 changes: 1 addition & 1 deletion jobs/cloud_controller_ng/templates/bpm.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def mount_nfs_volume!(config)
end

def mount_valkey_volume!(config)
if p("cc.experimental.use_puma_webserver") || p("cc.experimental.use_redis")
unless p("cc.temporary_enable_deprecated_thin_webserver") && !p("cc.experimental.use_redis")
config['additional_volumes'] = [] unless config.key?('additional_volumes')
config['additional_volumes'] << {
"path" => "/var/vcap/data/valkey",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local_route: <%= p('cc.nginx.ip') %>
external_port: <%= p("cc.external_port") %>
tls_port: <%= p("cc.tls_port") %>
internal_service_hostname: <%= p("cc.internal_service_hostname") %>
webserver: <%= p("cc.experimental.use_puma_webserver") ? 'puma' : 'thin' %>
webserver: <%= p("cc.temporary_enable_deprecated_thin_webserver") ? 'thin' : 'puma' %>
puma:
workers: <%= p("cc.puma.workers") %>
max_threads: <%= p("cc.puma.max_threads") %>
Expand Down Expand Up @@ -488,7 +488,7 @@ rate_limiter_v2_api:
per_process_admin_limit: <%= (p("cc.rate_limiter_v2_api.admin_limit").to_f/instances).ceil %>
reset_interval_in_minutes: <%= p("cc.rate_limiter_v2_api.reset_interval_in_minutes") %>

<% if p("cc.experimental.use_puma_webserver") || p("cc.experimental.use_redis") %>
<% unless p("cc.temporary_enable_deprecated_thin_webserver") && !p("cc.experimental.use_redis") %>
redis:
socket: "/var/vcap/data/valkey/valkey.sock"
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ wait_for_blobstore
export RUBYOPT='--yjit'
<% end %>

<% if link("cloud_controller_internal").p('cc.experimental.use_jemalloc_memory_allocator') %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so
<% end %>

cd /var/vcap/packages/cloud_controller_ng/cloud_controller_ng

Expand Down
4 changes: 1 addition & 3 deletions jobs/rotate_cc_database_key/templates/bin/run.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

set -eu

<% if link("cloud_controller_internal").p('cc.experimental.use_jemalloc_memory_allocator') %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so
<% end %>
export LD_PRELOAD=/var/vcap/packages/jemalloc/lib/libjemalloc.so

rotate() {
export CLOUD_CONTROLLER_NG_CONFIG=/var/vcap/jobs/rotate_cc_database_key/config/cloud_controller_ng.yml
Expand Down
2 changes: 1 addition & 1 deletion jobs/valkey/monit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
cloud_controller_internal = link("cloud_controller_internal")
if cloud_controller_internal.p("cc.experimental.use_puma_webserver") || cloud_controller_internal.p("cc.experimental.use_redis")
unless cloud_controller_internal.p("cc.temporary_enable_deprecated_thin_webserver") && !cloud_controller_internal.p("cc.experimental.use_redis")
%>

check process valkey
Expand Down
57 changes: 32 additions & 25 deletions spec/cloud_controller_ng/bpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,40 @@ def valkey_volume_mounted?(process)
end
end

context 'when the puma webserver is used' do
it 'mounts the valkey volume into the ccng job container' do
template_hash = YAML.safe_load(template.render({ 'cc' => { 'experimental' => { 'use_puma_webserver' => true } } }, consumes: {}))

results = template_hash['processes'].select { |p| p['name'].include?('cloud_controller_ng') }
expect(results.length).to eq(1)
expect(valkey_volume_mounted?(results[0])).to be_truthy
describe 'valkey config' do
context 'when the puma webserver is used' do
it 'mounts the valkey volume into the ccng job container' do
template_hash = YAML.safe_load(template.render({}, consumes: {}))

results = template_hash['processes'].select { |p| p['name'].include?('cloud_controller_ng') }
expect(results.length).to eq(1)
expect(valkey_volume_mounted?(results[0])).to be_truthy
end
end
end

context "when 'cc.experimental.use_redis' is set to 'true'" do
it 'mounts the valkey volume into the ccng job container' do
template_hash = YAML.safe_load(template.render({ 'cc' => { 'experimental' => { 'use_redis' => true } } }, consumes: {}))

results = template_hash['processes'].select { |p| p['name'].include?('cloud_controller_ng') }
expect(results.length).to eq(1)
expect(valkey_volume_mounted?(results[0])).to be_truthy
end
end

context "when neither the puma webserver is used nor 'cc.experimental.use_redis' is set to 'true'" do
it 'does not mount the valkey volume into the ccng job container' do
template_hash = YAML.safe_load(template.render({}, consumes: {}))

results = template_hash['processes'].select { |p| p['name'].include?('cloud_controller_ng') }
expect(results.length).to eq(1)
expect(valkey_volume_mounted?(results[0])).to be_falsey
context 'when thin webserver is used' do
context "when 'cc.experimental.use_redis' is set to 'true'" do
it 'mounts the valkey volume into the ccng job container' do
template_hash = YAML.safe_load(
template.render({ 'cc' => { 'temporary_enable_deprecated_thin_webserver' => true,
'experimental' => { 'use_redis' => true } } }, consumes: {})
)

results = template_hash['processes'].select { |p| p['name'].include?('cloud_controller_ng') }
expect(results.length).to eq(1)
expect(valkey_volume_mounted?(results[0])).to be_truthy
end
end

context "when 'cc.experimental.use_redis' is not set'" do
it 'mounts the valkey volume into the ccng job container' do
template_hash = YAML.safe_load(template.render({ 'cc' => { 'temporary_enable_deprecated_thin_webserver' => true } }, consumes: {}))

results = template_hash['processes'].select { |p| p['name'].include?('cloud_controller_ng') }
expect(results.length).to eq(1)
expect(valkey_volume_mounted?(results[0])).to be_falsey
end
end
end
end
end
Expand Down
26 changes: 15 additions & 11 deletions spec/cloud_controller_ng/cloud_controller_ng_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module Test
'private_endpoint' => 'https://blobstore.service.cf.internal:4443',
'public_endpoint' => 'https://blobstore.brook-sentry.capi.land',
'username' => 'blobstore-user' } },
'experimental' => {},
'install_buildpacks' =>
[{ 'name' => 'staticfile_buildpack', 'package' => 'staticfile-buildpack' },
{ 'name' => 'java_buildpack', 'package' => 'java-buildpack' },
Expand Down Expand Up @@ -570,24 +571,27 @@ module Test
describe 'valkey config' do
context 'when the puma webserver is used' do
it 'renders the valkey socket into the ccng config' do
merged_manifest_properties['cc']['experimental'] = { 'use_puma_webserver' => true }
template_hash = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
expect(template_hash['redis']['socket']).to eq('/var/vcap/data/valkey/valkey.sock')
end
end

context "when 'cc.experimental.use_redis' is set to 'true'" do
it 'renders the redis socket into the ccng config' do
merged_manifest_properties['cc']['experimental'] = { 'use_redis' => true }
template_hash = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
expect(template_hash['redis']['socket']).to eq('/var/vcap/data/valkey/valkey.sock')
context 'when thin webserver is used' do
context "when 'cc.experimental.use_redis' is set to 'true'" do
it 'renders the valkey socket into the ccng config' do
merged_manifest_properties['cc']['temporary_enable_deprecated_thin_webserver'] = true
merged_manifest_properties['cc']['experimental']['use_redis'] = true
template_hash = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
expect(template_hash['redis']['socket']).to eq('/var/vcap/data/valkey/valkey.sock')
end
end
end

context "when neither the puma webserver is used nor 'cc.experimental.use_redis' is set to 'true'" do
it 'does not render the redis socket into the ccng config' do
template_hash = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
expect(template_hash).not_to have_key('redis')
context "when 'cc.experimental.use_redis' is not set'" do
it 'does not render the valkey socket into the ccng config' do
merged_manifest_properties['cc']['temporary_enable_deprecated_thin_webserver'] = true
template_hash = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
expect(template_hash).not_to have_key('redis')
end
end
end
end
Expand Down
27 changes: 15 additions & 12 deletions spec/valkey/monit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,35 @@ module Test
let(:job) { release.job('valkey') }
let(:spec) { job.instance_variable_get(:@spec) }
let(:job_path) { job.instance_variable_get(:@job_path) }
let(:cc_internal_properties) { { 'cc' => { 'experimental' => { 'use_puma_webserver' => false, 'use_redis' => false } } } }
let(:cc_internal_properties) { { 'cc' => { 'temporary_enable_deprecated_thin_webserver' => false, 'experimental' => { 'use_redis' => false } } } }
let(:link) { Link.new(name: 'cloud_controller_internal', properties: cc_internal_properties) }

describe 'monit' do
let(:template) { Template.new(spec, File.join(job_path, 'monit')) }

context 'when the puma webserver is used' do
it 'renders the monit directives' do
cc_internal_properties['cc']['experimental']['use_puma_webserver'] = true
result = template.render({}, consumes: [link])
expect(result).to include('check process valkey')
end
end

context "when 'cc.experimental.use_redis' is set to 'true'" do
it 'renders the monit directives' do
cc_internal_properties['cc']['experimental']['use_redis'] = true
result = template.render({}, consumes: [link])
expect(result).to include('check process valkey')
context 'when thin webserver is used' do
context "when 'cc.experimental.use_redis' is set to 'true'" do
it 'renders the monit directives' do
cc_internal_properties['cc']['temporary_enable_deprecated_thin_webserver'] = true
cc_internal_properties['cc']['experimental']['use_redis'] = true
result = template.render({}, consumes: [link])
expect(result).to include('check process valkey')
end
end
end

context "when neither the puma webserver is used nor 'cc.experimental.use_redis' is set to 'true'" do
it 'does not render the monit directives' do
result = template.render({}, consumes: [link])
expect(result.strip).to eq('')
context "when 'cc.experimental.use_redis' is set to 'false'" do
it 'does not render the monit directives' do
cc_internal_properties['cc']['temporary_enable_deprecated_thin_webserver'] = true
result = template.render({}, consumes: [link])
expect(result.strip).to eq('')
end
end
end
end
Expand Down