Support using puma if configured via USE_PUMA=true (multithreading)

pull/7457/head
Markus Kahl 5 years ago
parent 2fc4416601
commit 60c29cce82
  1. 3
      Gemfile
  2. 5
      Gemfile.lock
  3. 2
      Procfile
  4. 10
      config/environments/production.rb
  5. 7
      config/puma.rb
  6. 29
      docker/web
  7. 4
      lib/open_project/configuration.rb
  8. 21
      packaging/scripts/web

@ -171,6 +171,8 @@ gem 'sprockets', '~> 3.7.0'
# also, better than thin since we can control worker concurrency.
gem 'unicorn'
gem 'puma', '~> 4.0.0' # used for development and optionally for production
gem 'nokogiri', '~> 1.10.3'
gem 'carrierwave', '~> 1.3.1'
@ -256,7 +258,6 @@ group :development do
end
group :development, :test do
gem 'puma', '~> 3.12.0'
gem 'thin', '~> 1.7.2'
# Tracing and profiling gems

@ -649,7 +649,8 @@ GEM
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
public_suffix (3.0.3)
puma (3.12.0)
puma (4.0.0)
nio4r (~> 2.0)
rabl (0.14.0)
activesupport (>= 2.3.14)
rack (2.0.6)
@ -997,7 +998,7 @@ DEPENDENCIES
pry-rails (~> 0.3.6)
pry-rescue (~> 1.5.0)
pry-stack_explorer (~> 0.4.9.2)
puma (~> 3.12.0)
puma (~> 4.0.0)
rabl (~> 0.14.0)
rack-attack (~> 5.4.2)
rack-mini-profiler

@ -1,4 +1,4 @@
web: bundle exec unicorn --config-file config/unicorn.rb --host ${HOST:="127.0.0.1"} --port ${PORT:="8080"} --env ${RAILS_ENV:="development"}
web: ./packaging/scripts/web
worker: bundle exec rake jobs:work
backup: ./packaging/scripts/backup
check: ./packaging/scripts/check

@ -127,4 +127,14 @@ OpenProject::Application.configure do
config.active_record.dump_schema_after_migration = false
if OpenProject::Configuration.enable_internal_assets_server?
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET, OPTIONS, HEAD',
'Cache-Control' => 'public, s-maxage=31536000, max-age=15552000',
'Expires' => "#{1.year.from_now.to_formatted_s(:rfc822)}"
}
end
end

@ -3,8 +3,9 @@
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 16 }
threads 0, threads_count
threads_min_count = ENV.fetch("RAILS_MIN_THREADS") { 4 }
threads_max_count = ENV.fetch("RAILS_MAX_THREADS") { 16 }
threads threads_min_count, threads_max_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
@ -30,4 +31,4 @@ workers ENV.fetch("WEB_CONCURRENCY") { 1 }
preload_app! if ENV["RAILS_ENV"] == 'production'
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
plugin :tmp_restart unless ENV["RAILS_ENV"] == 'production'

@ -8,15 +8,30 @@ MIN_INSTANCES="${PASSENGER_MIN_INSTANCES:=1}"
MAX_INSTANCES="${PASSENGER_MAX_INSTANCES:=3}"
SPAWN_METHOD="${PASSENGER_SPAWN_METHOD:=smart}"
USE_PUMA="${USE_PUMA:="false"}"
if [ "$RAILS_ENV" = "production" ] && [ "$USE_PUMA" = "true" ]; then
# @TODO Add apache config to serve the assets. Until then we have Puma serve
# them which is slower. This is ok if an asset host is used (SaaS).
# But for self-hosted installations we may want to fix that.
# Passenger does include a config to have nginx serve the assets.
export OPENPROJECT_ENABLE__INTERNAL__ASSETS__SERVER=true
fi
if [ "$MIGRATE" = "true" ]; then
echo "Migrating database..."
bundle exec rake db:migrate
fi
exec bundle exec passenger start \
-p $PORT \
-a "${BIND}" \
--min-instances "$MIN_INSTANCES" \
--max-pool-size "$MAX_INSTANCES" \
--spawn-method "$SPAWN_METHOD" \
--max-preloader-idle-time 0
if [ "$USE_PUMA" ]; then
# see `config/puma.rb` for configuration
bundle exec rails server puma -b $BIND -p $PORT
else
exec bundle exec passenger start \
-p $PORT \
-a "${BIND}" \
--min-instances "$MIN_INSTANCES" \
--max-pool-size "$MAX_INSTANCES" \
--spawn-method "$SPAWN_METHOD" \
--max-preloader-idle-time 0
fi

@ -68,6 +68,8 @@ module OpenProject
'rails_relative_url_root' => '',
'rails_force_ssl' => false,
'rails_asset_host' => nil,
# Enable internal asset server
'enable_internal_assets_server' => false,
# Additional / overridden help links
'force_help_link' => nil,
@ -143,7 +145,7 @@ module OpenProject
# Check for missing migrations in internal errors
'migration_check_on_exceptions' => true,
# Show pending migrations as warning bar
'show_pending_migrations_warning' => true,

@ -0,0 +1,21 @@
#!/bin/bash -e
HOST="${HOST:=127.0.0.1}"
PORT="${PORT:=8080}"
RAILS_ENV="${RAILS_ENV:="development"}"
USE_PUMA="${USE_PUMA:="false"}"
if [ "$RAILS_ENV" = "production" ] && [ "$USE_PUMA" = "true" ]; then
# @TODO Add apache config to serve the assets. Until then we have Puma serve
# them which is slower. This is ok if an asset host is used (SaaS).
# But for self-hosted installations we may want to fix that.
# Passenger does include a config to have nginx serve the assets.
export OPENPROJECT_ENABLE__INTERNAL__ASSETS__SERVER=true
fi
if [ "$USE_PUMA" = "true" ]; then
bundle exec rails server puma -b $HOST -p $PORT
else
bundle exec unicorn --config-file config/unicorn.rb --host $HOST --port $PORT --env $RAILS_ENV
fi
Loading…
Cancel
Save