[Git][noosfero/noosfero][master] Add puma configuration with Noosfero daemons

Bráulio Bhavamitra gitlab at mg.gitlab.com
Wed Mar 15 20:21:24 BRT 2017


Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero


Commits:
d91cb056 by Braulio Bhavamitra at 2017-03-15T20:20:45-03:00
Add puma configuration with Noosfero daemons

- - - - -


3 changed files:

- config/database.yml.pgsql
- − config/database.yml.sqlite3
- + config/puma.rb


Changes:

=====================================
config/database.yml.pgsql
=====================================
--- a/config/database.yml.pgsql
+++ b/config/database.yml.pgsql
@@ -15,6 +15,7 @@ development:
   template: template0
   username: noosfero
   password:
+  pool: 20
 
   # Connect on a TCP socket. Omitted by default since the client uses a
   # domain socket that doesn't need configuration. Windows does not have
@@ -49,6 +50,7 @@ production:
   template: template0
   username: noosfero
   password:
+  pool: 20
 
 cucumber:
   <<: *TEST


=====================================
config/database.yml.sqlite3 deleted
=====================================
--- a/config/database.yml.sqlite3
+++ /dev/null
@@ -1,16 +0,0 @@
-development:
-  adapter: sqlite3
-  database: db/development.db
-  timeout: 500
-
-test: &TEST
-  adapter: sqlite3
-  database: db/test.db
-  timeout: 2000
-
-production:
-  adapter: sqlite3
-  database: db/production.db
-
-cucumber:
-  <<: *TEST


=====================================
config/puma.rb
=====================================
--- /dev/null
+++ b/config/puma.rb
@@ -0,0 +1,78 @@
+RailsRoot      = Dir.pwd
+BindPort       = 3000
+Production     = if ENV['RAILS_ENV'] == 'production' then true else false end
+
+Workers        = 2
+Threads        = 16 # db pool must be higher than this
+
+WorkerKiller   = true
+WorkerMaxMem   = 256*2
+
+DaemonPriority = -5
+WorkerDaemons  = {
+  delayed_job: {
+    worker_nr: 0,
+    run:       -> do
+      require 'delayed_job'
+      worker = Delayed::Worker.new
+      worker.name_prefix = 'puma worker 0'
+      worker.start
+    end,
+  },
+  feed_updater: {
+    worker_nr: 0,
+    run:       -> do
+      FeedUpdater.new.run
+    end,
+  },
+}
+
+preload_app!
+
+directory       RailsRoot
+pidfile         "#{RailsRoot}/tmp/pids/puma.pid"
+bind            "unix://#{RailsRoot}/run/puma.sock" if Production
+bind            "tcp://0.0.0.0:#{BindPort}" unless Production
+stdout_redirect "#{RailsRoot}/log/puma.stdout.log", "#{RailsRoot}/log/puma.stderr.log", true if Production
+
+workers Workers
+threads 0,Threads
+
+before_fork do
+  if WorkerKiller
+    begin
+      require 'puma_worker_killer'
+      PumaWorkerKiller.config do |config|
+        config.ram           = Workers * WorkerMaxMem # mb
+        config.frequency     = 15                     # seconds
+        config.percent_usage = 0.90
+        config.rolling_restart_frequency = 12 * 3600  # 12 hours in seconds
+      end
+      PumaWorkerKiller.start
+    rescue LoadError
+      puts 'Add `puma_worker_killer` to `config/Gemfile` to use worker killer'
+    end
+  end
+end
+
+after_worker_fork do |worker_nr|
+  begin
+    ActiveRecord::Base.establish_connection
+  rescue
+    retry #if this fail it will stop worker killer
+  end
+
+  WorkerDaemons.each do |daemon, opts|
+    next unless opts[:worker_nr] == worker_nr
+    t = Thread.new do
+      sleep 2
+      begin
+        puts "#{worker_nr}: #{daemon}: starting"
+        opts[:run].call
+      rescue => e
+        puts "#{worker_nr}: #{daemon}: failed: #{e.class} #{e.message}"
+      end
+    end
+    t.priority = DaemonPriority
+  end
+end



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/d91cb0563bed4ad59980f043e40376b1c2338be2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170315/47a5ced5/attachment-0001.html>


More information about the Noosfero-dev mailing list