@silva96
Software Engineer and Father. Love to learn, love to teach, love to build. CTO at recorrido.cl -> Ruby, Elixir, Vue / Stimulus
My name is Benjamín Silva, I studied Computer Science. I try to keep up to date on technologies and best practices and this blog is a personal project that hopefully helps me on that. I believe making myself write tech stuff is a good way to share my knowledge at the same time keep me learning new things.
What I'm using on my daily work: Elixir (and Phoenix), Ruby on Rails, Rspec, PostgreSQL, Vue.js, Elasticsearch, AWS, Docker
What else I know or I used before: Android Native, React, Python Django
Nothing here yet.
Piotr Jurewicz Yes that's a good way to tackle down "most" of possible sources that can cause a process to die. But of course there might be other. For instance, if you have your rails app in the same instance, it can grow in ram too, so even having sidekiq with low memory usage, the system can enter a "resource starvation" state and the Kernel would kill proceses to safeguard the system state. The way the Kernel chooses this proceses is based in many factors, so there's still chance your sidekiq dies.
What happens if the process dies? you are not using a process manager like upstart, systemd or supervisord. We have al these scripts to manage sidekiq properly. commands : 02 _create_sidekiq_log_file : command : touch /var/log/sidekiq_worker.log files: "/opt/elasticbeanstalk/support/conf/sidekiq_worker.conf" : mode: "000755" owner: root group: root content: | description "Elastic Beanstalk Sidekiq Background Worker" # Greatly reduce Ruby memory fragmentation and heap usage # https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/ env MALLOC_ARENA_MAX=2 respawn respawn limit 3 30 # TERM is sent by sidekiqctl when stopping sidekiq. Without declaring these as # normal exit codes, it just respawns. normal exit 0 TERM # Upstart waits 5 seconds by default to kill a process. Increase timeout to # give sidekiq process enough time to exit. kill timeout 30 script exec /bin/bash << "EOT" EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir) EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir) . $EB_SUPPORT_DIR /envvars . $EB_SCRIPT_DIR /use-app-ruby.sh EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir) cd $EB_APP_DEPLOY_DIR echo "Bundle exec sidekiq worker" exec bundle exec sidekiq -e ${RACK_ENV} \ -C ${EB_APP_DEPLOY_DIR} /config/sidekiq.yml >/var/ log /sidekiq_worker.log 2>&1 EOT end script files : "/etc/init/sidekiq_worker.conf" : mode : "120400" content : "/opt/elasticbeanstalk/support/conf/sidekiq_worker.conf" "/etc/init/workers.conf" : mode : "000755" owner : root group : root content : | description "Manages the Set of Sidekiq Processes" # Use "sudo stop workers" to stop all Sidekiq instances. # Use "sudo start workers" to start all instances. # Use "sudo restart workers" to restart all instances. # This starts upon bootup and stops on shutdown start on runlevel [ 2345 ] stop on runlevel [ 06 ] pre-start script sudo start sidekiq_worker end script post-stop script sudo stop sidekiq_worker end script commands : reload_initctl_for_sidekiq : command : "sudo initctl reload-configuration" files: "/tmp/sidekiq_mute.sh" : mode: "000755" owner: root group: root content: | #!/bin/bash skwpid=$(initctl status sidekiq_worker | grep /running | awk '{print $NF}' ) if [ -f skwpid ] then echo "TSTP/quieting sidekiq worker" sudo kill -TSTP skwpid fi files: "/tmp/sidekiq_restart.sh" : mode: "000755" owner: root group: root content: | #!/bin/bash skwpid=$(initctl status sidekiq_worker | grep /running | awk '{print $NF}' ) if [ -f skwpid ] then echo "TERM/terminating sidekiq worker" sudo kill -TERM skwpid fi echo "STOPPING all sidekiq workers" sudo stop workers echo "STARTING all sidekiq workers" sudo start workers files : "/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh" : mode : "120755" owner : root group : root content : "/tmp/sidekiq_restart.sh" "/opt/elasticbeanstalk/hooks/configdeploy/post/50_restart_sidekiq.sh" : mode : "120755" owner : root group : root content : "/tmp/sidekiq_restart.sh" "/opt/elasticbeanstalk/hooks/restartappserver/post/50_restart_sidekiq.sh" : mode : "120755" owner : root group : root content : "/tmp/sidekiq_restart.sh" "/opt/elasticbeanstalk/hooks/appdeploy/pre/03_mute_sidekiq.sh" : mode : "120755" owner : root group : root content : "/tmp/sidekiq_mute.sh" "/opt/elasticbeanstalk/hooks/configdeploy/pre/03_mute_sidekiq.sh" : mode : "120755" owner : root group : root content : "/tmp/sidekiq_mute.sh" "/opt/elasticbeanstalk/hooks/restartappserver/pre/03_mute_sidekiq.sh" : mode : "120755" owner : root group : root content : "/tmp/sidekiq_mute.sh"