Skip to content

Commit 6837c80

Browse files
authored
[Ruby] Add rage-rb (#8908)
1 parent 20381d4 commit 6837c80

File tree

18 files changed

+267
-0
lines changed

18 files changed

+267
-0
lines changed

frameworks/Ruby/rage/Gemfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
source "https://rubygems.org"
2+
3+
gem "rage-rb", "~> 1.3"
4+
5+
gem "pg", "~> 1.0"
6+
gem "activerecord", "~> 7.0.0", require: "active_record"
7+
8+
# Build JSON APIs with ease
9+
# gem "alba"
10+
11+
# Get 50% to 150% boost when parsing JSON.
12+
# Rage will automatically use FastJsonparser if it is available.
13+
# gem "fast_jsonparser"

frameworks/Ruby/rage/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+
* [ActiveRecord](https://rubygems.org/gems/activerecord)
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/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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.find(random_id)
21+
end
22+
23+
def queries
24+
records = requested_ids.map do |id|
25+
World.find(id)
26+
end
27+
28+
render json: records
29+
end
30+
31+
def fortunes
32+
records = Fortune.pluck(:id, :message).map! { |id, message| { id:, message: } }
33+
34+
records << Fortune.new(id: 0, message: "Additional fortune added at request time.")
35+
records.sort_by! { |record| record[:message] }
36+
37+
render plain: FORTUNES_TEMPLATE.result(binding)
38+
headers["content-type"] = "text/html; charset=utf-8"
39+
end
40+
41+
def updates
42+
records = requested_ids.map do |id|
43+
World.find(id)
44+
end
45+
46+
updates = records.map do |record|
47+
new_value = random_id
48+
new_value = random_id until new_value != record.randomNumber
49+
50+
record.randomNumber = new_value
51+
52+
{ id: record.id, randomnumber: new_value }
53+
end
54+
55+
World.upsert_all(updates.sort_by! { |u| u[:id] })
56+
57+
render json: records
58+
end
59+
60+
private
61+
62+
def requested_ids
63+
num = params[:queries].to_i
64+
65+
if num > 500
66+
num = 500
67+
elsif num < 1
68+
num = 1
69+
end
70+
71+
ALL_DB_IDS.sample(num)
72+
end
73+
74+
def random_id
75+
Random.rand(9_999) + 1
76+
end
77+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
primary_abstract_class
3+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Fortune < ApplicationRecord
2+
self.table_name = "Fortune"
3+
4+
def as_json(*)
5+
attributes
6+
end
7+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class World < ApplicationRecord
2+
self.table_name = "World"
3+
4+
def as_json(*)
5+
attributes
6+
end
7+
8+
alias_attribute(:randomNumber, :randomnumber)
9+
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",
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",
25+
"notes": "",
26+
"versus": "None"
27+
}
28+
}
29+
]
30+
}

0 commit comments

Comments
 (0)