Change default number of Puma workers to 2

This commit is contained in:
Eugene Burmakin 2024-11-20 22:00:24 +01:00
parent 6b4da57f3d
commit 55e24f3adb
5 changed files with 43 additions and 18 deletions

View file

@ -1 +1 @@
0.16.7
0.16.8

View file

@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# 0.16.8 - 2024-11-20
### Changed
- Default number of Puma workers is now 2 instead of 1. This should improve the performance of the application. If you have a lot of users, you might want to increase the number of workers. You can do this by setting the `WEB_CONCURRENCY` env var in your `docker-compose.yml` file. Example:
```diff
dawarich_app:
image: freikin/dawarich:latest
container_name: dawarich_app
environment:
...
WEB_CONCURRENCY: "2"
```
# 0.16.7 - 2024-11-20
### Changed

View file

@ -1,12 +1,15 @@
# in config/initializers/prometheus.rb
if Rails.env != "test" && ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
# frozen_string_literal: true
if !Rails.env.test? && ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
require 'prometheus_exporter/middleware'
require 'prometheus_exporter/instrumentation'
# This reports stats per request like HTTP status and timings
Rails.application.middleware.unshift PrometheusExporter::Middleware
# this reports basic process stats like RSS and GC info, type master
# means it is instrumenting the master process
PrometheusExporter::Instrumentation::Process.start(type: "master")
# this reports basic process stats like RSS and GC info
PrometheusExporter::Instrumentation::Process.start(type: 'web')
# Add ActiveRecord instrumentation
PrometheusExporter::Instrumentation::ActiveRecord.start
end

View file

@ -3,9 +3,9 @@
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'] }
require 'prometheus_exporter/instrumentation'
if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
require 'prometheus_exporter/instrumentation'
config.server_middleware do |chain|
chain.add PrometheusExporter::Instrumentation::Sidekiq
end

View file

@ -6,7 +6,7 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count
@ -17,14 +17,14 @@ worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch('PORT') { 3000 }
port ENV.fetch('PORT', 3000)
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch('RAILS_ENV') { 'development' }
environment ENV.fetch('RAILS_ENV', 'development')
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
@ -32,24 +32,31 @@ pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
workers ENV.fetch('WEB_CONCURRENCY', 2)
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!
preload_app!
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart
# Prometheus exporter
#
# optional check, avoids spinning up and down threads per worker
if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
require 'prometheus_exporter/instrumentation'
PrometheusExporter::Instrumentation::Puma.start unless PrometheusExporter::Instrumentation::Puma.started?
before_fork do
PrometheusExporter::Client.default = PrometheusExporter::Client.new(
host: ENV.fetch('PROMETHEUS_EXPORTER_HOST', '0.0.0.0'),
port: ENV.fetch('PROMETHEUS_EXPORTER_PORT', 9394)
)
end
on_worker_boot do
require 'prometheus_exporter/instrumentation'
PrometheusExporter::Instrumentation::Puma.start
end
end