Skip to content

Commit

Permalink
Replace Clockwork with Sidetiq
Browse files Browse the repository at this point in the history
  • Loading branch information
stephankaag committed Aug 14, 2013
1 parent aec929b commit a6b4b5d
Show file tree
Hide file tree
Showing 44 changed files with 106 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .procfile.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
###

# This specifies how many of each task to run
concurrency: web=2,sidekiq=1,clockwork=1
concurrency: web=2,sidekiq=1

# Define the port range to use, must be in multiples of 1000
port: 3000
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ gem 'simple_handlebars_rails', path: 'vendor/gems/simple_handlebars_rails'

gem 'redcarpet', require: false
gem 'airbrake', '3.1.2', require: false # errbit is broken with 3.1.3 for now
gem 'clockwork', require: false
gem 'sidetiq', '>= 0.3.6'
gem 'eventmachine'
gem 'fast_xs'
gem 'fast_xor', git: 'https://github.com/CodeMonkeySteve/fast_xor.git'
Expand Down
26 changes: 14 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,13 @@ GEM
bourne (1.4.0)
mocha (~> 0.13.2)
builder (3.0.4)
celluloid (0.13.0)
celluloid (0.14.1)
timers (>= 1.0.0)
certified (0.1.1)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
clockwork (0.5.0)
tzinfo (~> 0.3.35)
coderay (1.0.9)
connection_pool (1.0.0)
connection_pool (1.1.0)
daemons (1.1.9)
debug_inspector (0.0.2)
diff-lcs (1.2.4)
Expand Down Expand Up @@ -213,6 +211,7 @@ GEM
hiredis (0.4.5)
httpauth (0.2.0)
i18n (0.6.4)
ice_cube (0.11.0)
image_optim (0.8.0)
fspath (~> 2.0.3)
image_size (~> 1.1.2)
Expand Down Expand Up @@ -244,7 +243,7 @@ GEM
mocha (0.13.3)
metaclass (~> 0.0.1)
mock_redis (0.8.1)
multi_json (1.7.7)
multi_json (1.7.8)
multipart-post (1.2.0)
mustache (0.99.4)
net-scp (1.1.2)
Expand Down Expand Up @@ -349,7 +348,7 @@ GEM
redis-activesupport (3.2.3)
activesupport (~> 3.2.3)
redis-store (~> 1.1.0)
redis-namespace (1.2.1)
redis-namespace (1.3.1)
redis (~> 3.0.0)
redis-rack (1.4.2)
rack (~> 1.4.1)
Expand Down Expand Up @@ -401,17 +400,20 @@ GEM
shoulda-matchers (1.5.6)
activesupport (>= 3.0.0)
bourne (~> 1.3)
sidekiq (2.11.1)
celluloid (~> 0.13.0)
connection_pool (~> 1.0)
multi_json (~> 1)
redis (~> 3)
sidekiq (2.13.0)
celluloid (>= 0.14.1)
connection_pool (>= 1.0.0)
json
redis (>= 3.0)
redis-namespace
sidekiq-failures (0.1.0)
sidekiq (>= 2.2.1)
sinatra
slim
sprockets
sidetiq (0.3.6)
ice_cube (~> 0.11.0)
sidekiq (~> 2.13.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
Expand Down Expand Up @@ -468,7 +470,6 @@ DEPENDENCIES
better_errors
binding_of_caller
certified
clockwork
diffy (>= 3.0)
discourse_emoji!
discourse_plugin!
Expand Down Expand Up @@ -537,6 +538,7 @@ DEPENDENCIES
shoulda
sidekiq
sidekiq-failures
sidetiq (>= 0.3.6)
simple_handlebars_rails!
simplecov
sinatra
Expand Down
11 changes: 6 additions & 5 deletions Gemfile_rails4.lock
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ GEM
celluloid (0.14.1)
timers (>= 1.0.0)
certified (0.1.1)
clockwork (0.5.3)
activesupport (~> 4.0.0)
tzinfo (~> 0.3.35)
coderay (1.0.9)
connection_pool (1.1.0)
daemons (1.1.9)
Expand Down Expand Up @@ -254,6 +251,7 @@ GEM
hiredis (0.4.5)
httpauth (0.2.0)
i18n (0.6.4)
ice_cube (0.11.0)
image_optim (0.8.1)
fspath (~> 2.0.3)
image_size (~> 1.1.2)
Expand Down Expand Up @@ -370,7 +368,7 @@ GEM
ffi (>= 0.5.0)
redcarpet (3.0.0)
redis (3.0.4)
redis-namespace (1.3.0)
redis-namespace (1.3.1)
redis (~> 3.0.0)
redis-store (1.1.2)
redis (>= 2.2.0)
Expand Down Expand Up @@ -419,6 +417,9 @@ GEM
redis-namespace
sidekiq-failures (0.2.1)
sidekiq (>= 2.2.1)
sidetiq (0.3.6)
ice_cube (~> 0.11.0)
sidekiq (~> 2.13.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
Expand Down Expand Up @@ -481,7 +482,6 @@ DEPENDENCIES
better_errors
binding_of_caller
certified
clockwork
diffy (>= 3.0)
discourse_emoji!
discourse_plugin!
Expand Down Expand Up @@ -550,6 +550,7 @@ DEPENDENCIES
shoulda
sidekiq
sidekiq-failures
sidetiq (>= 0.3.6)
simple_handlebars_rails!
simplecov
sinatra
Expand Down
3 changes: 1 addition & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
web: bundle exec rails server -p $PORT
sidekiq: bundle exec sidekiq -e $RAILS_ENV
clockwork: bundle exec clockwork config/clock.rb
sidekiq: bundle exec sidekiq -e $RAILS_ENV
8 changes: 2 additions & 6 deletions app/models/admin_dashboard_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def problems
[ rails_env_check,
host_names_check,
gc_checks,
sidekiq_check || queue_size_check || clockwork_check,
sidekiq_check || queue_size_check,
ram_check,
facebook_config_check,
twitter_config_check,
Expand Down Expand Up @@ -72,7 +72,7 @@ def as_json
end

def self.recalculate_interval
# Could be configurable, but clockwork + multisite need to support it.
# Could be configurable, multisite need to support it.
30 # minutes
end

Expand All @@ -93,10 +93,6 @@ def sidekiq_check
I18n.t('dashboard.sidekiq_warning') if Jobs.queued > 0 and (last_job_performed_at.nil? or last_job_performed_at < 2.minutes.ago)
end

def clockwork_check
I18n.t('dashboard.clockwork_warning') unless Jobs::ClockworkHeartbeat.is_clockwork_running?
end

def queue_size_check
queue_size = Jobs.queued
I18n.t('dashboard.queue_size_warning', queue_size: queue_size) unless queue_size < 100
Expand Down
9 changes: 0 additions & 9 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,6 @@ class Application < Rails::Application
# So open id logs somewhere sane
config.after_initialize do
OpenID::Util.logger = Rails.logger

if ENV['EMBED_CLOCKWORK']
puts ">> Running clockwork in background thread"
require_relative "clock"

Thread.new do
Clockwork.run
end
end
end
end
end
39 changes: 0 additions & 39 deletions config/clock.rb

This file was deleted.

20 changes: 0 additions & 20 deletions config/deploy.rb.sample
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,6 @@ end

after "deploy:setup", "config:nginx"

# Tasks to start/stop/restart a daemonized clockwork instance
namespace :clockwork do
desc "Start clockwork"
task :start, :roles => [:app] do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec clockworkd -c #{current_path}/config/clock.rb --pid-dir #{shared_path}/pids --log --log-dir #{shared_path}/log start"
end

task :stop, :roles => [:app] do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec clockworkd -c #{current_path}/config/clock.rb --pid-dir #{shared_path}/pids --log --log-dir #{shared_path}/log stop"
end

task :restart, :roles => [:app] do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec clockworkd -c #{current_path}/config/clock.rb --pid-dir #{shared_path}/pids --log --log-dir #{shared_path}/log restart"
end
end

after "deploy:stop", "clockwork:stop"
after "deploy:start", "clockwork:start"
before "deploy:restart", "clockwork:restart"

# Seed your database with the initial production image. Note that the production
# image assumes an empty, unmigrated database.
namespace :db do
Expand Down
24 changes: 3 additions & 21 deletions config/discourse.pill.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a

# getting this to work was a nightmare
# bundle exec spawns a process totally messing with the demonize option
# so we suck the environment out and set it up first
# so we suck the environment out and set it up first
bootup_bundle = [ "#{ENV['HOME']}/.rvm/bin/rvm/bootup_bundle",
"/usr/local/rvm/bin/rvm/bootup_bundle",
`which bootup_bundle`.strip,
Expand Down Expand Up @@ -68,7 +68,7 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
end
end

#debug instance
#debug instance
# app.process("thin-debug") do |process|
# process.start_command = "bundle exec thin start -e development -t 0 -p 10040 -P #{rails_root}/tmp/pids/thin-debug.pid -l #{rails_root}/log/thin-debug.log" -d"
# process.pid_file = "#{rails_root}/tmp/pids/thin-debug.pid"
Expand All @@ -85,7 +85,7 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
app.process("sidekiq-worker") do |process|
pidfile = "#{rails_root}/tmp/pids/sidekiq-worker.pid"

process.start_command = "/usr/bin/env PIDFILE=#{pidfile} RAILS_ENV=#{rails_env} bundle exec sidekiq -L #{rails_root}/log/sidekiq.log"
process.start_command = "/usr/bin/env PIDFILE=#{pidfile} RAILS_ENV=#{rails_env} bundle exec sidekiq -L #{rails_root}/log/sidekiq.log"
process.pid_file = pidfile
process.start_grace_time = 30.seconds
process.stop_grace_time = 10.seconds
Expand All @@ -95,23 +95,5 @@ Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |a
process.daemonize = true
end

# Perhaps you want to run `hostname -f` here? It depends on your environment
# In any case, ensure the output is what you expect it to be on the system
# running clockwork!
if `hostname -s`.strip == "host to run on"
app.process("clockwork") do |process|
pidfile = "#{rails_root}/tmp/pids/clockwork.pid"

process.start_command = "/usr/bin/env CLOCK_LOG=#{rails_root}/log/clockwork.log RAILS_ENV=#{rails_env} bundle exec clockwork config/clock.rb"
process.pid_file = pidfile
process.start_grace_time = 30.seconds
process.stop_grace_time = 10.seconds
process.restart_grace_time = 10.seconds
process.uid = user
process.gid = group
process.daemonize = true
end
end

end

6 changes: 5 additions & 1 deletion config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
sidekiq_redis = { url: $redis.url, namespace: 'sidekiq' }

Sidekiq.configure_server { |config| config.redis = sidekiq_redis }
Sidekiq.configure_server do |config|
config.redis = sidekiq_redis
Sidetiq::Clock.start!
end

Sidekiq.configure_client { |config| config.redis = sidekiq_redis }

Sidekiq.logger.level = Logger::WARN
1 change: 0 additions & 1 deletion config/locales/server.cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ cs:
rails_env_warning: "Váš server běží v módu %{env}."
host_names_warning: "Vaše konfigurace v souboru config/database.yml používá 'localhost' jako jméno hostitele. Změňte toto nastavení na doménu vašeho webu."
gc_warning: 'Váš server používá výchozí nastavení ruby garbage collectoru, což způsobuje snížený výkon. Přečtěte si toto téma ohledně ladění výkonu: <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126">Tuning Ruby and Rails for Discourse</a>.'
clockwork_warning: 'Clockwork neběží. Ujistěte se, že process clockwork vždy běží, aby mohly být plánovány důležité úlohy na pozadí. <a href="https://github.com/tomykaira/clockwork">Více informací o clockwork</a>.'
sidekiq_warning: 'Sidekiq neběží. Řada úloh, jako je zasílání emailů, se provádí asynchronně na pozadí přes sidekiq. Prosím, ujistěte se, že alespoň jeden process sidekiq běží. <a href="https://github.com/mperham/sidekiq">Více o Sidekiq</a>.'
queue_size_warning: 'Počet čekajících úloh je %{queue_size}, což je příliš mnoho. Mohlo by to indikovat problém se službou Sidekiq, nebo je zapotřebí spustit více Sidekiq worker procesů.'
memory_warning: 'Váš server má méně než 1 GB paměti. Doporučená konfigurace je alespoň 1 GB paměti.'
Expand Down
1 change: 0 additions & 1 deletion config/locales/server.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ de:
rails_env_warning: "Dein Server läuft im %{env}-Modus."
host_names_warning: "Deine config/database.yml-Datei verwendet localhost als Hostname. Trage hier den Hostnamen deiner Webseite ein."
gc_warning: 'Dein Server verwendet die Standardparameter für Rubys Garbage-Collector, die nicht optimal sind. Lese dieses Thema über Performanzeinstellungen (en): <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126">Tuning Ruby and Rails for Discourse</a>.'
clockwork_warning: 'Clockwork läuft nicht. Stelle sicher, dass immer ein Clockwork-Prozess läuft, so dass wichtige Jobs eingeplant werden können. <a href="https://github.com/tomykaira/clockwork">Mehr über Clockwork erfährst du hier (en)</a>.'
sidekiq_warning: 'Sidekiq läuft nicht. Viele Aufgaben, wie zum Beispiel das Versenden von Mails, werden asynchron durch Sidekiq ausgeführt. Stelle sicher, dass mindestens eine Sidekiq-Prozess läuft. <a href="https://github.com/mperham/sidekiq">Mehr über Sidekiq erfährst du hier (en)</a>.'
queue_size_warning: 'Die Anzahl der Aktionen in der Warteschlange ist mit %{queue_size} ziemlich hoch. Das könnte auf ein Problem mit dem Sidekiq Prozess(en) hinweisen, oder du musst mehr Sidekiq Arbeiter hinzufügen.'
memory_warning: 'Dein Server läuft mit weniger als 1 GB Hauptspeicher. Mindestens 1 GB Hauptspeicher werden empfohlen.'
Expand Down
1 change: 0 additions & 1 deletion config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ en:
rails_env_warning: "Your server is running in %{env} mode."
host_names_warning: "Your config/database.yml file is using the default localhost hostname. Update it to use your site's hostname."
gc_warning: 'Your server is using default ruby garbage collection parameters, which will not give you the best performance. Read this topic on performance tuning: <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126" target="_blank">Tuning Ruby and Rails for Discourse</a>.'
clockwork_warning: 'Clockwork is not running. Ensure that a clockwork process is always running so that important jobs can be scheduled. <a href="https://github.com/tomykaira/clockwork" target="_blank">Learn about clockwork here</a>.'
sidekiq_warning: 'Sidekiq is not running. Many tasks, like sending emails, are executed asynchronously by sidekiq. Please ensure at least one sidekiq process is running. <a href="https://github.com/mperham/sidekiq" target="_blank">Learn about Sidekiq here</a>.'
queue_size_warning: 'The number of queued jobs is %{queue_size}, which is high. This could indicate a problem with the Sidekiq process(es), or you may need to add more Sidekiq workers.'
memory_warning: 'Your server is running with less than 1 GB of total memory. At least 1 GB of memory is recommended.'
Expand Down
1 change: 0 additions & 1 deletion config/locales/server.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ fr:
rails_env_warning: "Votre serveur fonctionne dans l'environnement de %{env}."
host_names_warning: "Le fichier config/database.yml utilise le nom d'hôte par défaut. Veuillez renseigner votre nom d'hôte."
gc_warning: "Votre serveur utilise les paramètres par défaut de collection du GC de ruby, ce qui ne vous donneras pas les meilleures performances. Merci de lire cette discussion sur <a href=\"http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126\">l'optimisation des performances de Ruby et Rails pour Discourse [EN]</a>."
clockwork_warning: "Clockwork n'est pas lancé. Assurez-vous qu'un processus clockwork soit toujours lancé afin que les tâches importantes soient planifiées. <a href=\"https://github.com/tomykaira/clockwork\">En savoir plus sur clockwork [EN]</a>."
sidekiq_warning: "Sidekiq n'est pas lancé. De nombreuses tâches, comme l'envoie d'e-mails, sont executées de manière asynchrome par sidekiq. Assurez-vous d'avoir au moins un processus sidekiq de lancé. <a href=\"https://github.com/mperham/sidekiq\">En savoir plus sur sidekiq [EN]</a>."
queue_size_warning: "Il y a %{queue_size} tâches dans la file d'attente, ce qui est beaucoup. Cela peut provenir d'un problème avec les processus Sidekiq, ou à un manque de processus Sidekiq travailleurs."
memory_warning: "Votre serveur dispose de moins de 1 Go de mémoire vive. Au moins 1 Go de RAM est recommandé."
Expand Down
1 change: 0 additions & 1 deletion config/locales/server.id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ id:
rails_env_warning: "Your server is running in %{env} mode."
host_names_warning: "Your config/database.yml file is using the default localhost hostname. Update it to use your site's hostname."
gc_warning: 'Your server is using default ruby garbage collection parameters, which will not give you the best performance. Read this topic on performance tuning: <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126">Tuning Ruby and Rails for Discourse</a>.'
clockwork_warning: 'Clockwork is not running. Ensure that a clockwork process is always running so that important jobs can be scheduled. <a href="https://github.com/tomykaira/clockwork">Learn about clockwork here</a>.'
sidekiq_warning: 'Sidekiq is not running. Many tasks, like sending emails, are executed asynchronously by sidekiq. Please ensure at least one sidekiq process is running. <a href="https://github.com/mperham/sidekiq">Learn about Sidekiq here</a>.'
memory_warning: 'Your server is running with less than 1 GB of total memory. At least 1 GB of memory is recommended.'

Expand Down
1 change: 0 additions & 1 deletion config/locales/server.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ it:
rails_env_warning: "Il tuo server è in modalità %{env}."
host_names_warning: "Il tuo file config/database.yml sta usando l'hostname localhost di default. Aggiornalo con l'hostname del tuo sito."
gc_warning: 'Il tuo server sta usando i parametri di garbage collection di default di ruby, che potrebbero non garantirti le migliori performance. Leggi questo topic sul tuning delle performance: <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126">Tuning Ruby and Rails for Discourse</a>.'
clockwork_warning: 'Clockwork non è in esecuzione. Assicurati che un processo clockwork sia sempre in esecuzione per far sì che task importanti possano essere messi in coda. <a href="https://github.com/tomykaira/clockwork">Leggi di più su clockwork qui</a>.'
sidekiq_warning: "Sidekiq non è in esecuzione. Molti task, come l'invio di email, sono eseguiti in maniera asincrona da sidekiq. Perfavore assicurati che almeno un processo sidekiq sia in esecuzione. <a href=\"https://github.com/mperham/sidekiq\">Leggi di più su sidekiq qui</a>."
queue_size_warning: 'Il numero di job in coda è %{queue_size}, che è alto. Questo indica un problema con i processi Sidekiq, oppure dovresti aggiungere altri Sidekiq worker.'
memory_warning: 'Il tuo server ha meno di 1 GB di memoria. È raccomandato avere a disposizione almeno 1 GB di memoria.'
Expand Down
1 change: 0 additions & 1 deletion config/locales/server.ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ ko:
rails_env_warning: "Your server is running in %{env} mode."
host_names_warning: "Your config/database.yml file is using the default localhost hostname. Update it to use your site's hostname."
gc_warning: 'Your server is using default ruby garbage collection parameters, which will not give you the best performance. Read this topic on performance tuning: <a href="http://meta.discourse.org/t/tuning-ruby-and-rails-for-discourse/4126">Tuning Ruby and Rails for Discourse</a>.'
clockwork_warning: 'Clockwork is not running. Ensure that a clockwork process is always running so that important jobs can be scheduled. <a href="https://github.com/tomykaira/clockwork">Learn about clockwork here</a>.'
sidekiq_warning: 'Sidekiq is not running. Many tasks, like sending emails, are executed asynchronously by sidekiq. Please ensure at least one sidekiq process is running. <a href="https://github.com/mperham/sidekiq">Learn about Sidekiq here</a>.'
queue_size_warning: 'The number of queued jobs is %{queue_size}, which is high. This could indicate a problem with the Sidekiq process(es), or you may need to add more Sidekiq workers.'
memory_warning: 'Your server is running with less than 1 GB of total memory. At least 1 GB of memory is recommended.'
Expand Down
Loading

0 comments on commit a6b4b5d

Please sign in to comment.