Skip to content

Commit e5cffb4

Browse files
authored
[rails] Add Falcon benchmarks (#9339)
Falcon is an async server for Ruby.
1 parent 2f858b0 commit e5cffb4

File tree

9 files changed

+152
-14
lines changed

9 files changed

+152
-14
lines changed

frameworks/Ruby/rails/Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ source 'https://rubygems.org'
22

33
gem 'oj', '~> 3.16'
44
gem 'pg', '~> 1.5', group: :postgresql
5-
gem 'puma', '~> 6.4'
5+
gem 'puma', '~> 6.4', require: false
6+
gem 'falcon', '~> 0.47', require: false
67
gem 'rails', '~> 7.2.0'
78
gem 'redis', '~> 5.0'
89
gem 'trilogy', '~> 2.8.1', group: :mysql

frameworks/Ruby/rails/Gemfile.lock

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,73 @@ GEM
7171
minitest (>= 5.1)
7272
securerandom (>= 0.3)
7373
tzinfo (~> 2.0, >= 2.0.5)
74+
async (2.17.0)
75+
console (~> 1.26)
76+
fiber-annotation
77+
io-event (~> 1.6, >= 1.6.5)
78+
async-container (0.18.3)
79+
async (~> 2.10)
80+
async-http (0.82.1)
81+
async (>= 2.10.2)
82+
async-pool (~> 0.9)
83+
io-endpoint (~> 0.14)
84+
io-stream (~> 0.6)
85+
metrics (~> 0.12)
86+
protocol-http (~> 0.37)
87+
protocol-http1 (>= 0.28.1)
88+
protocol-http2 (~> 0.19)
89+
traces (~> 0.10)
90+
async-http-cache (0.4.4)
91+
async-http (~> 0.56)
92+
async-pool (0.10.1)
93+
async (>= 1.25)
94+
traces
95+
async-service (0.12.0)
96+
async
97+
async-container (~> 0.16)
7498
base64 (0.2.0)
7599
bigdecimal (3.1.8)
76100
builder (3.3.0)
77101
concurrent-ruby (1.3.4)
78102
connection_pool (2.4.1)
103+
console (1.27.0)
104+
fiber-annotation
105+
fiber-local (~> 1.1)
106+
json
79107
crass (1.0.6)
80108
date (3.3.4)
81109
drb (2.2.1)
82110
erubi (1.13.0)
111+
falcon (0.48.3)
112+
async
113+
async-container (~> 0.18)
114+
async-http (~> 0.75)
115+
async-http-cache (~> 0.4)
116+
async-service (~> 0.10)
117+
bundler
118+
localhost (~> 1.1)
119+
openssl (~> 3.0)
120+
process-metrics (~> 0.2)
121+
protocol-http (~> 0.31)
122+
protocol-rack (~> 0.7)
123+
samovar (~> 2.3)
124+
fiber-annotation (0.2.0)
125+
fiber-local (1.1.0)
126+
fiber-storage
127+
fiber-storage (1.0.0)
83128
globalid (1.2.1)
84129
activesupport (>= 6.1)
85130
i18n (1.14.6)
86131
concurrent-ruby (~> 1.0)
87132
io-console (0.7.2)
88-
irb (1.14.0)
133+
io-endpoint (0.14.0)
134+
io-event (1.7.2)
135+
io-stream (0.6.0)
136+
irb (1.14.1)
89137
rdoc (>= 4.0.0)
90138
reline (>= 0.4.2)
139+
json (2.7.2)
140+
localhost (1.3.1)
91141
logger (1.6.1)
92142
loofah (2.22.0)
93143
crass (~> 1.0.2)
@@ -97,11 +147,13 @@ GEM
97147
net-imap
98148
net-pop
99149
net-smtp
150+
mapping (1.1.1)
100151
marcel (1.0.4)
152+
metrics (0.12.0)
101153
mini_mime (1.1.5)
102154
mini_portile2 (2.8.7)
103155
minitest (5.25.1)
104-
net-imap (0.4.14)
156+
net-imap (0.4.17)
105157
date
106158
net-protocol
107159
net-pop (0.1.2)
@@ -118,14 +170,29 @@ GEM
118170
racc (~> 1.4)
119171
nokogiri (1.16.7-x86_64-linux)
120172
racc (~> 1.4)
121-
oj (3.16.5)
173+
oj (3.16.6)
122174
bigdecimal (>= 3.0)
123175
ostruct (>= 0.2)
176+
openssl (3.2.0)
124177
ostruct (0.6.0)
125-
pg (1.5.7)
178+
pg (1.5.8)
179+
process-metrics (0.3.0)
180+
console (~> 1.8)
181+
json (~> 2)
182+
samovar (~> 2.1)
183+
protocol-hpack (1.5.1)
184+
protocol-http (0.40.0)
185+
protocol-http1 (0.28.1)
186+
protocol-http (~> 0.22)
187+
protocol-http2 (0.19.3)
188+
protocol-hpack (~> 1.4)
189+
protocol-http (~> 0.18)
190+
protocol-rack (0.10.1)
191+
protocol-http (~> 0.37)
192+
rack (>= 1.0)
126193
psych (5.1.2)
127194
stringio
128-
puma (6.4.2)
195+
puma (6.4.3)
129196
nio4r (~> 2.0)
130197
racc (1.8.1)
131198
rack (3.1.8)
@@ -168,34 +235,39 @@ GEM
168235
rake (13.2.1)
169236
rdoc (6.7.0)
170237
psych (>= 4.0.0)
171-
redis (5.2.0)
238+
redis (5.3.0)
172239
redis-client (>= 0.22.0)
173240
redis-client (0.22.2)
174241
connection_pool
175-
reline (0.5.9)
242+
reline (0.5.10)
176243
io-console (~> 0.5)
244+
samovar (2.3.0)
245+
console (~> 1.0)
246+
mapping (~> 1.0)
177247
securerandom (0.3.1)
178248
stringio (3.1.1)
179-
thor (1.3.1)
249+
thor (1.3.2)
180250
timeout (0.4.1)
251+
traces (0.13.1)
181252
trilogy (2.8.1)
182253
tzinfo (2.0.6)
183254
concurrent-ruby (~> 1.0)
184-
tzinfo-data (1.2024.1)
255+
tzinfo-data (1.2024.2)
185256
tzinfo (>= 1.0.0)
186257
useragent (0.16.10)
187-
webrick (1.8.1)
258+
webrick (1.8.2)
188259
websocket-driver (0.7.6)
189260
websocket-extensions (>= 0.1.0)
190261
websocket-extensions (0.1.5)
191-
zeitwerk (2.6.17)
262+
zeitwerk (2.7.0)
192263

193264
PLATFORMS
194265
arm64-darwin-20
195266
ruby
196267
x86_64-linux
197268

198269
DEPENDENCIES
270+
falcon (~> 0.47)
199271
oj (~> 3.16)
200272
pg (~> 1.5)
201273
puma (~> 6.4)

frameworks/Ruby/rails/benchmark_config.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@
4444
"display_name": "rails-mysql",
4545
"notes": "",
4646
"versus": "rack-puma-mri"
47+
},
48+
"falcon": {
49+
"db_url": "/db",
50+
"json_url": "/json",
51+
"query_url": "/queries?queries=",
52+
"fortune_url": "/fortunes",
53+
"update_url": "/updates?queries=",
54+
"plaintext_url": "/plaintext",
55+
"port": 8080,
56+
"approach": "Realistic",
57+
"classification": "Fullstack",
58+
"database": "Postgres",
59+
"framework": "rails",
60+
"language": "Ruby",
61+
"orm": "Full",
62+
"platform": "Rack",
63+
"webserver": "Falcon",
64+
"os": "Linux",
65+
"database_os": "Linux",
66+
"display_name": "rails-falcon",
67+
"notes": "",
68+
"versus": "rack-falcon-mri"
4769
}
4870
}]
4971
}

