Ver Fonte

[ruby/grape] Use Iodine instead of Unicorn (#10335)

Unicorn is no longer maintained.
Replace with Iodine, as it performs better in these benchmarks.
Petrik de Heus há 2 semanas atrás
pai
commit
c9cfe77ef6

+ 8 - 2
frameworks/Ruby/grape/Gemfile

@@ -1,8 +1,14 @@
 source 'https://rubygems.org'
 source 'https://rubygems.org'
 
 
 gem 'mysql2', '0.5.6'
 gem 'mysql2', '0.5.6'
-gem 'unicorn', '6.1.0'
-gem 'puma', '~> 7.1'
 gem 'activerecord', '~> 8.1.0', :require => 'active_record'
 gem 'activerecord', '~> 8.1.0', :require => 'active_record'
 gem 'grape', '2.1.1'
 gem 'grape', '2.1.1'
 gem 'json', '~> 2.9'
 gem 'json', '~> 2.9'
+
+group :iodine, optional: true do
+  gem "iodine", "~> 0.7", require: false
+end
+
+group :puma, optional: true do
+  gem "puma", "~> 7.1", require: false
+end

+ 2 - 6
frameworks/Ruby/grape/Gemfile.lock

@@ -50,8 +50,8 @@ GEM
       zeitwerk
       zeitwerk
     i18n (1.14.7)
     i18n (1.14.7)
       concurrent-ruby (~> 1.0)
       concurrent-ruby (~> 1.0)
+    iodine (0.7.58)
     json (2.16.0)
     json (2.16.0)
-    kgio (2.11.4)
     logger (1.6.6)
     logger (1.6.6)
     minitest (5.25.4)
     minitest (5.25.4)
     mustermann (3.0.3)
     mustermann (3.0.3)
@@ -63,15 +63,11 @@ GEM
     puma (7.1.0)
     puma (7.1.0)
       nio4r (~> 2.0)
       nio4r (~> 2.0)
     rack (3.2.3)
     rack (3.2.3)
-    raindrops (0.20.1)
     ruby2_keywords (0.0.5)
     ruby2_keywords (0.0.5)
     securerandom (0.4.1)
     securerandom (0.4.1)
     timeout (0.4.3)
     timeout (0.4.3)
     tzinfo (2.0.6)
     tzinfo (2.0.6)
       concurrent-ruby (~> 1.0)
       concurrent-ruby (~> 1.0)
-    unicorn (6.1.0)
-      kgio (~> 2.6)
-      raindrops (~> 0.7)
     uri (1.0.3)
     uri (1.0.3)
     zeitwerk (2.7.2)
     zeitwerk (2.7.2)
 
 
@@ -83,10 +79,10 @@ PLATFORMS
 DEPENDENCIES
 DEPENDENCIES
   activerecord (~> 8.1.0)
   activerecord (~> 8.1.0)
   grape (= 2.1.1)
   grape (= 2.1.1)
+  iodine (~> 0.7)
   json (~> 2.9)
   json (~> 2.9)
   mysql2 (= 0.5.6)
   mysql2 (= 0.5.6)
   puma (~> 7.1)
   puma (~> 7.1)
-  unicorn (= 6.1.0)
 
 
 BUNDLED WITH
 BUNDLED WITH
    2.7.0
    2.7.0

+ 3 - 3
frameworks/Ruby/grape/README.md

@@ -12,9 +12,9 @@ comparing a variety of web servers.
 The tests were run with:
 The tests were run with:
 
 
 * [Ruby 3.4](http://www.ruby-lang.org/)
 * [Ruby 3.4](http://www.ruby-lang.org/)
-* [Grape 2.0.0](http://www.ruby-grape.org/)
-* [Unicorn 6.1.0](https://yhbt.net/unicorn/)
-* [Puma 6.4](https://puma.io/)
+* [Grape 2.1](http://www.ruby-grape.org/)
+* [Iodine](https://github.com/boazsegev/iodine)
+* [Puma 7](https://puma.io/)
 
 
 ## Paths & Source for Tests
 ## Paths & Source for Tests
 
 

+ 4 - 4
frameworks/Ruby/grape/benchmark_config.json

@@ -22,7 +22,7 @@
       "notes": "",
       "notes": "",
       "versus": "rack-puma-mri"
       "versus": "rack-puma-mri"
     },
     },
-    "unicorn": {
+    "iodine": {
       "json_url": "/json",
       "json_url": "/json",
       "db_url": "/db",
       "db_url": "/db",
       "query_url": "/query?queries=",
       "query_url": "/query?queries=",
@@ -36,12 +36,12 @@
       "language": "Ruby",
       "language": "Ruby",
       "orm": "Full",
       "orm": "Full",
       "platform": "Rack",
       "platform": "Rack",
-      "webserver": "Unicorn",
+      "webserver": "Iodine",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
-      "display_name": "grape [unicorn]",
+      "display_name": "grape [iodine]",
       "notes": "",
       "notes": "",
-      "versus": "rack-unicorn-mri"
+      "versus": "rack-iodine-mri"
     }
     }
   }]
   }]
 }
 }

+ 1 - 1
frameworks/Ruby/grape/config.ru

@@ -79,7 +79,7 @@ module Acme
   class API < Grape::API
   class API < Grape::API
     before do
     before do
       header 'Date', Time.now.httpdate if defined?(Puma)
       header 'Date', Time.now.httpdate if defined?(Puma)
-      header 'Server', 'WebServer'
+      header 'Server', 'grape'
     end
     end
     logger nil
     logger nil
     content_type :json, 'application/json'
     content_type :json, 'application/json'

+ 3 - 3
frameworks/Ruby/grape/config.toml

@@ -17,7 +17,7 @@ platform = "Rack"
 webserver = "Puma"
 webserver = "Puma"
 versus = "rack-puma-mri"
 versus = "rack-puma-mri"
 
 
-[unicorn]
+[iodine]
 urls.plaintext = "/plaintext"
 urls.plaintext = "/plaintext"
 urls.json = "/json"
 urls.json = "/json"
 urls.db = "/db"
 urls.db = "/db"
@@ -30,5 +30,5 @@ database_os = "Linux"
 os = "Linux"
 os = "Linux"
 orm = "Full"
 orm = "Full"
 platform = "Rack"
 platform = "Rack"
-webserver = "Unicorn"
-versus = "rack-unicorn-mri"
+webserver = "Iodine"
+versus = "rack-iodine-mri"

+ 0 - 158
frameworks/Ruby/grape/config/nginx.conf

@@ -1,158 +0,0 @@
-# This is example contains the bare mininum to get nginx going with
-# Unicorn or Rainbows! servers.  Generally these configuration settings
-# are applicable to other HTTP application servers (and not just Ruby
-# ones), so if you have one working well for proxying another app
-# server, feel free to continue using it.
-#
-# The only setting we feel strongly about is the fail_timeout=0
-# directive in the "upstream" block.  max_fails=0 also has the same
-# effect as fail_timeout=0 for current versions of nginx and may be
-# used in its place.
-#
-# Users are strongly encouraged to refer to nginx documentation for more
-# details and search for other example configs.
-
-# you generally only need one nginx worker unless you're serving
-# large amounts of static files which require blocking disk reads
-worker_processes 8;
-
-# # drop privileges, root is needed on most systems for binding to port 80
-# # (or anything < 1024).  Capability-based security may be available for
-# # your system and worth checking out so you won't need to be root to
-# # start nginx to bind on 80
-# user nobody nogroup; # for systems with a "nogroup"
-#user nobody nobody; # for systems with "nobody" as a group instead
-
-# Feel free to change all paths to suite your needs here, of course
-pid /tmp/nginx.pid;
-#error_log /tmp/nginx.error.log;
-error_log stderr error;
-
-events {
-  worker_connections 4096; # increase if you have lots of clients
-  accept_mutex off; # "on" if nginx worker_processes > 1
-  use epoll; # enable for Linux 2.6+
-  # use kqueue; # enable for FreeBSD, OSX
-}
-
-http {
-  # nginx will find this file in the config directory set at nginx build time
-  include /etc/nginx/mime.types;
-
-  # fallback in case we can't determine a type
-  default_type application/octet-stream;
-
-  # click tracking!
-  #access_log /tmp/nginx.access.log combined;
-  access_log off;
-
-  # you generally want to serve static files with nginx since neither
-  # Unicorn nor Rainbows! is optimized for it at the moment
-  sendfile on;
-
-  tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
-  tcp_nodelay off; # on may be better for some Comet/long-poll stuff
-
-  # we haven't checked to see if Rack::Deflate on the app server is
-  # faster or not than doing compression via nginx.  It's easier
-  # to configure it all in one place here for static files and also
-  # to disable gzip for clients who don't get gzip/deflate right.
-  # There are other gzip settings that may be needed used to deal with
-  # bad clients out there, see http://wiki.nginx.org/NginxHttpGzipModule
-  #gzip on;
-  #gzip_http_version 1.0;
-  #gzip_proxied any;
-  #gzip_min_length 500;
-  #gzip_disable "MSIE [1-6]\.";
-  #gzip_types text/plain text/html text/xml text/css
-  #           text/comma-separated-values
-  #           text/javascript application/x-javascript
-  #           application/atom+xml;
-
-  # this can be any application server, not just Unicorn/Rainbows!
-  upstream app_server {
-    # fail_timeout=0 means we always retry an upstream even if it failed
-    # to return a good HTTP response (in case the Unicorn master nukes a
-    # single worker for timing out).
-
-    # for UNIX domain socket setups:
-    server unix:/tmp/unicorn.sock fail_timeout=0;
-
-    # for TCP setups, point these to your backend servers
-    # server 192.168.0.7:8080 fail_timeout=0;
-    # server 192.168.0.8:8080 fail_timeout=0;
-    # server 192.168.0.9:8080 fail_timeout=0;
-  }
-
-  server {
-    # enable one of the following if you're on Linux or FreeBSD
-    listen 8080 default deferred; # for Linux
-    # listen 80 default accept_filter=httpready; # for FreeBSD
-
-    # If you have IPv6, you'll likely want to have two separate listeners.
-    # One on IPv4 only (the default), and another on IPv6 only instead
-    # of a single dual-stack listener.  A dual-stack listener will make
-    # for ugly IPv4 addresses in $remote_addr (e.g ":ffff:10.0.0.1"
-    # instead of just "10.0.0.1") and potentially trigger bugs in
-    # some software.
-    # listen [::]:80 ipv6only=on; # deferred or accept_filter recommended
-
-    client_max_body_size 4G;
-    server_name _;
-
-    # ~2 seconds is often enough for most folks to parse HTML/CSS and
-    # retrieve needed images/icons/frames, connections are cheap in
-    # nginx so increasing this is generally safe...
-    keepalive_timeout 10;
-
-    # path for static files
-    root /path/to/app/current/public;
-
-    # Prefer to serve static files directly from nginx to avoid unnecessary
-    # data copies from the application server.
-    #
-    # try_files directive appeared in in nginx 0.7.27 and has stabilized
-    # over time.  Older versions of nginx (e.g. 0.6.x) requires
-    # "if (!-f $request_filename)" which was less efficient:
-    # http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
-    try_files $uri/index.html $uri.html $uri @app;
-
-    location @app {
-      # an HTTP header important enough to have its own Wikipedia entry:
-      #   http://en.wikipedia.org/wiki/X-Forwarded-For
-      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
-      # enable this if you forward HTTPS traffic to unicorn,
-      # this helps Rack set the proper URL scheme for doing redirects:
-      # proxy_set_header X-Forwarded-Proto $scheme;
-
-      # pass the Host: header from the client right along so redirects
-      # can be set properly within the Rack application
-      proxy_set_header Host $http_host;
-
-      # we don't want nginx trying to do something clever with
-      # redirects, we set the Host: header above already.
-      proxy_redirect off;
-
-      # set "proxy_buffering off" *only* for Rainbows! when doing
-      # Comet/long-poll/streaming.  It's also safe to set if you're using
-      # only serving fast clients with Unicorn + nginx, but not slow
-      # clients.  You normally want nginx to buffer responses to slow
-      # clients, even with Rails 3.1 streaming because otherwise a slow
-      # client can become a bottleneck of Unicorn.
-      #
-      # The Rack application may also set "X-Accel-Buffering (yes|no)"
-      # in the response headers do disable/enable buffering on a
-      # per-response basis.
-      # proxy_buffering off;
-
-      proxy_pass http://app_server;
-    }
-
-    # Rails error pages
-    error_page 500 502 503 504 /500.html;
-    location = /500.html {
-      root /path/to/app/current/public;
-    }
-  }
-}

+ 0 - 15
frameworks/Ruby/grape/config/unicorn.rb

@@ -1,15 +0,0 @@
-require_relative 'auto_tune'
-
-num_workers, = auto_tune
-worker_processes num_workers
-
-listen "/tmp/unicorn.sock", :backlog => 4096
-
-preload_app true
-GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
-
-before_fork do |server, worker|
-end
-
-after_fork do |server, worker|
-end

+ 4 - 1
frameworks/Ruby/grape/grape-unicorn.dockerfile → frameworks/Ruby/grape/grape-iodine.dockerfile

@@ -13,8 +13,11 @@ ADD ./ /grape
 
 
 WORKDIR /grape
 WORKDIR /grape
 
 
+RUN bundle config set with 'iodine'
 RUN bundle install --jobs=4 --gemfile=/grape/Gemfile
 RUN bundle install --jobs=4 --gemfile=/grape/Gemfile
 
 
+ENV RACK_ENV=production
+
 EXPOSE 8080
 EXPOSE 8080
 
 
-CMD nginx -c /grape/config/nginx.conf && bundle exec unicorn -E production -c config/unicorn.rb
+CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1)

+ 1 - 0
frameworks/Ruby/grape/grape.dockerfile

@@ -11,6 +11,7 @@ ADD ./ /grape
 
 
 WORKDIR /grape
 WORKDIR /grape
 
 
+RUN bundle config set with 'puma'
 RUN bundle install --jobs=4 --gemfile=/grape/Gemfile
 RUN bundle install --jobs=4 --gemfile=/grape/Gemfile
 
 
 ENV WEB_CONCURRENCY=auto
 ENV WEB_CONCURRENCY=auto