Skip to content
Merged
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
7 changes: 7 additions & 0 deletions frameworks/Ruby/rage-sequel/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "https://rubygems.org"

gem "rage-rb", "~> 1.10"

gem "pg", "~> 1.0"
gem 'sequel', '~> 5.0'
gem 'sequel_pg', '~> 1.6', platforms: :ruby, require: false
37 changes: 37 additions & 0 deletions frameworks/Ruby/rage-sequel/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
GEM
remote: https://rubygems.org/
specs:
bigdecimal (3.1.9)
pg (1.5.9)
rack (2.2.10)
rack-test (2.2.0)
rack (>= 1.3)
rage-iodine (4.0.0)
rage-rb (1.11.0)
rack (~> 2.0)
rack-test (~> 2.1)
rage-iodine (~> 4.0)
rake (>= 12.0)
thor (~> 1.0)
zeitwerk (~> 2.6)
rake (13.2.1)
sequel (5.88.0)
bigdecimal
sequel_pg (1.17.1)
pg (>= 0.18.0, != 1.2.0)
sequel (>= 4.38.0)
thor (1.3.2)
zeitwerk (2.7.1)

PLATFORMS
ruby
x86_64-darwin-20

DEPENDENCIES
pg (~> 1.0)
rage-rb (~> 1.10)
sequel (~> 5.0)
sequel_pg (~> 1.6)

BUNDLED WITH
2.5.6
47 changes: 47 additions & 0 deletions frameworks/Ruby/rage-sequel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Rage Benchmarking Test

Rage is a fast web framework compatible with Rails. It uses an event-driven architecture and implements a lightweight, cooperative concurrency model based on Ruby Fibers.

https://github.com/rage-rb/rage

### Test Type Implementation Source Code

* [JSON](app/controllers/benchmarks_controller.rb)
* [PLAINTEXT](app/controllers/benchmarks_controller.rb)
* [DB](app/controllers/benchmarks_controller.rb)
* [QUERY](app/controllers/benchmarks_controller.rb)
* [UPDATE](app/controllers/benchmarks_controller.rb)
* [FORTUNES](app/controllers/benchmarks_controller.rb)

## Important Libraries

The tests were run with:

