Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frameworks/roda/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ENV RUBY_MN_THREADS=1
ENV RACK_ENV=production
ENV WEB_CONCURRENCY=auto
ENV MAX_THREADS=4
ENV MAX_IO_THREADS=10
ENV MAX_IO_THREADS=4

WORKDIR /app

Expand Down
18 changes: 9 additions & 9 deletions frameworks/roda/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ class App < Roda
end

r.is('baseline11') do
total = request.params['a'].to_i + request.params['b'].to_i
total = request.GET['a'].to_i + request.GET['b'].to_i
if request.post?
total += request.body.read.to_i
end
render_plain total.to_s
end

r.is 'baseline2' do
total = request.params['a'].to_i + request.params['b'].to_i
total = request.GET['a'].to_i + request.GET['b'].to_i
render_plain total.to_s
end

r.is 'json', Integer do |count|
dataset = opts[:dataset_items]
r.halt 500, 'No dataset' unless dataset
m = (request.params['m'] || 1).to_i
m = (request.GET['m'] || 1).to_i
items = dataset.slice(0, count).map do |d|
d.merge(total: (d[:price] * d[:quantity] * m))
end
Expand All @@ -84,9 +84,9 @@ class App < Roda
end

r.is 'async-db' do
min_val = (request.params['min'] || 10).to_i
max_val = (request.params['max'] || 50).to_i
limit = (request.params['limit'] || 50).to_i.clamp(1, 50)
min_val = (request.GET['min'] || 10).to_i
max_val = (request.GET['max'] || 50).to_i
limit = (request.GET['limit'] || 50).to_i.clamp(1, 50)

rows = self.class.get_async_db&.with do |connection|
connection.exec_prepared('select', [min_val, max_val, limit])
Expand All @@ -100,9 +100,9 @@ class App < Roda

r.is 'crud/items' do
r.get do
category = request.params['category'] || 'electronics'
page = (request.params['page'] || 1).to_i
limit = (request.params['limit'] || 10).to_i
category = request.GET['category'] || 'electronics'
page = (request.GET['page'] || 1).to_i
limit = (request.GET['limit'] || 10).to_i
offset = (page - 1) * limit

rows = self.class.get_async_db&.with do |connection|
Expand Down
17 changes: 0 additions & 17 deletions frameworks/roda/config.ru
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
require_relative 'app'

# Threads marked as IO bound are allowed to go over Puma's max thread limit.
class MarkAsIOBoundThreads
IOBoundPaths = %w[/baseline11 /baseline2 /async-db].map { [_1, nil] }.to_h.freeze

def initialize(app)
@app = app
end

def call(env)
if IOBoundPaths.has_key? env['PATH_INFO']
env["puma.mark_as_io_bound"].call
end
@app.call(env)
end
end

use MarkAsIOBoundThreads
use Rack::Deflater # enable gzip
run App
Loading