Install rustc so Ruby is built with YJIT #14

Open
armin-bot wants to merge 4 commits from armin-bot/impress:claude/amazing-ritchie-2us66j into main
Contributor

Summary

Production Ruby has no YJIT: ruby-build only compiles it in when rustc is installed at build time, and deploy/setup.yml never installed it. Rails already enables YJIT in production on its own (config.load_defaults 8.1 sets config.yjit = !Rails.env.local?), so no app config change is needed: I booted the app in production mode locally and got RubyVM::YJIT.enabled? == true (and false in development).

This PR:

  • Installs rustc in deploy/setup.yml, before the "Install Ruby" task. The server runs Ubuntu 22.04, where the rustc apt package is 1.58.1 in the release pocket and 1.75.0 from jammy-updates/jammy-security (Ruby 3.4 needs >= 1.58), so plain apt works. I built Ruby 3.4.5 with rustc 1.75.0 and no cargo on PATH (which is what the apt package gives you) and it came out with YJIT. I did not try 1.58.1, which only just meets the minimum; step 2 of the procedure prints which version you actually get.
  • Adds a check after "Install Ruby" that warns when the installed Ruby lacks YJIT. This matters because "Install Ruby" is skipped when /opt/ruby-<version> already exists, so adding rustc alone won't rebuild production's current Ruby.

This PR does not change production by itself. The existing Ruby needs a one-time manual rebuild; the procedure is below. It's in this description rather than in docs/, since it only needs to be run once.