* [Sequel](https://rubygems.org/gems/sequel)
* [PG](https://rubygems.org/gems/pg)

## Test URLs

### JSON

http://localhost:8080/json

### PLAINTEXT

http://localhost:8080/plaintext

### DB

http://localhost:8080/db

### QUERY

http://localhost:8080/queries?queries=

### UPDATE

http://localhost:8080/updates?queries=

### FORTUNES

http://localhost:8080/fortunes
1 change: 1 addition & 0 deletions frameworks/Ruby/rage-sequel/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative "config/application"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < RageController::API
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

class BenchmarksController < ApplicationController
ALL_DB_IDS = (1..10_000).to_a
FORTUNES_TEMPLATE = ERB.new(Rage.root.join("app/views/fortunes.html.erb").read)

before_action do
headers["server"] = "rage"
end

def db
render json: World.with_pk(random_id).values
end

def queries
worlds = DB.synchronize do
requested_ids.map do |id|
World.with_pk(id)
end
end

render json: worlds.map!(&:values)
end

def fortunes
records = Fortune.all

records << Fortune.new(id: 0, message: "Additional fortune added at request time.")
records.sort_by!(&:message)

render plain: FORTUNES_TEMPLATE.result(binding)
headers["content-type"] = "text/html; charset=utf-8"
end

def updates
worlds = nil

DB.synchronize do
worlds = requested_ids.map do |id|
world = World.with_pk(id)
new_value = random_id
new_value = random_id while new_value == world.randomnumber
world.randomnumber = new_value

world
end

World.batch_update(worlds)
end

render json: worlds.map!(&:values)
end

private

def requested_ids
num = params[:queries].to_i

if num > 500
num = 500
elsif num < 1
num = 1
end

ALL_DB_IDS.sample(num)
end

def random_id
Random.rand(9_999) + 1
end
end
12 changes: 12 additions & 0 deletions frameworks/Ruby/rage-sequel/app/views/fortunes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head><title>Fortunes</title></head>
<body>
<table>
<tr><th>id</th><th>message</th></tr>
<% records.each do |record| %>
<tr><td><%= record.id %></td><td><%= CGI.escape_html(record.message) %></td></tr>
<% end %>
</table>
</body>
</html>
28 changes: 28 additions & 0 deletions frameworks/Ruby/rage-sequel/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"framework": "rage-sequel",
"tests": [
{
"default": {
"db_url": "/db",
"query_url": "/queries?queries=",
"fortune_url": "/fortunes",
"update_url": "/updates?queries=",
"port": 8080,
"approach": "Realistic",
"classification": "Micro",
"database": "postgres",
"framework": "Rage",
"language": "Ruby",
"flavor": "None",
"orm": "Full",
"platform": "Rack",
"webserver": "Rage-Iodine",
"os": "Linux",
"database_os": "Linux",
"display_name": "Rage-Sequel",
"notes": "",
"versus": "None"
}
}
]
}
3 changes: 3 additions & 0 deletions frameworks/Ruby/rage-sequel/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative "config/application"

run Rage.application
14 changes: 14 additions & 0 deletions frameworks/Ruby/rage-sequel/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "bundler/setup"
require "rage"
Bundler.require(*Rage.groups)

require "rage/all"

Rage.configure do
# use this to add settings that are constant across all environments
end

require "erb"
require "cgi"

require "rage/setup"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rage.configure do
config.server.workers_count = -1
config.logger = Rage::Logger.new(STDOUT)
end
3 changes: 3 additions & 0 deletions frameworks/Ruby/rage-sequel/config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rage.configure do
config.logger = nil
end
41 changes: 41 additions & 0 deletions frameworks/Ruby/rage-sequel/config/initializers/sequel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

SEQUEL_NO_ASSOCIATIONS = true
Sequel.extension :fiber_concurrency

# Determine thread pool size and timeout
opts = {
max_connections: 512,
pool_timeout: 10
}

DB = Sequel.connect \
'%{adapter}://%{host}/%{database}?user=%{user}&password=%{password}' % {
:adapter=>'postgres',
:host=>'tfb-database',
:database=>'hello_world',
:user=>'benchmarkdbuser',
:password=>'benchmarkdbpass'
}, opts

# Define ORM models
class World < Sequel::Model(:World)
def self.batch_update(worlds)
ids = []
sql = String.new("UPDATE world SET randomnumber = CASE id ")
worlds.each do |world|
sql << "when #{world.id} then #{world.randomnumber} "
ids << world.id
end
sql << "ELSE randomnumber END WHERE id IN ( #{ids.join(',')})"
DB.run(sql)
end
end

class Fortune < Sequel::Model(:Fortune)
# Allow setting id to zero (0) per benchmark requirements
unrestrict_primary_key
end

[World, Fortune].each(&:freeze)
DB.freeze
8 changes: 8 additions & 0 deletions frameworks/Ruby/rage-sequel/config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Rage.routes.draw do
root to: ->(env) { [200, {}, "It works!"] }

get "db", to: "benchmarks#db"
get "queries", to: "benchmarks#queries"
get "fortunes", to: "benchmarks#fortunes"
get "updates", to: "benchmarks#updates"
end
Empty file.
13 changes: 13 additions & 0 deletions frameworks/Ruby/rage-sequel/rage-sequel.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ruby:3.4

EXPOSE 8080
WORKDIR /rage-sequel

COPY Gemfile* /rage-sequel/
RUN bundle install --jobs=8
COPY . /rage-sequel

ENV RUBY_YJIT_ENABLE=1
ENV BUNDLE_FORCE_RUBY_PLATFORM=true

CMD bundle exec rage s -b 0.0.0.0 -p 8080 -e production
Loading