Skip to content

Commit 386f918

Browse files
authored
Merge pull request #749 from p8/rails/allowed-http-methods
[rails] Remove Methodguard middleware
2 parents a1b6c7d + 25577b4 commit 386f918

39 files changed

Lines changed: 686 additions & 698 deletions

frameworks/rails/config/application.rb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,17 @@
33

44
Bundler.require(*Rails.groups)
55

6-
# Catch unknown HTTP methods, routing errors, and mark /upload as binary
7-
class MethodGuard
8-
VALID_METHODS = %w[GET HEAD POST PUT DELETE PATCH OPTIONS TRACE].to_set.freeze
9-
6+
# Mark /upload as binary so Rack skips form parameter parsing
7+
class MarkUploadAsBinary
108
def initialize(app)
119
@app = app
1210
end
1311

1412
def call(env)
15-
unless VALID_METHODS.include?(env['REQUEST_METHOD'])
16-
return [405, { 'content-type' => 'text/plain' }, ['Method Not Allowed']]
17-
end
18-
# Mark /upload as binary so Rack skips form parameter parsing
1913
if env['PATH_INFO'] == '/upload'
2014
env['CONTENT_TYPE'] = 'application/octet-stream'
2115
end
2216
@app.call(env)
23-
rescue => e
24-
if e.class.name.include?('UnknownHttpMethod') || e.class.name.include?('RoutingError')
25-
[400, { 'content-type' => 'text/plain' }, ['Bad Request']]
26-
else
27-
raise
28-
end
2917
end
3018
end
3119

@@ -65,7 +53,7 @@ class BenchmarkApp < Rails::Application
6553

6654
# Add gzip support
6755
config.middleware.insert 0, Rack::Deflater
68-
config.middleware.insert 0, MethodGuard
56+
config.middleware.insert 0, MarkUploadAsBinary
6957
config.middleware.insert 0, MarkAsIOBoundThreads
7058

7159
# Silence logging

