Browse Source

[rails] Add Falcon benchmarks (#9339)

Falcon is an async server for Ruby.
Petrik de Heus 9 months ago
parent
commit
e5cffb4bc1

+ 2 - 1
frameworks/Ruby/rails/Gemfile

@@ -2,7 +2,8 @@ source 'https://rubygems.org'
 
 gem 'oj', '~> 3.16'
 gem 'pg', '~> 1.5', group: :postgresql
-gem 'puma', '~> 6.4'
+gem 'puma', '~> 6.4', require: false
+gem 'falcon', '~> 0.47', require: false
 gem 'rails', '~> 7.2.0'
 gem 'redis', '~> 5.0'
 gem 'trilogy', '~> 2.8.1', group: :mysql

+ 83 - 11
frameworks/Ruby/rails/Gemfile.lock

@@ -71,23 +71,73 @@ GEM
       minitest (>= 5.1)
       securerandom (>= 0.3)
       tzinfo (~> 2.0, >= 2.0.5)
+    async (2.17.0)
+      console (~> 1.26)
+      fiber-annotation
+      io-event (~> 1.6, >= 1.6.5)
+    async-container (0.18.3)
+      async (~> 2.10)
+    async-http (0.82.1)
+      async (>= 2.10.2)
+      async-pool (~> 0.9)
+      io-endpoint (~> 0.14)
+      io-stream (~> 0.6)
+      metrics (~> 0.12)
+      protocol-http (~> 0.37)
+      protocol-http1 (>= 0.28.1)
+      protocol-http2 (~> 0.19)
+      traces (~> 0.10)
+    async-http-cache (0.4.4)
+      async-http (~> 0.56)
+    async-pool (0.10.1)
+      async (>= 1.25)
+      traces
+    async-service (0.12.0)
+      async
+      async-container (~> 0.16)
     base64 (0.2.0)
     bigdecimal (3.1.8)
     builder (3.3.0)
     concurrent-ruby (1.3.4)
     connection_pool (2.4.1)
+    console (1.27.0)
+      fiber-annotation
+      fiber-local (~> 1.1)
+      json
     crass (1.0.6)
     date (3.3.4)
     drb (2.2.1)
     erubi (1.13.0)
+    falcon (0.48.3)
+      async
+      async-container (~> 0.18)
+      async-http (~> 0.75)
+      async-http-cache (~> 0.4)
+      async-service (~> 0.10)
+      bundler
+      localhost (~> 1.1)
+      openssl (~> 3.0)
+      process-metrics (~> 0.2)
+      protocol-http (~> 0.31)
+      protocol-rack (~> 0.7)
+      samovar (~> 2.3)
+    fiber-annotation (0.2.0)
+    fiber-local (1.1.0)
+      fiber-storage
+    fiber-storage (1.0.0)
     globalid (1.2.1)
       activesupport (>= 6.1)
     i18n (1.14.6)
       concurrent-ruby (~> 1.0)
     io-console (0.7.2)
-    irb (1.14.0)
+    io-endpoint (0.14.0)
+    io-event (1.7.2)
+    io-stream (0.6.0)
+    irb (1.14.1)
       rdoc (>= 4.0.0)
       reline (>= 0.4.2)
+    json (2.7.2)
+    localhost (1.3.1)
     logger (1.6.1)
     loofah (2.22.0)
       crass (~> 1.0.2)
@@ -97,11 +147,13 @@ GEM
       net-imap
       net-pop
       net-smtp
+    mapping (1.1.1)
     marcel (1.0.4)
+    metrics (0.12.0)
     mini_mime (1.1.5)
     mini_portile2 (2.8.7)
     minitest (5.25.1)
-    net-imap (0.4.14)
+    net-imap (0.4.17)
       date
       net-protocol
     net-pop (0.1.2)
@@ -118,14 +170,29 @@ GEM
       racc (~> 1.4)
     nokogiri (1.16.7-x86_64-linux)
       racc (~> 1.4)
-    oj (3.16.5)
+    oj (3.16.6)
       bigdecimal (>= 3.0)
       ostruct (>= 0.2)
+    openssl (3.2.0)
     ostruct (0.6.0)
-    pg (1.5.7)
+    pg (1.5.8)
+    process-metrics (0.3.0)
+      console (~> 1.8)
+      json (~> 2)
+      samovar (~> 2.1)
+    protocol-hpack (1.5.1)
+    protocol-http (0.40.0)
+    protocol-http1 (0.28.1)
+      protocol-http (~> 0.22)
+    protocol-http2 (0.19.3)
+      protocol-hpack (~> 1.4)
+      protocol-http (~> 0.18)
+    protocol-rack (0.10.1)
+      protocol-http (~> 0.37)
+      rack (>= 1.0)
     psych (5.1.2)
       stringio
-    puma (6.4.2)
+    puma (6.4.3)
       nio4r (~> 2.0)
     racc (1.8.1)
     rack (3.1.8)
@@ -168,27 +235,31 @@ GEM
     rake (13.2.1)
     rdoc (6.7.0)
       psych (>= 4.0.0)
-    redis (5.2.0)
+    redis (5.3.0)
       redis-client (>= 0.22.0)
     redis-client (0.22.2)
       connection_pool
-    reline (0.5.9)
+    reline (0.5.10)
       io-console (~> 0.5)
+    samovar (2.3.0)
+      console (~> 1.0)
+      mapping (~> 1.0)
     securerandom (0.3.1)
     stringio (3.1.1)
-    thor (1.3.1)
+    thor (1.3.2)
     timeout (0.4.1)
+    traces (0.13.1)
     trilogy (2.8.1)
     tzinfo (2.0.6)
       concurrent-ruby (~> 1.0)
-    tzinfo-data (1.2024.1)
+    tzinfo-data (1.2024.2)
       tzinfo (>= 1.0.0)
     useragent (0.16.10)
-    webrick (1.8.1)
+    webrick (1.8.2)
     websocket-driver (0.7.6)
       websocket-extensions (>= 0.1.0)
     websocket-extensions (0.1.5)
-    zeitwerk (2.6.17)
+    zeitwerk (2.7.0)
 
 PLATFORMS
   arm64-darwin-20
@@ -196,6 +267,7 @@ PLATFORMS
   x86_64-linux
 
 DEPENDENCIES
+  falcon (~> 0.47)
   oj (~> 3.16)
   pg (~> 1.5)
   puma (~> 6.4)

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

@@ -44,6 +44,28 @@
       "display_name": "rails-mysql",
       "notes": "",
       "versus": "rack-puma-mri"
+    },
+    "falcon": {
+      "db_url": "/db",
+      "json_url": "/json",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortunes",
+      "update_url": "/updates?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "Postgres",
+      "framework": "rails",
+      "language": "Ruby",
+      "orm": "Full",
+      "platform": "Rack",
+      "webserver": "Falcon",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "rails-falcon",
+      "notes": "",
+      "versus": "rack-falcon-mri"
     }
   }]
 }