Memory and ordering (see #19)

#19 changed the memory picture since I first wrote this, so this supersedes my earlier cap arithmetic:

  • #19 runs 6 workers (FALCON_COUNT=6) under MemoryMax=4G, and measured YJIT at about 75MB per worker (≈1.8GB for 6 workers). That fits under 4G with room for spikes, so no MemoryMax change or lower --yjit-mem-size is needed here. (I had suggested both, based on the old 1.2G cap. That cap turned out to be below healthy steady-state usage, not a leak symptom.)
  • Do #19 first. YJIT's extra memory would not fit under the old 1.2G cap. #19 needs bin/deploy:setup (it changes the service file and installs libjemalloc2), not just a deploy.
  • #19 also brings jemalloc. If you want jemalloc's and YJIT's effects on memory and latency told apart, leave a few days between them (jemalloc first). Doing both close together works fine; you just won't be able to say which did what.
  • Deploys now run automatically when anything lands on main (#18) and restart the service, so don't merge anything during the swap window below.

Testing

  • Ruby 3.4.5 built locally with and without YJIT: the only RbConfig::CONFIG differences are the YJIT_* entries and configure_args; the extension ABI (3.4.0, x86_64-linux, shared libruby) is identical.
  • Native gems (bcrypt, msgpack, nio4r) compiled by the no-YJIT build load and run under the YJIT build with YJIT enabled.
  • The swap and rollback below were run in a scratch directory, including the failure case (a leftover -noyjit directory makes the chain stop without nesting directories). A renamed built Ruby does not work (libruby RUNPATH and shebangs break), which is why the procedure uses a symlink.
  • The two new Ansible tasks were run against a no-YJIT and a YJIT Ruby (warns, and stays silent, respectively), and under --check.
  • Not tested on the real box: Ubuntu 22.04, the sudoers rules, systemctl output, the cron jobs.
One-time procedure for the production box: swap in a YJIT-enabled Ruby 3.4.5

YJIT is Ruby's JIT compiler. Rails turns it on by itself in production
(config.load_defaults 8.1 sets config.yjit = !Rails.env.local?), if the
Ruby was built with it. ruby-build only compiles YJIT in when rustc is
installed at build time, and the build succeeds silently without it.

setup.yml now installs rustc before building Ruby, so new servers
and future Ruby upgrades get YJIT automatically
. But the setup playbook skips
"Install Ruby" when /opt/ruby-<version> already exists, so a server whose Ruby
was built before this change keeps its YJIT-less Ruby until you rebuild it by
hand. Running bin/deploy:setup installs rustc and prints a warning if the
current Ruby has no YJIT.

You can check any Ruby yourself:

/opt/ruby-3.4.5/bin/ruby -e 'p defined?(RubyVM::YJIT)'   # "constant" = has YJIT, nil = doesn't

One-time procedure: swap in a YJIT-enabled 3.4.5

Same Ruby version, so the gems in /srv/impress/shared/bundle are reused as-is
(see "Why the gems are safe to reuse" below), and
the downtime is just a service restart (under a minute, probably, counting the
Rails boot). This is not the Ruby-upgrade dance described in
deploy/deploy.yml, which is for changing versions.

Run these on the server as a user with sudo. Everything up to step 4 leaves
the live app untouched. Note that only sudo -u impress ... and
sudo systemctl {status,start,stop,restart} impress are passwordless (see the
sudoers rules in setup.yml); everything else below needs your own sudo
password.

1. Preflight. Record a baseline to compare against later, and check there's
room to compile:

nproc
free -m && df -h /opt /tmp              # see the note on RAM below
sudo journalctl -u impress --since "7 days ago" | grep -c "Scheduled restart job"
sudo journalctl -k --since "7 days ago" | grep -c "Memory cgroup out of memory"   # kernel OOM kills (may only cover the retained journal)
sudo journalctl -u impress --since "7 days ago" | grep -c "OOM killer"
ps -u impress -o pid,rss,args --sort=-rss | head

nice (used in step 3) only protects CPU, not memory. Compiling Ruby with
YJIT, plus the extra production Rails boot in the same step, runs next to the
live service, and if the box runs short of RAM the OOM killer could take out
falcon. We haven't measured the build's peak memory, so as a rough guess:
if the available column of free -m is under about 1.5 GB, wait for a quiet
window or add temporary swap first.

2. Install rustc, either with this or by running bin/deploy:setup from
your machine. (Prefer the apt-get route: the full setup playbook also
re-runs the MariaDB, certbot and service-file tasks, and can restart the app.)

sudo apt-get update && sudo apt-get install -y rustc
apt-cache policy rustc | head -n 3
rustc --version    # must be >= 1.58; jammy-updates ships 1.75.0, the release pocket 1.58.1

(On Ubuntu 22.04 you should get 1.75.0 from jammy-updates, which is enabled
by default. I only tested the YJIT build with 1.75; if you somehow only get
1.58.1, it meets the stated minimum but is untested.)

3. Build into a temporary prefix. The app keeps running meanwhile; nice
keeps the build from starving it. This takes a few minutes (longer on a small
box):

sudo nice -n 19 /opt/ruby-build/bin/ruby-build 3.4.5 /opt/ruby-3.4.5-yjit

Check that it has YJIT, and that it matches the live Ruby in everything that
affects compiled gems (the two lines printed by each loop should be identical;
the only differences expected in configure_args are the prefix and nothing
else, since YJIT is on by default):

/opt/ruby-3.4.5-yjit/bin/ruby -e 'p defined?(RubyVM::YJIT)'    # => "constant"
for r in /opt/ruby-3.4.5 /opt/ruby-3.4.5-yjit; do
  $r/bin/ruby -e 'p [Gem.extension_api_version, RbConfig::CONFIG.values_at("arch", "ENABLE_SHARED")]'
  $r/bin/ruby -e 'puts RbConfig::CONFIG["configure_args"].gsub(ARGV[0], "<PREFIX>")' $r
done

Then try the new Ruby against the real app and the real production gems,
without touching the running service. This boots Rails in production mode
and loads every native extension:

sudo -u impress bash -c 'source /srv/impress/.bash_profile && cd /srv/impress/current && /opt/ruby-3.4.5-yjit/bin/bundle exec /opt/ruby-3.4.5-yjit/bin/ruby bin/rails runner "puts RUBY_DESCRIPTION, RubyVM::YJIT.enabled?"'

Expect a description containing +YJIT, then true. If anything looks wrong,
stop here: sudo rm -rf /opt/ruby-3.4.5-yjit and nothing has changed.

4. Swap. Downtime starts here. Deploys run automatically when anything lands on main (#18) and restart the service, so don't merge anything now, and check the Actions page for a deploy in progress. First refresh your sudo password cache, so
you aren't prompted while the site is down (the earlier sudo calls may have
expired). The && chain matters: if a step fails, the later ones are skipped,
and the final start just brings the old, unchanged Ruby back up. If that
happens, work out why before retrying (for instance, a leftover
/opt/ruby-3.4.5-noyjit from an earlier attempt makes the mv fail).

sudo -v
sudo systemctl stop impress && \
  sudo mv -T /opt/ruby-3.4.5 /opt/ruby-3.4.5-noyjit && \
  sudo ln -sT /opt/ruby-3.4.5-yjit /opt/ruby-3.4.5
sudo systemctl start impress

The cron jobs (items:auto_model every 2 minutes, neopets:import every 10)
also run through /opt/ruby-3.4.5, so a run that fires in the instant between
the mv and the ln fails, and the next one is fine. After the swap they run
with YJIT too; they run under cron rather than the impress service, so
MemoryMax doesn't cover them.

Note that /opt/ruby-3.4.5 becomes a symlink to the real new install, rather
than the new install being renamed into place. That's deliberate: a built Ruby
has its own prefix baked in (the ruby binary's library path, and the shebangs
of bundle, gem, etc.), so a renamed Ruby fails to start. Everything that
references /opt/ruby-3.4.5 (the systemd unit, /etc/profile.d, the cron
jobs, the shebangs of gem binstubs in the shared bundle, and the Ansible
playbooks) keeps working unchanged through the symlink. Leave
/opt/ruby-3.4.5-yjit in place.

5. Verify.

sudo systemctl --no-pager status impress    # active (running), and "since" is just now
sudo readlink /proc/$(systemctl show -p MainPID --value impress)/exe   # under /opt/ruby-3.4.5-yjit/
sudo -u impress bash -c 'source /etc/profile && source /srv/impress/.bash_profile && cd /srv/impress/current && bin/rails runner "puts RUBY_DESCRIPTION, RubyVM::YJIT.enabled?"'
curl -sI https://impress.openneo.net/ | head -n 1

The rails runner one runs the same way the cron jobs do. It should print
+YJIT and true. "active (running)" only means the process started, not
that it's serving yet, so give it a few seconds after the start (Rails boot)
before the curl should show HTTP/2 200. Then click around the site a bit.

Rollback (if the app misbehaves, or memory gets out of hand, see below):

sudo -v
sudo systemctl stop impress && \
  sudo rm /opt/ruby-3.4.5 && \
  sudo mv -T /opt/ruby-3.4.5-noyjit /opt/ruby-3.4.5
sudo systemctl start impress

(rm without -r only removes the symlink, and refuses if /opt/ruby-3.4.5
is somehow a real directory. Don't add a trailing slash to that path.)

Once you're confident (a week or so), sudo rm -rf /opt/ruby-3.4.5-noyjit.

Why the gems are safe to reuse

Compiled gems live in /srv/impress/shared/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/,
keyed by Ruby ABI version and platform, which don't change when YJIT is added.
Comparing RbConfig::CONFIG between a --disable-yjit and a default build of
3.4.5, the only differences were the YJIT_* entries and configure_args. The
extensions' ELF headers say NEEDED libruby.so.3.4, which is satisfied by the
libruby the running process already loaded, whichever install it came from.
We tested this directly: gems with C extensions (bcrypt, msgpack, nio4r)
compiled by a YJIT-less 3.4.5 loaded and ran under the YJIT build, with YJIT
enabled and code compiled.

The one thing that would break this is building the new Ruby with different
configure options (e.g. a different ruby-build version or RUBY_CONFIGURE_OPTS).
That's what the comparison in step 3 is for.

Memory: what to watch afterwards

With #19 deployed, the service runs 6 workers under MemoryMax=4G, and YJIT is expected to add about 75MB per worker (≈450MB total, measured in #19, not on the live box). Hitting the cap is now a signal worth investigating, not routine. For the first few days:

systemctl show impress -p MemoryCurrent -p MemoryMax -p ActiveEnterTimestamp
cat /sys/fs/cgroup/system.slice/impress.service/memory.events   # oom_kill should stay 0
ps -u impress -o pid,rss,args --sort=-rss | head
sudo journalctl -u impress --since "7 days ago" | grep -c "Scheduled restart job"

It's also worth watching response times, since that's the point. YJIT needs a warm-up period after every restart, so numbers are worse right after one.

If something goes wrong, the rollback above takes seconds. (If you ever need to cap YJIT specifically, Environment="RUBYOPT=--yjit-mem-size=<MiB>" in the service file does it. Ruby 3.4's RubyVM::YJIT.enable, which Rails calls, doesn't accept a mem_size: option.)

🤖 Generated with Claude Code

https://claude.ai/code/session_014PWWd2aRXHH83fsXVzrDQ2

## Summary Production Ruby has no YJIT: `ruby-build` only compiles it in when `rustc` is installed at build time, and `deploy/setup.yml` never installed it. Rails already enables YJIT in production on its own (`config.load_defaults 8.1` sets `config.yjit = !Rails.env.local?`), so **no app config change is needed**: I booted the app in production mode locally and got `RubyVM::YJIT.enabled? == true` (and `false` in development). This PR: - Installs `rustc` in `deploy/setup.yml`, before the "Install Ruby" task. The server runs Ubuntu 22.04, where the `rustc` apt package is 1.58.1 in the release pocket and **1.75.0** from `jammy-updates`/`jammy-security` (Ruby 3.4 needs >= 1.58), so plain `apt` works. I built Ruby 3.4.5 with rustc 1.75.0 and no `cargo` on `PATH` (which is what the apt package gives you) and it came out with YJIT. I did not try 1.58.1, which only just meets the minimum; step 2 of the procedure prints which version you actually get. - Adds a check after "Install Ruby" that warns when the installed Ruby lacks YJIT. This matters because "Install Ruby" is skipped when `/opt/ruby-<version>` already exists, so adding `rustc` alone won't rebuild production's current Ruby. **This PR does not change production by itself.** The existing Ruby needs a one-time manual rebuild; the procedure is below. It's in this description rather than in `docs/`, since it only needs to be run once. ## Memory and ordering (see [#19](https://code.openneo.net/OpenNeo/impress/pulls/19)) [#19](https://code.openneo.net/OpenNeo/impress/pulls/19) changed the memory picture since I first wrote this, so this supersedes my earlier cap arithmetic: - [#19](https://code.openneo.net/OpenNeo/impress/pulls/19) runs 6 workers (`FALCON_COUNT=6`) under `MemoryMax=4G`, and measured YJIT at about 75MB per worker (≈1.8GB for 6 workers). That fits under 4G with room for spikes, so **no `MemoryMax` change or lower `--yjit-mem-size` is needed here**. (I had suggested both, based on the old 1.2G cap. That cap turned out to be below healthy steady-state usage, not a leak symptom.) - **Do [#19](https://code.openneo.net/OpenNeo/impress/pulls/19) first.** YJIT's extra memory would not fit under the old 1.2G cap. [#19](https://code.openneo.net/OpenNeo/impress/pulls/19) needs `bin/deploy:setup` (it changes the service file and installs `libjemalloc2`), not just a deploy. - [#19](https://code.openneo.net/OpenNeo/impress/pulls/19) also brings jemalloc. If you want jemalloc's and YJIT's effects on memory and latency told apart, leave a few days between them (jemalloc first). Doing both close together works fine; you just won't be able to say which did what. - Deploys now run automatically when anything lands on `main` ([#18](https://code.openneo.net/OpenNeo/impress/pulls/18)) and restart the service, so don't merge anything during the swap window below. ## Testing - Ruby 3.4.5 built locally with and without YJIT: the only `RbConfig::CONFIG` differences are the `YJIT_*` entries and `configure_args`; the extension ABI (`3.4.0`, `x86_64-linux`, shared libruby) is identical. - Native gems (`bcrypt`, `msgpack`, `nio4r`) compiled by the no-YJIT build load and run under the YJIT build with YJIT enabled. - The swap and rollback below were run in a scratch directory, including the failure case (a leftover `-noyjit` directory makes the chain stop without nesting directories). A renamed built Ruby does **not** work (`libruby` RUNPATH and shebangs break), which is why the procedure uses a symlink. - The two new Ansible tasks were run against a no-YJIT and a YJIT Ruby (warns, and stays silent, respectively), and under `--check`. - Not tested on the real box: Ubuntu 22.04, the sudoers rules, `systemctl` output, the cron jobs. <details> <summary>One-time procedure for the production box: swap in a YJIT-enabled Ruby 3.4.5</summary> YJIT is Ruby's JIT compiler. Rails turns it on by itself in production (`config.load_defaults 8.1` sets `config.yjit = !Rails.env.local?`), *if* the Ruby was built with it. ruby-build only compiles YJIT in when `rustc` is installed at build time, and the build succeeds silently without it. `setup.yml` now installs `rustc` before building Ruby, so **new servers and future Ruby upgrades get YJIT automatically**. But the setup playbook skips "Install Ruby" when `/opt/ruby-<version>` already exists, so a server whose Ruby was built before this change keeps its YJIT-less Ruby until you rebuild it by hand. Running `bin/deploy:setup` installs `rustc` and prints a warning if the current Ruby has no YJIT. You can check any Ruby yourself: ```bash /opt/ruby-3.4.5/bin/ruby -e 'p defined?(RubyVM::YJIT)' # "constant" = has YJIT, nil = doesn't ``` ### One-time procedure: swap in a YJIT-enabled 3.4.5 Same Ruby version, so the gems in `/srv/impress/shared/bundle` are reused as-is (see "Why the gems are safe to reuse" below), and the downtime is just a service restart (under a minute, probably, counting the Rails boot). This is *not* the Ruby-upgrade dance described in `deploy/deploy.yml`, which is for changing versions. Run these on the server as a user with `sudo`. Everything up to step 4 leaves the live app untouched. Note that only `sudo -u impress ...` and `sudo systemctl {status,start,stop,restart} impress` are passwordless (see the sudoers rules in `setup.yml`); everything else below needs your own sudo password. **1. Preflight.** Record a baseline to compare against later, and check there's room to compile: ```bash nproc free -m && df -h /opt /tmp # see the note on RAM below sudo journalctl -u impress --since "7 days ago" | grep -c "Scheduled restart job" sudo journalctl -k --since "7 days ago" | grep -c "Memory cgroup out of memory" # kernel OOM kills (may only cover the retained journal) sudo journalctl -u impress --since "7 days ago" | grep -c "OOM killer" ps -u impress -o pid,rss,args --sort=-rss | head ``` `nice` (used in step 3) only protects CPU, not memory. Compiling Ruby with YJIT, plus the extra production Rails boot in the same step, runs *next to* the live service, and if the box runs short of RAM the OOM killer could take out falcon. We haven't measured the build's peak memory, so as a rough guess: if the `available` column of `free -m` is under about 1.5 GB, wait for a quiet window or add temporary swap first. **2. Install rustc**, either with this or by running `bin/deploy:setup` from your machine. (Prefer the `apt-get` route: the full setup playbook also re-runs the MariaDB, certbot and service-file tasks, and can restart the app.) ```bash sudo apt-get update && sudo apt-get install -y rustc apt-cache policy rustc | head -n 3 rustc --version # must be >= 1.58; jammy-updates ships 1.75.0, the release pocket 1.58.1 ``` (On Ubuntu 22.04 you should get 1.75.0 from `jammy-updates`, which is enabled by default. I only tested the YJIT build with 1.75; if you somehow only get 1.58.1, it meets the stated minimum but is untested.) **3. Build into a temporary prefix.** The app keeps running meanwhile; `nice` keeps the build from starving it. This takes a few minutes (longer on a small box): ```bash sudo nice -n 19 /opt/ruby-build/bin/ruby-build 3.4.5 /opt/ruby-3.4.5-yjit ``` Check that it has YJIT, and that it matches the live Ruby in everything that affects compiled gems (the two lines printed by each loop should be identical; the only differences expected in `configure_args` are the prefix and nothing else, since YJIT is on by default): ```bash /opt/ruby-3.4.5-yjit/bin/ruby -e 'p defined?(RubyVM::YJIT)' # => "constant" for r in /opt/ruby-3.4.5 /opt/ruby-3.4.5-yjit; do $r/bin/ruby -e 'p [Gem.extension_api_version, RbConfig::CONFIG.values_at("arch", "ENABLE_SHARED")]' $r/bin/ruby -e 'puts RbConfig::CONFIG["configure_args"].gsub(ARGV[0], "<PREFIX>")' $r done ``` Then try the new Ruby against the real app and the real production gems, *without* touching the running service. This boots Rails in production mode and loads every native extension: ```bash sudo -u impress bash -c 'source /srv/impress/.bash_profile && cd /srv/impress/current && /opt/ruby-3.4.5-yjit/bin/bundle exec /opt/ruby-3.4.5-yjit/bin/ruby bin/rails runner "puts RUBY_DESCRIPTION, RubyVM::YJIT.enabled?"' ``` Expect a description containing `+YJIT`, then `true`. If anything looks wrong, stop here: `sudo rm -rf /opt/ruby-3.4.5-yjit` and nothing has changed. **4. Swap.** Downtime starts here. Deploys run automatically when anything lands on `main` ([#18](https://code.openneo.net/OpenNeo/impress/pulls/18)) and restart the service, so don't merge anything now, and check the Actions page for a deploy in progress. First refresh your sudo password cache, so you aren't prompted while the site is down (the earlier `sudo` calls may have expired). The `&&` chain matters: if a step fails, the later ones are skipped, and the final `start` just brings the old, unchanged Ruby back up. If that happens, work out why before retrying (for instance, a leftover `/opt/ruby-3.4.5-noyjit` from an earlier attempt makes the `mv` fail). ```bash sudo -v sudo systemctl stop impress && \ sudo mv -T /opt/ruby-3.4.5 /opt/ruby-3.4.5-noyjit && \ sudo ln -sT /opt/ruby-3.4.5-yjit /opt/ruby-3.4.5 sudo systemctl start impress ``` The cron jobs (`items:auto_model` every 2 minutes, `neopets:import` every 10) also run through `/opt/ruby-3.4.5`, so a run that fires in the instant between the `mv` and the `ln` fails, and the next one is fine. After the swap they run with YJIT too; they run under cron rather than the `impress` service, so `MemoryMax` doesn't cover them. Note that `/opt/ruby-3.4.5` becomes a *symlink* to the real new install, rather than the new install being renamed into place. That's deliberate: a built Ruby has its own prefix baked in (the `ruby` binary's library path, and the shebangs of `bundle`, `gem`, etc.), so a renamed Ruby fails to start. Everything that references `/opt/ruby-3.4.5` (the systemd unit, `/etc/profile.d`, the cron jobs, the shebangs of gem binstubs in the shared bundle, and the Ansible playbooks) keeps working unchanged through the symlink. Leave `/opt/ruby-3.4.5-yjit` in place. **5. Verify.** ```bash sudo systemctl --no-pager status impress # active (running), and "since" is just now sudo readlink /proc/$(systemctl show -p MainPID --value impress)/exe # under /opt/ruby-3.4.5-yjit/ sudo -u impress bash -c 'source /etc/profile && source /srv/impress/.bash_profile && cd /srv/impress/current && bin/rails runner "puts RUBY_DESCRIPTION, RubyVM::YJIT.enabled?"' curl -sI https://impress.openneo.net/ | head -n 1 ``` The `rails runner` one runs the same way the cron jobs do. It should print `+YJIT` and `true`. "active (running)" only means the process started, not that it's serving yet, so give it a few seconds after the start (Rails boot) before the `curl` should show `HTTP/2 200`. Then click around the site a bit. **Rollback** (if the app misbehaves, or memory gets out of hand, see below): ```bash sudo -v sudo systemctl stop impress && \ sudo rm /opt/ruby-3.4.5 && \ sudo mv -T /opt/ruby-3.4.5-noyjit /opt/ruby-3.4.5 sudo systemctl start impress ``` (`rm` without `-r` only removes the symlink, and refuses if `/opt/ruby-3.4.5` is somehow a real directory. Don't add a trailing slash to that path.) Once you're confident (a week or so), `sudo rm -rf /opt/ruby-3.4.5-noyjit`. #### Why the gems are safe to reuse Compiled gems live in `/srv/impress/shared/bundle/ruby/3.4.0/extensions/x86_64-linux/3.4.0/`, keyed by Ruby ABI version and platform, which don't change when YJIT is added. Comparing `RbConfig::CONFIG` between a `--disable-yjit` and a default build of 3.4.5, the only differences were the `YJIT_*` entries and `configure_args`. The extensions' ELF headers say `NEEDED libruby.so.3.4`, which is satisfied by the `libruby` the running process already loaded, whichever install it came from. We tested this directly: gems with C extensions (`bcrypt`, `msgpack`, `nio4r`) compiled by a YJIT-less 3.4.5 loaded and ran under the YJIT build, with YJIT enabled and code compiled. The one thing that would break this is building the new Ruby with different `configure` options (e.g. a different `ruby-build` version or `RUBY_CONFIGURE_OPTS`). That's what the comparison in step 3 is for. #### Memory: what to watch afterwards With [#19](https://code.openneo.net/OpenNeo/impress/pulls/19) deployed, the service runs 6 workers under `MemoryMax=4G`, and YJIT is expected to add about 75MB per worker (≈450MB total, measured in [#19](https://code.openneo.net/OpenNeo/impress/pulls/19), not on the live box). Hitting the cap is now a signal worth investigating, not routine. For the first few days: ```bash systemctl show impress -p MemoryCurrent -p MemoryMax -p ActiveEnterTimestamp cat /sys/fs/cgroup/system.slice/impress.service/memory.events # oom_kill should stay 0 ps -u impress -o pid,rss,args --sort=-rss | head sudo journalctl -u impress --since "7 days ago" | grep -c "Scheduled restart job" ``` It's also worth watching response times, since that's the point. YJIT needs a warm-up period after every restart, so numbers are worse right after one. If something goes wrong, the rollback above takes seconds. (If you ever need to cap YJIT specifically, `Environment="RUBYOPT=--yjit-mem-size=<MiB>"` in the service file does it. Ruby 3.4's `RubyVM::YJIT.enable`, which Rails calls, doesn't accept a `mem_size:` option.) </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014PWWd2aRXHH83fsXVzrDQ2
ruby-build only compiles YJIT when rustc is present at build time, and
setup.yml never installed it, so production Ruby has no YJIT (Rails'
load_defaults 8.1 would enable it automatically if it were available).

- setup.yml: install rustc (1.75 from focal-updates; focal main has only
  1.41) before "Install Ruby", and warn when the installed Ruby lacks YJIT,
  since the Install Ruby task is skipped when /opt/ruby-<version> exists.
- docs/deployment-setup.md: add a copy-pasteable, low-downtime procedure
  for swapping a YJIT build into place (symlink, not rename, because a
  built Ruby bakes in its prefix), with rollback, the gem-compatibility
  reasoning, and what to watch for memory (per-worker YJIT memory vs the
  unit's MemoryMax=1.2G).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014PWWd2aRXHH83fsXVzrDQ2
- Chain the swap and rollback with && and use mv -T / ln -sT, so a failed
  step (e.g. a leftover -noyjit dir) can't nest directories inside the live
  Ruby; the trailing start then just restores the unchanged app.
- Add `sudo -v` before downtime and say which sudo commands are passwordless.
- Give a rough RAM threshold for building next to the live service, add an
  OOM-grep baseline, a readiness curl, and cron-job notes.
- Compare configure_args in the build check; prefer plain apt-get over a
  full setup run on production; soften the downtime claim.
- setup.yml: default rc to 0 so the YJIT warning is skipped under --check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014PWWd2aRXHH83fsXVzrDQ2
It's a one-time operation, so it lives in the PR description instead of
docs/deployment-setup.md. The setup.yml warning is now self-contained.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014PWWd2aRXHH83fsXVzrDQ2
Ubuntu 22.04's rustc is 1.58.1 in the release pocket and 1.75 from
jammy-updates; either meets Ruby 3.4's minimum of 1.58.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014PWWd2aRXHH83fsXVzrDQ2
Some required checks are missing.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'claude/amazing-ritchie-2us66j:armin-bot-claude/amazing-ritchie-2us66j'
git switch 'armin-bot-claude/amazing-ritchie-2us66j'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
OpenNeo/impress!14
No description provided.