R
Railway16mo ago
macwilko

YJIT Ruby 3.2

I have a Rails app deployed on Railway using Ruby 3.2 with nixpacks. How can I enable the Ruby to be compiled with YJIT enabled?
Solution:
is this helpful?
Jump to solution
15 Replies
Percy
Percy16mo ago
Project ID: d1c85c02-8ca5-43c3-adc6-4a24cb066e33
macwilko
macwilko16mo ago
d1c85c02-8ca5-43c3-adc6-4a24cb066e33
Solution
Brody
Brody16mo ago
is this helpful?
macwilko
macwilko16mo ago
Thankyou I’ll try it and reply here
#7 [stage-0 3/15] COPY .nixpacks/nixpkgs-293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.nix .nixpacks/nixpkgs-293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.nix
#7 CACHED

#8 [stage-0 4/15] RUN nix-env -if .nixpacks/nixpkgs-293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.nix && nix-collect-garbage -d
#8 CACHED

#9 [stage-0 5/15] RUN apt-get update && apt-get install -y --no-install-recommends default-libmysqlclient-dev procps default-libmysqlclient-dev git curl autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
#9 CACHED

#10 [stage-0 6/15] RUN curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash -s stable && printf '\neval "$(~/.rbenv/bin/rbenv init -)"' >> /root/.profile && . /root/.profile && rbenv install 3.2.2 && rbenv global 3.2.2 && gem install bundler:2.4.6

#10 1.149 Installing rbenv with git...
#10 1.160 Initialized empty Git repository in /root/.rbenv/.git/
#10 1.160 hint: Using 'master' as the name for the initial branch. This default branch name
#10 1.160 hint: is subject to change. To configure the initial branch name to use in all
#10 1.160 hint: of your new repositories, which will suppress this warning, call:
#10 1.160 hint:
#10 1.160 hint: git config --global init.defaultBranch <name>
#10 1.160 hint:

#10 1.160 hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
#10 1.160 hint: 'development'. The just-created branch can be renamed via this command:
#10 1.160 hint:
#10 1.160 hint: git branch -m <name>
#10 1.172 Updating origin

#10 1.808 From https://github.com/rbenv/rbenv
#10 1.808 * [new branch] master -> origin/master
#10 1.836 * [new tag] v0.1.0 -> v0.1.0
#10 1.836 * [new tag] v0.1.1 -> v0.1.1
#10 1.836 * [new tag] v0.1.2 -> v0.1.2
#10 1.836 * [new tag] v0.2.0 -> v0.2.0
#10 1.836 * [new tag] v0.2.1 -> v0.2.1
#10 1.836 * [new tag] v0.3.0 -> v0.3.0
#10 1.836 * [new tag] v0.4.0 -> v0.4.0
#10 1.836 * [new tag] v1.0.0 -> v1.0.0
#10 1.836 * [new tag] v1.1.0 -> v1.1.0

#10 1.836 * [new tag] v1.1.1 -> v1.1.1
#10 1.836 * [new tag] v1.1.2 -> v1.1.2
#10 1.836 * [new tag] v1.2.0 -> v1.2.0
#10 1.861 Already on 'master'
#10 1.861 Branch 'master' set up to track remote branch 'master' from 'origin'.

#10 1.884
#10 1.884 Installing ruby-build with git...
#10 1.900 Cloning into '/root/.rbenv/plugins/ruby-build'...

#10 2.960
#10 2.960 All done!
#10 2.962 Note that this installer does NOT edit your shell configuration files:
#10 2.962 1. Run `~/.rbenv/bin/rbenv init' to view instructions on how to configure rbenv for your shell.
#10 2.962 2. Launch a new terminal window after editing shell configuration files.
#10 2.962

#10 3.210 To follow progress, use 'tail -f /tmp/ruby-build.20230721073358.132.log' or pass --verbose

#10 3.244 Downloading ruby-3.2.2.tar.gz...
#10 3.244 -> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz

#10 5.642 Installing ruby-3.2.2...

#10 340.3 Installed ruby-3.2.2 to /root/.rbenv/versions/3.2.2
#10 340.3

#10 341.3
#10 341.3 NOTE: to activate this Ruby version as the new default, run: rbenv global 3.2.2
#7 [stage-0 3/15] COPY .nixpacks/nixpkgs-293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.nix .nixpacks/nixpkgs-293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.nix
#7 CACHED

#8 [stage-0 4/15] RUN nix-env -if .nixpacks/nixpkgs-293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.nix && nix-collect-garbage -d
#8 CACHED

#9 [stage-0 5/15] RUN apt-get update && apt-get install -y --no-install-recommends default-libmysqlclient-dev procps default-libmysqlclient-dev git curl autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
#9 CACHED

#10 [stage-0 6/15] RUN curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash -s stable && printf '\neval "$(~/.rbenv/bin/rbenv init -)"' >> /root/.profile && . /root/.profile && rbenv install 3.2.2 && rbenv global 3.2.2 && gem install bundler:2.4.6

#10 1.149 Installing rbenv with git...
#10 1.160 Initialized empty Git repository in /root/.rbenv/.git/
#10 1.160 hint: Using 'master' as the name for the initial branch. This default branch name
#10 1.160 hint: is subject to change. To configure the initial branch name to use in all
#10 1.160 hint: of your new repositories, which will suppress this warning, call:
#10 1.160 hint:
#10 1.160 hint: git config --global init.defaultBranch <name>
#10 1.160 hint:

#10 1.160 hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
#10 1.160 hint: 'development'. The just-created branch can be renamed via this command:
#10 1.160 hint:
#10 1.160 hint: git branch -m <name>
#10 1.172 Updating origin

#10 1.808 From https://github.com/rbenv/rbenv
#10 1.808 * [new branch] master -> origin/master
#10 1.836 * [new tag] v0.1.0 -> v0.1.0
#10 1.836 * [new tag] v0.1.1 -> v0.1.1
#10 1.836 * [new tag] v0.1.2 -> v0.1.2
#10 1.836 * [new tag] v0.2.0 -> v0.2.0
#10 1.836 * [new tag] v0.2.1 -> v0.2.1
#10 1.836 * [new tag] v0.3.0 -> v0.3.0
#10 1.836 * [new tag] v0.4.0 -> v0.4.0
#10 1.836 * [new tag] v1.0.0 -> v1.0.0
#10 1.836 * [new tag] v1.1.0 -> v1.1.0

#10 1.836 * [new tag] v1.1.1 -> v1.1.1
#10 1.836 * [new tag] v1.1.2 -> v1.1.2
#10 1.836 * [new tag] v1.2.0 -> v1.2.0
#10 1.861 Already on 'master'
#10 1.861 Branch 'master' set up to track remote branch 'master' from 'origin'.

#10 1.884
#10 1.884 Installing ruby-build with git...
#10 1.900 Cloning into '/root/.rbenv/plugins/ruby-build'...

#10 2.960
#10 2.960 All done!
#10 2.962 Note that this installer does NOT edit your shell configuration files:
#10 2.962 1. Run `~/.rbenv/bin/rbenv init' to view instructions on how to configure rbenv for your shell.
#10 2.962 2. Launch a new terminal window after editing shell configuration files.
#10 2.962

#10 3.210 To follow progress, use 'tail -f /tmp/ruby-build.20230721073358.132.log' or pass --verbose

#10 3.244 Downloading ruby-3.2.2.tar.gz...
#10 3.244 -> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz

#10 5.642 Installing ruby-3.2.2...

#10 340.3 Installed ruby-3.2.2 to /root/.rbenv/versions/3.2.2
#10 340.3

#10 341.3
#10 341.3 NOTE: to activate this Ruby version as the new default, run: rbenv global 3.2.2
It's not clear to me if YJIT is enabled after the ENV variable was set OK I can test something i believe RubyVM::YJIT.enabled?
Matts-Workhorse:zen-api wilko$ railway shell
No service linked, skipping service variables
Entering subshell with Railway variables available. Type 'exit' to exit.
bash-3.2$ irb
3.2.2 :001 > RubyVM::YJIT.enabled?
=> false
3.2.2 :002 >
Matts-Workhorse:zen-api wilko$ railway shell
No service linked, skipping service variables
Entering subshell with Railway variables available. Type 'exit' to exit.
bash-3.2$ irb
3.2.2 :001 > RubyVM::YJIT.enabled?
=> false
3.2.2 :002 >
seems to not be enabled OK! I've fixed it !
Entering subshell with Railway variables available. Type 'exit' to exit.
bash-3.2$ RUBY_YJIT_ENABLE=1 irb
3.2.2 :001 > RubyVM::YJIT.enabled?
=> true
Entering subshell with Railway variables available. Type 'exit' to exit.
bash-3.2$ RUBY_YJIT_ENABLE=1 irb
3.2.2 :001 > RubyVM::YJIT.enabled?
=> true
I think the way to do this is configure the NIXPACKS_START_CMD with something like
RUBY_YJIT_ENABLE=1 rails s -e production
RUBY_YJIT_ENABLE=1 rails s -e production
yep, confirmed:
2023-07-21T08:35:53.164Z pid=1 tid=4ah INFO: Running in ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [x86_64-linux]
2023-07-21T08:35:53.164Z pid=1 tid=4ah INFO: Running in ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [x86_64-linux]
Brody
Brody16mo ago
railway shell is a local shell on your computer, it is not a shell within your deployment
macwilko
macwilko16mo ago
Thanks Brody
Brody
Brody16mo ago
did you set this as a service variable?
macwilko
macwilko16mo ago
There's one thing I'm gonna do Rails.logger.info RUBY_DESCRIPTION that will print out something to the effect of ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22 one sec I know YJIT is working fine on the workers but honestly don't know if it applied to the Web process
Brody
Brody16mo ago
sounds good for context I have zero knowledge of ruby
macwilko
macwilko16mo ago
me too! ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [x86_64-linux] working good logged from the web process
Brody
Brody16mo ago
success?
macwilko
macwilko16mo ago
yeah!
Brody
Brody16mo ago
awesome!!
macwilko
macwilko16mo ago
ty!
Brody
Brody16mo ago
no problem!!
Want results from more Discord servers?
Add your server