Skip to content

Commit ce32f4b

Browse files
committed
Keep renderer benchmarks on the active wire protocol
1 parent e283277 commit ce32f4b

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

benchmarks/bench-node-renderer.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def read_password_from_config
4141
BASE_URL = env_or_default("BASE_URL", "localhost:3800")
4242
PROTOCOL_VERSION = read_protocol_version
4343
LOAD_GENERATOR_SHARDS = env_or_default("LOAD_GENERATOR_SHARDS", 1).to_i
44+
RAW_RENDER_CONTENT_TYPE = "application/vnd.react-on-rails.render-request+javascript"
45+
RAW_RENDER_PROTOCOL_HEADER = "X-React-On-Rails-Pro-Protocol-Version"
4446

4547
# Test cases: JavaScript expressions to evaluate
4648
# Format: { name: "test_name", request: "javascript_code", rsc: true/false }
@@ -105,8 +107,10 @@ def rsc_bundle?(bundle_timestamp)
105107
# Use curl with h2c since Net::HTTP doesn't support HTTP/2
106108
result, status = Open3.capture2(
107109
"curl", "-s", "--http2-prior-knowledge", "-X", "POST",
108-
"-H", "Content-Type: application/x-www-form-urlencoded",
109-
"-d", body,
110+
"-H", "Content-Type: #{RAW_RENDER_CONTENT_TYPE}",
111+
"-H", "#{RAW_RENDER_PROTOCOL_HEADER}: #{PROTOCOL_VERSION}",
112+
"-H", "Authorization: Bearer #{PASSWORD}",
113+
"--data-binary", body,
110114
url
111115
)
112116
return nil unless status.success?
@@ -145,23 +149,14 @@ def categorize_bundles(bundles)
145149
[rsc_bundle, non_rsc_bundle]
146150
end
147151

148-
# URL-encode special characters for form body
149-
def url_encode(str)
150-
URI.encode_www_form_component(str)
151-
end
152-
153152
# Build render URL for a bundle and render name
154153
def render_url(bundle_timestamp, render_name)
155154
"http://#{BASE_URL}/bundles/#{bundle_timestamp}/render/#{render_name}"
156155
end
157156

158157
# Build request body for a rendering request
159158
def render_body(rendering_request)
160-
[
161-
"protocolVersion=#{url_encode(PROTOCOL_VERSION)}",
162-
"password=#{url_encode(PASSWORD)}",
163-
"renderingRequest=#{url_encode(rendering_request)}"
164-
].join("&")
159+
rendering_request
165160
end
166161

167162
def validate_node_renderer_benchmark_config!
@@ -380,7 +375,9 @@ def run_vegeta_benchmark(test_case, bundle_timestamp, shard_count: LOAD_GENERATO
380375
# Write targets file (Vegeta format with @body reference)
381376
File.write(targets_file, <<~TARGETS)
382377
POST #{target_url}
383-
Content-Type: application/x-www-form-urlencoded
378+
Content-Type: #{RAW_RENDER_CONTENT_TYPE}
379+
#{RAW_RENDER_PROTOCOL_HEADER}: #{PROTOCOL_VERSION}
380+
Authorization: Bearer #{PASSWORD}
384381
@#{body_file}
385382
TARGETS
386383

benchmarks/spec/bench_node_renderer_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,32 @@ def add(name:, rps:, p50:, status:, p90: nil)
141141
end
142142

143143
describe "#run_vegeta_benchmark" do
144+
it "sends the rendering request verbatim using the raw renderer protocol" do
145+
stub_const("CONNECTIONS", 1)
146+
stub_const("MAX_CONNECTIONS", 1)
147+
stub_const("RATE", "max")
148+
stub_const("DURATION", "1s")
149+
150+
writes = {}
151+
allow(File).to receive(:write) { |path, contents| writes[path] = contents }
152+
allow(FileUtils).to receive(:rm_f)
153+
allow(Process).to receive_messages(spawn: 1, wait2: [1, process_status(success: true)])
154+
allow(self).to receive_messages(system: true, parse_json_file: { "throughput" => 1,
155+
"latencies" => { "50th" => 1_000_000,
156+
"90th" => 2_000_000 },
157+
"status_codes" => { "200" => 1 } })
158+
159+
rendering_request = 'render({quoted: "value & more"})'
160+
run_vegeta_benchmark({ name: "raw_request", request: rendering_request }, "bundleX", shard_count: 1)
161+
162+
expect(writes.fetch("#{OUTDIR}/raw_request_vegeta_body.txt")).to eq(rendering_request)
163+
expect(writes.fetch("#{OUTDIR}/raw_request_vegeta_targets.txt")).to include(
164+
"Content-Type: #{RAW_RENDER_CONTENT_TYPE}",
165+
"#{RAW_RENDER_PROTOCOL_HEADER}: #{PROTOCOL_VERSION}",
166+
"Authorization: Bearer #{PASSWORD}"
167+
)
168+
end
169+
144170
it "runs all shards concurrently before merging their result streams into one Vegeta report" do
145171
stub_const("CONNECTIONS", 10)
146172
stub_const("MAX_CONNECTIONS", 10)

0 commit comments

Comments
 (0)