-
-
Notifications
You must be signed in to change notification settings - Fork 632
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
SSR benchmark script #1555
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# A simple example of how to benchmark the dummy app. | ||
# | ||
|
||
set -euo pipefail | ||
|
||
shutdown_server() { | ||
if [ -f tmp/pids/server.pid ]; then | ||
kill $(cat tmp/pids/server.pid) | ||
rm -f tmp/pids/server.pid | ||
fi | ||
} | ||
|
||
hit_backend() { | ||
local pathname="$1" | ||
curl "http://localhost:3000$pathname" \ | ||
--max-time 3 \ | ||
--silent \ | ||
--no-progress-meter \ | ||
--fail \ | ||
-w %{time_total} \ | ||
-o /dev/null | ||
} | ||
|
||
run_benchmarks() { | ||
local runtime="$1" | ||
local pathname="$2" | ||
|
||
echo "Benchmarking with $runtime..." | ||
|
||
# start dummy app server in background | ||
MANUAL_EXECJS_RUNTIME="$runtime" \ | ||
RAILS_ENV=production \ | ||
bundle exec rails s -p 3000 & | ||
|
||
sleep 3 # wait for server to start | ||
|
||
echo "Warmup: $(hit_backend $pathname)" | ||
|
||
durations=() | ||
for i in {1..10}; do | ||
dur=$(hit_backend $pathname) | ||
durations+=("$dur") | ||
echo "Request $i: ${dur}s" | ||
done | ||
|
||
echo "$runtime average: $(echo "${durations[*]}" | awk '{ total += $1 } END { print total/NR }')s" | ||
|
||
shutdown_server | ||
} | ||
|
||
# If you modified `node_package` files, first follow the | ||
# instructions in CONTRIBUTING.md to setup `yalc`. | ||
|
||
# Build server-rendering assets: | ||
# yarn build:rescript # if needed | ||
rm -rf public/webpack | ||
RAILS_ENV=production NODE_ENV=production bin/webpacker | ||
|
||
# kill server on exit | ||
trap shutdown_server EXIT | ||
|
||
# kill any existing server | ||
shutdown_server | ||
|
||
# remove any existing logs | ||
rm -f log/*.log | ||
|
||
echo "Benchmarking server-side rendering..." | ||
|
||
# run_benchmarks Node /render_js # FIXME: Node runtime is broken with this setup, it stalls infinitely. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
run_benchmarks MiniRacer /render_js | ||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I enable the generated routes on the dummy app? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wyattades you'l want to run |
||
|
||
echo "Benchmarking complete!" |
There was a problem hiding this comment.
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