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

Closed

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?

@justin808
Copy link
Member

@AbanoubGhadban @Judahmeek should we close?

@justin808
Copy link
Member

@alexeyr-ci1 @alexeyr-ci Please advise on the next step for this:

  1. Update and merge?
  2. Close?
  3. What else?

@alexeyr-ci
Copy link
Collaborator

@justin808

Please advise on the next step for this:

In my opinion:

  1. this particular PR should be closed;
  2. we should have a benchmark script
    1. without adding new runtimes, but ideally so it can easily be applied to them in a branch/fork or in RoRP.
    2. use a tool like Hey or K6 (we'll need HTTP/2 support) instead of doing it manually https://grafana.com/blog/2020/03/03/open-source-load-testing-tool-review/#scriptable-tools-vs-non-scriptable-ones

@justin808
Copy link
Member

@alexeyr-ci close this after opening issues for your suggestions.

Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@alexeyr-ci
Copy link
Collaborator

The new issue: #1658.

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

Successfully merging this pull request may close these issues.

4 participants