Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR benchmark script #1555

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wyattades
Copy link
Contributor

@wyattades wyattades commented Jul 15, 2023

Summary

Add some instructions and a script to perform performance benchmarking on some server-side-rendering routes. The goal is to test the performance of different ExecJS runtimes in a real react_on_rails application.

Things to-do before merging. I'd appreciate some guidance to get them working:

  • fix the nodejs runtime
  • fix hitting the React routes on the dummy app

Anecdotal results:

I ran this against a route on my app with very expensive React SSR.
This is the total roundtrip duration of the request, so it also includes some database IO.
Device: M1 Macbook Pro 2021

  • alaska:
    • first call: 800ms
    • subsequent calls: 62ms
  • nodejs 18:
    • first call: 600ms
    • subsequent calls: 300ms
  • mini_racer:
    • first call: 260ms
    • subsequent calls: 70ms

Pull Request checklist

  • Add/update test to cover these changes
  • Update documentation
  • Update CHANGELOG file
    Add the CHANGELOG entry at the top of the file.

Other Information


This change is Reviewable

@wyattades wyattades mentioned this pull request Jul 15, 2023
3 tasks
@@ -2,7 +2,7 @@

gem "shakapacker", "6.5.1"
gem "bootsnap", require: false
gem "rails", "~> 7.0"
gem "rails", "~> 7.0", ">= 7.0.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for compatibility with Ruby 3.2.1

@@ -24,6 +24,7 @@
"css-minimizer-webpack-plugin": "^3.1.3",
"eslint-plugin-prettier": "^3.1.0",
"expose-loader": "^1.0.3",
"fast-text-encoding": "^1.0.6",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this have to do with SSR?

@@ -51,6 +52,7 @@
"sass-loader": "^12.3.0",
"sass-resources-loader": "^2.1.0",
"shakapacker": "6.5.1",
"stream-browserify": "^3.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this have to do with SSR?

@@ -109,6 +111,31 @@ const configureServer = () => {
// If using the React on Rails Pro node server renderer, uncomment the next line
// serverWebpackConfig.target = 'node'

// MiniRacer specific config
if (process.env.EXECJS_RUNTIME === 'MiniRacer') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you get these from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miniracer needs a couple polyfills for some Node.js modules that are used in React 18 SSR. Here's my original post:
#1457 (comment)
AFAIK this isn't documented anywhere

@justin808
Copy link
Member

justin808 commented Jul 17, 2023

@wyattades Ping me on Slack. I'd like you to test out https://www.shakacode.com/react-on-rails-pro/ vs execjs.

Here's an invite

run_benchmarks Alaska /render_js

# FIXME: all others SSR endpoints are broken with this setup
# e.g. Hitting /server_side_hello_world gives error: "ActionView::Template::Error (Shakapacker can't find generated/HelloWorld.js in manifest.json"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the 2 FIXMEs ^ that I can't figure out. I'm unfamiliar with the generated/* files, can someone give me some advice here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's if you're using the auto bundles, so that you just use react_component and the bundle is included on the page automatically

https://github.com/shakacode/react_on_rails/blob/master/docs/guides/file-system-based-automated-bundle-generation.md

Copy link
Contributor Author

@wyattades wyattades Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I enable the generated routes on the dummy app?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wyattades you'l want to run bundle exec rake react_on_rails:generate_packs as part of the setup.

@@ -109,6 +111,31 @@ const configureServer = () => {
// If using the React on Rails Pro node server renderer, uncomment the next line
// serverWebpackConfig.target = 'node'

// MiniRacer specific config
if (process.env.EXECJS_RUNTIME === 'MiniRacer') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (process.env.EXECJS_RUNTIME === 'MiniRacer') {
if (process.env.MANUAL_EXECJS_RUNTIME === 'MiniRacer') {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explained this webpack code in the github comment above:

Miniracer needs a couple polyfills for some Node.js modules that are used in React 18 SSR

Also, EXECJS_RUNTIME doesn't work (we're using some different name, MANUAL_EXECJS_RUNTIME) because it breaks when trying to autoload the Alaska gem

@justin808
Copy link
Member

@wyattades what's left? you have this PR as draft.


echo "Benchmarking server-side rendering..."

# run_benchmarks Node /render_js # FIXME: Node runtime is broken with this setup, it stalls infinitely.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird.

Because if you uninstall MiniRacer, then ExecJS should use NodeJS by default & that seems to work correctly.

@justin808
Copy link
Member

@Judahmeek @ahangarha any good reason this was NEVER FINISHED?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants