Skip to content

Commit fb6834a

Browse files
committed
Add rage-sequel
1 parent 0a9ab06 commit fb6834a

File tree

16 files changed

+305
-0
lines changed

16 files changed

+305
-0
lines changed

frameworks/Ruby/rage-sequel/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source "https://rubygems.org"
2+
3+
gem "rage-rb", "~> 1.10"
4+
5+
gem "pg", "~> 1.0"
6+
gem 'sequel', '~> 5.0'
7+
gem 'sequel_pg', '~> 1.6', platforms: :ruby, require: false
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
bigdecimal (3.1.9)
5+
pg (1.5.9)
6+
rack (2.2.10)
7+
rack-test (2.2.0)
8+
rack (>= 1.3)
9+
rage-iodine (4.0.0)
10+
rage-rb (1.11.0)
11+
rack (~> 2.0)
12+
rack-test (~> 2.1)
13+
rage-iodine (~> 4.0)
14+
rake (>= 12.0)
15+
thor (~> 1.0)
16+
zeitwerk (~> 2.6)
17+
rake (13.2.1)
18+
sequel (5.88.0)
19+
bigdecimal
20+
sequel_pg (1.17.1)
21+
pg (>= 0.18.0, != 1.2.0)
22+
sequel (>= 4.38.0)
23+
thor (1.3.2)
24+
zeitwerk (2.7.1)
25+
26+
PLATFORMS
27+
ruby
28+
x86_64-darwin-20
29+
30+
DEPENDENCIES
31+
pg (~> 1.0)
32+
rage-rb (~> 1.10)
33+
sequel (~> 5.0)
34+
sequel_pg (~> 1.6)
35+
36+
BUNDLED WITH
37+
2.5.6

frameworks/Ruby/rage-sequel/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Rage Benchmarking Test
2+
3+
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.
4+
5+
https://github.com/rage-rb/rage
6+
7+
### Test Type Implementation Source Code
8+
9+
* [JSON](app/controllers/benchmarks_controller.rb)
10+
* [PLAINTEXT](app/controllers/benchmarks_controller.rb)
11+
* [DB](app/controllers/benchmarks_controller.rb)
12+
* [QUERY](app/controllers/benchmarks_controller.rb)
13+
* [UPDATE](app/controllers/benchmarks_controller.rb)
14+
* [FORTUNES](app/controllers/benchmarks_controller.rb)
15+
16+
## Important Libraries
17+
18+
The tests were run with:
19+
20+
* [Sequel](https://rubygems.org/gems/sequel)
21+
* [PG](https://rubygems.org/gems/pg)
22+
23+
## Test URLs
24+
25+
### JSON
26+
27+
http://localhost:8080/json
28+
29+
### PLAINTEXT
30+
31+
http://localhost:8080/plaintext
32+
33+
### DB
34+
35+
http://localhost:8080/db
36+
37+
### QUERY
38+
39+
http://localhost:8080/queries?queries=
40+
41+
### UPDATE
42+
43+
http://localhost:8080/updates?queries=
44+
45+
### FORTUNES
46+
47+
http://localhost:8080/fortunes

frameworks/Ruby/rage-sequel/Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require_relative "config/application"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ApplicationController < RageController::API
2+
end
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# frozen_string_literal: true
2+
3+
class BenchmarksController < ApplicationController
4+
ALL_DB_IDS = (1..10_000).to_a
5+
FORTUNES_TEMPLATE = ERB.new(Rage.root.join("app/views/fortunes.html.erb").read)
6+
7+
before_action do
8+
headers["server"] = "rage"
9+
end
10+
11+
def json
12+
render json: { message: "Hello, World!" }
13+
end
14+
15+
def plaintext
16+
render plain: "Hello, World!"
17+
end
18+
19+
def db
20+
render json: World.with_pk(random_id).values
21+
end
22+
23+
def queries
24+
worlds = DB.synchronize do
25+
requested_ids.map do |id|
26+
World.with_pk(id)
27+
end
28+
end
29+
30+
render json: worlds.map!(&:values)
31+
end
32+
33+
def fortunes
34+
records = Fortune.all
35+
36+
records << Fortune.new(id: 0, message: "Additional fortune added at request time.")
37+
records.sort_by!(&:message)
38+
39+
render plain: FORTUNES_TEMPLATE.result(binding)
40+
headers["content-type"] = "text/html; charset=utf-8"
41+
end
42+
43+
def updates
44+
worlds = nil
45+
46+
DB.synchronize do
47+
worlds = requested_ids.map do |id|
48+
world = World.with_pk(id)
49+
new_value = random_id
50+
new_value = random_id while new_value == world.randomnumber
51+
world.randomnumber = new_value
52+
53+
world
54+
end
55+
56+
World.batch_update(worlds)
57+
end
58+
59+
render json: worlds.map!(&:values)
60+
end
61+
62+
private
63+
64+
def requested_ids
65+
num = params[:queries].to_i
66+
67+
if num > 500
68+
num = 500
69+
elsif num < 1
70+
num = 1
71+
end
72+
73+
ALL_DB_IDS.sample(num)
74+
end
75+
76+
def random_id
77+
Random.rand(9_999) + 1
78+
end
79+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head><title>Fortunes</title></head>
4+
<body>
5+
<table>
6+
<tr><th>id</th><th>message</th></tr>
7+
<% records.each do |record| %>
8+
<tr><td><%= record.id %></td><td><%= CGI.escape_html(record.message) %></td></tr>
9+
<% end %>
10+
</table>
11+
</body>
12+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"framework": "rage-sequel",
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/json",
7+
"plaintext_url": "/plaintext",
8+
"db_url": "/db",
9+
"query_url": "/queries?queries=",
10+
"fortune_url": "/fortunes",
11+
"update_url": "/updates?queries=",
12+
"port": 8080,
13+
"approach": "Realistic",
14+
"classification": "Micro",
15+
"database": "postgres",
16+
"framework": "Rage",
17+
"language": "Ruby",
18+
"flavor": "None",
19+
"orm": "Full",
20+
"platform": "Rack",
21+
"webserver": "Rage-Iodine",
22+
"os": "Linux",
23+
"database_os": "Linux",
24+
"display_name": "Rage-Sequel",
25+
"notes": "",
26+
"versus": "None"
27+
}
28+
}
29+
]
30+
}

frameworks/Ruby/rage-sequel/config.ru

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require_relative "config/application"
2+
3+
run Rage.application
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "bundler/setup"
2+
require "rage"
3+
Bundler.require(*Rage.groups)
4+
5+
require "rage/all"
6+
7+
Rage.configure do
8+
# use this to add settings that are constant across all environments
9+
end
10+
11+
require "erb"
12+
require "cgi"
13+
14+
require "rage/setup"

0 commit comments

Comments
 (0)