Derailed benchmark not running on production environment

We're running a large rails application, with a lot of request.
Since our upgrade to FreeBSD 13 the live environment is leaking memory in our ruby on rails app.
(FreeBSD 12 version of the jail didn't leak)

This application uses an NFS mount to store (a lot) of client specific files.

Running derailed_benchmark live didn't work. (Pressing ctrl+t, I noticed there were a lof of NFS locks)

In the file
derailed_benchmarks-2.1.1/lib/derailed_benchmarks/load_tasks.rb

it adds '.' to the loadpath. Which causes the production environment to complete iterate over all directories. Which 'hangs', because we have a very big active-strorage directory.

Workaround is to remove the '.' file

#    %W{ . lib test config }.each do |file|
    %W{ lib test config }.each do |file|
      $LOAD_PATH << File.expand_path(file)
    end

Ruby rbtrace ArgumentError: command is too long

(This code blow requires you to include rbtrace in your gems)

To make a stack dump of your running rubyprocess, you could use somthing like this:

my_pid=1234
bundle exec rbtrace -p $my_pid -e 'Thread.new{GC.start;require "objspace";io=File.open("/tmp/ruby-heap.dump", "w"); ObjectSpace.dump_all(output: io); io.close}'

Unfortunately on FreeBSD / Mac OS X this results in (ArgumentError: command is too long)

A workaround for this, is to simply put the code in ruby file, and just load it. For example:
/tmp/rbcode.rb. With the following content

Thread.new{GC.start;require "objspace";io=File.open("/tmp/ruby-heap.dump", "w"); ObjectSpace.dump_all(output: io); io.close}

Next you can use rbtrace lik this:

bundle exec rbtrace -p $my_pid -e 'load("/tmp/rbcode.rb")'

FreeBSD cleanup all iocage

Finally I converted my internal sever to Bastille as jail manager. (I was using iocage). (https://bastillebsd.org)
To completely remove all stuff from iocage, you can run the following command:

iocage clean -a

Then delete the package

pkg delete py38-iocage

Iocage thank you for managing my jails for many year!
(I'm still using you on several other servers)

Cron Job to clear Rails Cache

The rails file cache is something that keeps growing.
Here are some 'handy' snippets.

Delete all files older then 7 days. (replace -delete with -print to test it)

find ./tmp/cache/ -type f -mtime +7 -delete

Delete all empty folders. (mindepth prevents the deletion of the root folder)

find ./tmp/cache/ -type d -empty -delete -mindepth 1

The whenever.rb I use

job_type :command_in_path, "cd :path && :task :output"

every :day, at: "0:40" do
  command_in_path "find ./tmp/cache/ -type f -mtime +7 -delete"
end

every :day, at: "1:10" do
  command_in_path "find ./tmp/cache/ -type d -empty -delete -mindepth 1"
end

Spree Issues config.action_view.raise_on_missing_translations

I'm working on a Rails Spree 4.1 app.
I enabled raising exception on missing translations via the option config.action_view.raise_on_missing_translations in config/environment/development.rb.
It's nice to know I a tranlsation is missing.

This was working fine, until I included the spree_mollie_gateway.

I couldn't boot the rails application anymore. It constantly raised:

gems/i18n-1.8.3/lib/i18n.rb:373:in `handle_exception': translation missing: nl.spree.validation.must_be_int (I18n::MissingTranslationData)

The woraround I now use is this: (config/development.rb)
Just enable it after the GEM is loaded

# Raises error for missing translations.
  config.action_view.raise_on_missing_translations = false
  Rails.application.config.to_prepare do
    ActionView::Base.raise_on_missing_translations = true
  end