frameworks/Ruby/rails/config/application.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ class Application < Rails::Application
5151
config.middleware.delete Rack::Sendfile
5252
config.middleware.delete Rack::TempfileReaper
5353
config.middleware.delete Rails::Rack::Logger
54+
55+
config.active_support.isolation_level = :fiber if defined?(Falcon)
5456
end
5557
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# required by Falcon:
2+
# https://github.com/socketry/falcon/blob/19fe8ece7cc49aa03222afe2c940682aeb69fe37/guides/rails-integration/readme.md?plain=1#L38
3+
require_relative "../config/environment"

frameworks/Ruby/rails/falcon.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env -S falcon host
2+
# frozen_string_literal: true
3+
4+
load :rack
5+
6+
hostname = File.basename(__dir__)
7+
port = ENV["PORT"] || 8080
8+
9+
rack hostname do
10+
append preload "config/falcon_preload.rb"
11+
endpoint Async::HTTP::Endpoint.parse("http://0.0.0.0:#{port}")
12+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ruby:3.4-rc
2+
3+
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends redis-server
4+
5+
EXPOSE 8080
6+
WORKDIR /rails
7+
8+
# ENV RUBY_YJIT_ENABLE=1 YJIT is enabled in config/initializers/enable_yjit.rb
9+
10+
# Use Jemalloc
11+
RUN apt-get update && \
12+
apt-get install -y --no-install-recommends libjemalloc2
13+
ENV LD_PRELOAD=libjemalloc.so.2
14+
15+
COPY ./Gemfile* /rails/
16+
17+
ENV BUNDLE_FORCE_RUBY_PLATFORM=true
18+
ENV BUNDLE_WITHOUT=mysql
19+
RUN bundle install --jobs=8
20+
21+
COPY . /rails/
22+
23+
ENV RAILS_ENV=production_postgresql
24+
ENV PORT=8080
25+
ENV REDIS_URL=redis://localhost:6379/0
26+
CMD bundle exec falcon host

frameworks/Ruby/rails/rails.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ENV LD_PRELOAD=libjemalloc.so.2
1515
COPY ./Gemfile* /rails/
1616

1717
ENV BUNDLE_FORCE_RUBY_PLATFORM=true
18-
ENV BUNDLE_WITHOUT=trilogy
18+
ENV BUNDLE_WITHOUT=mysql
1919
RUN bundle install --jobs=8
2020

2121
COPY . /rails/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22
service redis-server start
3-
rails server
3+
bundle exec falcon host

0 commit comments

Comments
 (0)