Skip to content

Commit eb4eac9

Browse files
committed
[roda] Mark upload as io bound
Use Puma 8's new 'mark_as_io_bound' option allow more threads on the IO heavy upload call. It seems only the baseline call benefits from this. Before ------ | Test | Conn | RPS | CPU | Mem | Δ RPS | Δ Mem | |------|------|-----|-----|-----|-------|-------| | baseline | 512 | 75,252 | 4506.6% | 7.1GiB | +0.1% | ~0% | | baseline | 4096 | 37,996 | 3896.3% | 5.4GiB | +1.4% | -10.0% | | pipelined | 512 | 583,729 | 6455.6% | 1.7GiB | -12.0% | -10.5% | | pipelined | 4096 | 562,005 | 6432.4% | 2.1GiB | -14.3% | ~0% | | limited-conn | 512 | 28,537 | 3693.9% | 4.9GiB | -5.8% | -7.5% | | limited-conn | 4096 | 28,977 | 3489.3% | 5.1GiB | -1.0% | -3.8% | | json | 4096 | 231,255 | 6362.4% | 4.3GiB | -9.0% | -21.8% | | json-comp | 512 | 128,684 | 6473.1% | 4.0GiB | -2.9% | -2.4% | | json-comp | 4096 | 131,000 | 6500.5% | 3.6GiB | -2.2% | -10.0% | | json-comp | 16384 | 130,762 | 6515.4% | 4.1GiB | -1.8% | +5.1% | | json-tls | 4096 | 205,209 | 6514.8% | 5.1GiB | -8.0% | -1.9% | | upload | 32 | 965 | 3102.4% | 8.3GiB | -0.4% | -3.5% | | upload | 256 | 895 | 6517.6% | 6.9GiB | +3.9% | -19.8% | | api-4 | 256 | 18,551 | 396.5% | 489MiB | -1.3% | +28.3% | | api-16 | 1024 | 46,029 | 1676.7% | 1.5GiB | -5.7% | +7.1% | | static | 1024 | 142,223 | 6539.9% | 6.3GiB | -43.4% | -13.7% | | static | 4096 | 140,111 | 6528.3% | 6.7GiB | -42.4% | -14.1% | | static | 6800 | 138,172 | 6484.5% | 7.1GiB | -42.7% | -4.1% | | async-db | 1024 | 108,099 | 6396.5% | 2.5GiB | -8.6% | -7.4% | After when enabled for all tests -------------------------------- | Test | Conn | RPS | CPU | Mem | Δ RPS | Δ Mem | |------|------|-----|-----|-----|-------|-------| | baseline | 512 | 103,762 | 4938.2% | 10.2GiB | +38.0% | +43.7% | | baseline | 4096 | 57,379 | 4092.2% | 8.9GiB | +53.1% | +48.3% | | pipelined | 512 | 565,924 | 6517.1% | 1.7GiB | -14.6% | -10.5% | | pipelined | 4096 | 548,129 | 6413.7% | 2.0GiB | -16.4% | -4.8% | | limited-conn | 512 | 28,662 | 3767.3% | 5.6GiB | -5.3% | +5.7% | | limited-conn | 4096 | 28,806 | 3548.4% | 6.5GiB | -1.6% | +22.6% | | json | 4096 | 230,980 | 6328.1% | 4.7GiB | -9.2% | -14.5% | | json-comp | 512 | 123,348 | 6447.6% | 3.5GiB | -6.9% | -14.6% | | json-comp | 4096 | 131,084 | 6508.4% | 3.7GiB | -2.2% | -7.5% | | json-comp | 16384 | 129,825 | 6280.0% | 4.3GiB | -2.5% | +10.3% | | json-tls | 4096 | 201,924 | 6498.8% | 5.0GiB | -9.5% | -3.8% | | upload | 32 | 961 | 3150.3% | 7.8GiB | -0.8% | -9.3% | | upload | 256 | 900 | 6532.3% | 6.8GiB | +4.5% | -20.9% | | api-4 | 256 | 18,413 | 395.8% | 496MiB | -2.0% | +30.2% | | api-16 | 1024 | 45,106 | 1639.4% | 1.2GiB | -7.6% | -14.3% | | static | 1024 | 140,836 | 6526.6% | 6.0GiB | -44.0% | -17.8% | | static | 4096 | 136,155 | 6530.6% | 6.4GiB | -44.0% | -17.9% | | static | 6800 | 137,830 | 6546.6% | 6.4GiB | -42.8% | -13.5% | | async-db | 1024 | 109,209 | 6375.1% | 2.6GiB | -7.6% | -3.7% |
1 parent 78d93bd commit eb4eac9

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

frameworks/roda/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ENV RUBY_MN_THREADS=1
1212
ENV RACK_ENV=production
1313
ENV WEB_CONCURRENCY=auto
1414
ENV MAX_THREADS=4
15+
ENV MAX_IO_THREADS=10
1516

1617
WORKDIR /app
1718

frameworks/roda/app.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class App < Roda
6969
end
7070

7171
r.is 'upload' do
72+
request.env["puma.mark_as_io_bound"].call
7273
size = 0
7374
buf = request.body
7475
while (chunk = buf.read(65536))

frameworks/roda/config.ru

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ class MethodGuard
1717
end
1818
end
1919

20+
# Threads marked as IO bound are allowed to go over Puma's max thread limit.
21+
class MarkAsIOBoundThreads
22+
def initialize(app)
23+
@app = app
24+
end
25+
26+
def call(env)
27+
if env['PATH_INFO'] == '/baseline'
28+
env["puma.mark_as_io_bound"].call
29+
end
30+
@app.call(env)
31+
end
32+
end
33+
34+
use MarkAsIOBoundThreads
2035
use MethodGuard
2136
use Rack::Deflater # enable gzip
2237
run App

frameworks/roda/puma.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
threads ENV.fetch('MAX_THREADS', 4).to_i
2+
max_io_threads ENV.fetch("MAX_IO_THREADS", 10).to_i
23

34
tls_cert_path = ENV.fetch('TLS_CERT', '/certs/server.crt')
45
tls_key_path = ENV.fetch('TLS_KEY', '/certs/server.key')

0 commit comments

Comments
 (0)