site/data/api-16-1024.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -724,28 +724,28 @@
724724
{
725725
"framework": "rails",
726726
"language": "Ruby",
727-
"rps": 24814,
728-
"avg_latency": "40.30ms",
729-
"p99_latency": "130.30ms",
730-
"cpu": "1741.5%",
731-
"memory": "956MiB",
727+
"rps": 25015,
728+
"avg_latency": "39.99ms",
729+
"p99_latency": "129.10ms",
730+
"cpu": "1675.4%",
731+
"memory": "874MiB",
732732
"connections": 1024,
733733
"threads": 64,
734734
"duration": "5s",
735735
"pipeline": 1,
736-
"bandwidth": "130.55MB/s",
737-
"input_bw": "1.40MB/s",
738-
"reconnects": 74318,
739-
"status_2xx": 372223,
736+
"bandwidth": "131.55MB/s",
737+
"input_bw": "1.41MB/s",
738+
"reconnects": 74953,
739+
"status_2xx": 375225,
740740
"status_3xx": 0,
741741
"status_4xx": 0,
742742
"status_5xx": 0,
743-
"tpl_baseline": 139406,
744-
"tpl_json": 139728,
743+
"tpl_baseline": 140651,
744+
"tpl_json": 140741,
745745
"tpl_db": 0,
746746
"tpl_upload": 0,
747747
"tpl_static": 0,
748-
"tpl_async_db": 93088
748+
"tpl_async_db": 93833
749749
},
750750
{
751751
"framework": "ring-http-exchange",

site/data/api-4-256.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -724,28 +724,28 @@
724724
{
725725
"framework": "rails",
726726
"language": "Ruby",
727-
"rps": 9914,
728-
"avg_latency": "25.42ms",
729-
"p99_latency": "101.50ms",
730-
"cpu": "393.4%",
727+
"rps": 9974,
728+
"avg_latency": "25.24ms",
729+
"p99_latency": "98.90ms",
730+
"cpu": "394.6%",
731731
"memory": "309MiB",
732732
"connections": 256,
733733
"threads": 64,
734734
"duration": "5s",
735735
"pipeline": 1,
736-
"bandwidth": "52.15MB/s",
737-
"input_bw": "571.22KB/s",
738-
"reconnects": 29731,
739-
"status_2xx": 148719,
736+
"bandwidth": "52.43MB/s",
737+
"input_bw": "574.67KB/s",
738+
"reconnects": 29915,
739+
"status_2xx": 149617,
740740
"status_3xx": 0,
741741
"status_4xx": 0,
742742
"status_5xx": 0,
743-
"tpl_baseline": 55723,
744-
"tpl_json": 55787,
743+
"tpl_baseline": 56124,
744+
"tpl_json": 56125,
745745
"tpl_db": 0,
746746
"tpl_upload": 0,
747747
"tpl_static": 0,
748-
"tpl_async_db": 37209
748+
"tpl_async_db": 37368
749749
},
750750
{
751751
"framework": "ring-http-exchange",

site/data/async-db-1024.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,19 @@
576576
{
577577
"framework": "rails",
578578
"language": "Ruby",
579-
"rps": 71458,
580-
"avg_latency": "13.68ms",
581-
"p99_latency": "28.70ms",
582-
"cpu": "6322.5%",
583-
"memory": "3.6GiB",
579+
"rps": 70016,
580+
"avg_latency": "14.03ms",
581+
"p99_latency": "30.40ms",
582+
"cpu": "6400.0%",
583+
"memory": "2.9GiB",
584584
"connections": 1024,
585585
"threads": 64,
586586
"duration": "5s",
587587
"pipeline": 1,
588-
"bandwidth": "296.94MB/s",
589-
"input_bw": "4.77MB/s",
590-
"reconnects": 28129,
591-
"status_2xx": 714589,
588+
"bandwidth": "291.08MB/s",
589+
"input_bw": "4.67MB/s",
590+
"reconnects": 27721,
591+
"status_2xx": 700163,
592592
"status_3xx": 0,
593593
"status_4xx": 0,
594594
"status_5xx": 0

site/data/baseline-4096.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,19 @@
869869
{
870870
"framework": "rails",
871871
"language": "Ruby",
872-
"rps": 33180,
873-
"avg_latency": "104.29ms",
874-
"p99_latency": "365.30ms",
875-
"cpu": "4858.3%",
876-
"memory": "6.4GiB",
872+
"rps": 34491,
873+
"avg_latency": "100.31ms",
874+
"p99_latency": "346.90ms",
875+
"cpu": "5030.2%",
876+
"memory": "6.6GiB",
877877
"connections": 4096,
878878
"threads": 64,
879879
"duration": "5s",
880880
"pipeline": 1,
881-
"bandwidth": "6.99MB/s",
882-
"input_bw": "2.56MB/s",
881+
"bandwidth": "7.27MB/s",
882+
"input_bw": "2.66MB/s",
883883
"reconnects": 0,
884-
"status_2xx": 165904,
884+
"status_2xx": 172456,
885885
"status_3xx": 0,
886886
"status_4xx": 0,
887887
"status_5xx": 0

site/data/baseline-512.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,19 @@
869869
{
870870
"framework": "rails",
871871
"language": "Ruby",
872-
"rps": 77647,
873-
"avg_latency": "6.60ms",
874-
"p99_latency": "85.70ms",
875-
"cpu": "5535.9%",
876-
"memory": "6.9GiB",
872+
"rps": 80896,
873+
"avg_latency": "6.34ms",
874+
"p99_latency": "84.80ms",
875+
"cpu": "5651.8%",
876+
"memory": "6.8GiB",
877877
"connections": 512,
878878
"threads": 64,
879879
"duration": "5s",
880880
"pipeline": 1,
881-
"bandwidth": "16.36MB/s",
882-
"input_bw": "6.00MB/s",
883-
"reconnects": 290,
884-
"status_2xx": 388239,
881+
"bandwidth": "17.04MB/s",
882+
"input_bw": "6.25MB/s",
883+
"reconnects": 307,
884+
"status_2xx": 404484,
885885
"status_3xx": 0,
886886
"status_4xx": 0,
887887
"status_5xx": 0

site/data/json-4096.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -656,19 +656,19 @@
656656
{
657657
"framework": "rails",
658658
"language": "Ruby",
659-
"rps": 121800,
660-
"avg_latency": "28.82ms",
661-
"p99_latency": "80.50ms",
662-
"cpu": "6479.0%",
663-
"memory": "3.6GiB",
659+
"rps": 120806,
660+
"avg_latency": "30.45ms",
661+
"p99_latency": "89.40ms",
662+
"cpu": "6330.5%",
663+
"memory": "3.7GiB",
664664
"connections": 4096,
665665
"threads": 64,
666666
"duration": "5s",
667667
"pipeline": 1,
668-
"bandwidth": "434.81MB/s",
669-
"input_bw": "5.81MB/s",
670-
"reconnects": 22406,
671-
"status_2xx": 609001,
668+
"bandwidth": "430.55MB/s",
669+
"input_bw": "5.76MB/s",
670+
"reconnects": 22297,
671+
"status_2xx": 604033,
672672
"status_3xx": 0,
673673
"status_4xx": 0,
674674
"status_5xx": 0

site/data/json-comp-16384.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,19 @@
562562
{
563563
"framework": "rails",
564564
"language": "Ruby",
565-
"rps": 83173,
566-
"avg_latency": "116.31ms",
567-
"p99_latency": "591.00ms",
568-
"cpu": "6188.0%",
569-
"memory": "4.6GiB",
565+
"rps": 84414,
566+
"avg_latency": "108.30ms",
567+
"p99_latency": "556.90ms",
568+
"cpu": "6245.2%",
569+
"memory": "4.9GiB",
570570
"connections": 16384,
571571
"threads": 64,
572572
"duration": "5s",
573573
"pipeline": 1,
574-
"bandwidth": "121.56MB/s",
575-
"input_bw": "6.19MB/s",
576-
"reconnects": 11405,
577-
"status_2xx": 415868,
574+
"bandwidth": "123.36MB/s",
575+
"input_bw": "6.28MB/s",
576+
"reconnects": 11919,
577+
"status_2xx": 422071,
578578
"status_3xx": 0,
579579
"status_4xx": 0,
580580
"status_5xx": 0

site/data/json-comp-4096.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,19 @@
562562
{
563563
"framework": "rails",
564564
"language": "Ruby",
565-
"rps": 83238,
566-
"avg_latency": "45.17ms",
567-
"p99_latency": "92.40ms",
568-
"cpu": "6291.2%",
569-
"memory": "4.1GiB",
565+
"rps": 82184,
566+
"avg_latency": "44.70ms",
567+
"p99_latency": "115.20ms",
568+
"cpu": "6431.4%",
569+
"memory": "3.8GiB",
570570
"connections": 4096,
571571
"threads": 64,
572572
"duration": "5s",
573573
"pipeline": 1,
574-
"bandwidth": "121.64MB/s",
575-
"input_bw": "6.19MB/s",
576-
"reconnects": 14727,
577-
"status_2xx": 416190,
574+
"bandwidth": "120.03MB/s",
575+
"input_bw": "6.11MB/s",
576+
"reconnects": 14674,
577+
"status_2xx": 410923,
578578
"status_3xx": 0,
579579
"status_4xx": 0,
580580
"status_5xx": 0

site/data/json-comp-512.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,19 @@
562562
{
563563
"framework": "rails",
564564
"language": "Ruby",
565-
"rps": 81194,
566-
"avg_latency": "6.30ms",
567-
"p99_latency": "23.80ms",
568-
"cpu": "6354.5%",
569-
"memory": "3.0GiB",
565+
"rps": 83902,
566+
"avg_latency": "6.10ms",
567+
"p99_latency": "24.50ms",
568+
"cpu": "6435.9%",
569+
"memory": "3.7GiB",
570570
"connections": 512,
571571
"threads": 64,
572572
"duration": "5s",
573573
"pipeline": 1,
574-
"bandwidth": "118.67MB/s",
575-
"input_bw": "6.04MB/s",
576-
"reconnects": 16103,
577-
"status_2xx": 405974,
574+
"bandwidth": "122.63MB/s",
575+
"input_bw": "6.24MB/s",
576+
"reconnects": 16740,
577+
"status_2xx": 419511,
578578
"status_3xx": 0,
579579
"status_4xx": 0,
580580
"status_5xx": 0

0 commit comments

Comments
 (0)