ソースを参照

[ruby/sinatra] Add iodine to the tests (#9651)

+--------------+------+-----+-----+------+-------+---------+--------------+
|              |  json|   db|query|update|fortune|plaintext|weighted_score|
+--------------+------+-----+-----+------+-------+---------+--------------+
|        master| 58048|23085|12225|  5170|  12364|    47186|           775|
|sinatra/iodine|103642|41732|31679|  7853|  10708|   100518|          1461|
+--------------+------+-----+-----+------+-------+---------+--------------+
Petrik de Heus 5 ヶ月 前
コミット
7935fc5d70

+ 5 - 1
frameworks/Ruby/sinatra/Gemfile

@@ -12,6 +12,10 @@ group :postgresql, optional: true do
   gem 'pg', '~> 1.5', platforms: [:ruby, :mswin]
 end
 
+group :iodine, optional: true do
+  gem 'iodine', '~> 0.7', platforms: [:ruby, :mswin], require: false
+end
+
 group :passenger, optional: true do
   gem 'passenger', '~> 6.0', platforms: [:ruby, :mswin], require: false
 end
@@ -20,7 +24,7 @@ group :puma, optional: true do
   gem 'puma', '~> 6.4', require: false
 end
 
-group :unicorn do
+group :unicorn, optional: true do
   gem 'unicorn', '~> 6.1', platforms: [:ruby, :mswin], require: false
 end
 

+ 2 - 0
frameworks/Ruby/sinatra/Gemfile.lock

@@ -29,6 +29,7 @@ GEM
     drb (2.2.1)
     i18n (1.14.7)
       concurrent-ruby (~> 1.0)
+    iodine (0.7.58)
     json (2.10.1)
     kgio (2.11.4)
     logger (1.6.6)
@@ -81,6 +82,7 @@ PLATFORMS
 DEPENDENCIES
   activerecord (~> 8.0)
   agoo
+  iodine (~> 0.7)
   json (~> 2.8)
   mysql2 (~> 0.5)
   passenger (~> 6.0)

+ 22 - 0
frameworks/Ruby/sinatra/benchmark_config.json

@@ -66,6 +66,28 @@
         "versus": "rack-postgres-agoo-mri",
         "notes": ""
       },
+      "postgres-iodine-mri": {
+        "json_url": "/json",
+        "db_url": "/db",
+        "query_url": "/queries?queries=",
+        "fortune_url": "/fortunes",
+        "update_url": "/updates?queries=",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "Postgres",
+        "framework": "sinatra",
+        "language": "Ruby",
+        "orm": "Full",
+        "platform": "Rack",
+        "webserver": "Iodine",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "sinatra-postgres-iodine-mri",
+        "versus": "rack-postgres-iodine-mri",
+        "notes": ""
+      },
       "postgres-passenger-mri": {
         "db_url": "/db",
         "query_url": "/queries?queries=",

+ 2 - 0
frameworks/Ruby/sinatra/boot.rb

@@ -15,6 +15,8 @@ SERVER_STRING =
     'puma'
   elsif defined?(Unicorn)
     'unicorn'
+  elsif defined?(Iodine)
+    'iodine'
   elsif defined?(Agoo)
     'agoo'
   end

+ 3 - 0
frameworks/Ruby/sinatra/hello_world.rb

@@ -10,6 +10,9 @@ class HelloWorld < Sinatra::Base
     # XSS, CSRF, IP spoofing, etc. protection are not explicitly required
     disable :protection
 
+    # disable it for all environments
+    set :host_authorization, { permitted_hosts: [] }
+
     # Only add the charset parameter to specific content types per the requirements
     set :add_charset, [mime_type(:html)]
   end

+ 20 - 0
frameworks/Ruby/sinatra/sinatra-postgres-iodine-mri.dockerfile

@@ -0,0 +1,20 @@
+FROM ruby:3.4
+
+ENV RUBY_YJIT_ENABLE=1
+
+# Use Jemalloc
+RUN apt-get update && \
+    apt-get install -y --no-install-recommends libjemalloc2
+ENV LD_PRELOAD=libjemalloc.so.2
+
+ADD ./ /sinatra
+WORKDIR /sinatra
+
+ENV BUNDLE_WITH=postgresql:iodine
+RUN bundle install --jobs=4 --gemfile=/sinatra/Gemfile
+
+ENV DBTYPE=postgresql
+
+EXPOSE 8080
+
+CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1)