+ 2 - 0
frameworks/Ruby/rails/config/application.rb

@@ -51,5 +51,7 @@ module Hello
     config.middleware.delete Rack::Sendfile
     config.middleware.delete Rack::TempfileReaper
     config.middleware.delete Rails::Rack::Logger
+
+    config.active_support.isolation_level = :fiber if defined?(Falcon)
   end
 end

+ 3 - 0
frameworks/Ruby/rails/config/falcon_preload.rb

@@ -0,0 +1,3 @@
+# required by Falcon:
+# https://github.com/socketry/falcon/blob/19fe8ece7cc49aa03222afe2c940682aeb69fe37/guides/rails-integration/readme.md?plain=1#L38
+require_relative "../config/environment"

+ 12 - 0
frameworks/Ruby/rails/falcon.rb

@@ -0,0 +1,12 @@
+#!/usr/bin/env -S falcon host
+# frozen_string_literal: true
+
+load :rack
+
+hostname = File.basename(__dir__)
+port = ENV["PORT"] || 8080
+
+rack hostname do
+  append preload "config/falcon_preload.rb"
+  endpoint Async::HTTP::Endpoint.parse("http://0.0.0.0:#{port}")
+end

+ 26 - 0
frameworks/Ruby/rails/rails-falcon.dockerfile

@@ -0,0 +1,26 @@
+FROM ruby:3.4-rc
+
+RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends redis-server
+
+EXPOSE 8080
+WORKDIR /rails
+
+# ENV RUBY_YJIT_ENABLE=1 YJIT is enabled in config/initializers/enable_yjit.rb
+
+# Use Jemalloc
+RUN apt-get update && \
+    apt-get install -y --no-install-recommends libjemalloc2
+ENV LD_PRELOAD=libjemalloc.so.2
+
+COPY ./Gemfile* /rails/
+
+ENV BUNDLE_FORCE_RUBY_PLATFORM=true
+ENV BUNDLE_WITHOUT=mysql
+RUN bundle install --jobs=8
+
+COPY . /rails/
+
+ENV RAILS_ENV=production_postgresql
+ENV PORT=8080
+ENV REDIS_URL=redis://localhost:6379/0
+CMD bundle exec falcon host

+ 1 - 1
frameworks/Ruby/rails/rails.dockerfile

@@ -15,7 +15,7 @@ ENV LD_PRELOAD=libjemalloc.so.2
 COPY ./Gemfile* /rails/
 
 ENV BUNDLE_FORCE_RUBY_PLATFORM=true
-ENV BUNDLE_WITHOUT=trilogy
+ENV BUNDLE_WITHOUT=mysql
 RUN bundle install --jobs=8
 
 COPY . /rails/

+ 1 - 1
frameworks/Ruby/rails/run-with-redis.sh

@@ -1,3 +1,3 @@
 #!/bin/bash
 service redis-server start
-rails server
+bundle exec falcon host