Skip to content

Commit 76a58d8

Browse files
authored
Merge branch 'TechEmpower:master' into master
2 parents 25f0f39 + f22bbb6 commit 76a58d8

19 files changed

+294
-2
lines changed

frameworks/PHP/reactphp/benchmark_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"framework": "reactphp",
3+
"maintainers": ["WyriHaximus"],
34
"tests": [{
45
"default": {
56
"json_url": "/json",

frameworks/Ruby/rack/rack-iodine.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ COPY . .
1919

2020
EXPOSE 8080
2121

22-
CMD bundle exec iodine -p 8080
22+
CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1)

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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 db
12+
render json: World.with_pk(random_id).values
13+
end
14+
15+
def queries
16+
worlds = DB.synchronize do
17+
requested_ids.map do |id|
18+
World.with_pk(id)
19+
end
20+
end
21+
22+
render json: worlds.map!(&:values)
23+
end
24+
25+
def fortunes
26+
records = Fortune.all
27+
28+
records << Fortune.new(id: 0, message: "Additional fortune added at request time.")
29+
records.sort_by!(&:message)
30+
31+
render plain: FORTUNES_TEMPLATE.result(binding)
32+
headers["content-type"] = "text/html; charset=utf-8"
33+
end
34+
35+
def updates
36+
worlds = nil
37+
38+
DB.synchronize do
39+
worlds = requested_ids.map do |id|
40+
world = World.with_pk(id)
41+
new_value = random_id
42+
new_value = random_id while new_value == world.randomnumber
43+
world.randomnumber = new_value
44+
45+
world
46+
end
47+
48+
World.batch_update(worlds)
49+
end
50+
51+
render json: worlds.map!(&:values)
52+
end
53+
54+
private
55+
56+
def requested_ids
57+
num = params[:queries].to_i
58+
59+
if num > 500
60+
num = 500
61+
elsif num < 1
62+
num = 1
63+
end
64+
65+
ALL_DB_IDS.sample(num)
66+
end
67+
68+
def random_id
69+
Random.rand(9_999) + 1
70+
end
71+
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"framework": "rage-sequel",
3+
"tests": [
4+
{
5+
"default": {
6+
"db_url": "/db",
7+
"query_url": "/queries?queries=",
8+
"fortune_url": "/fortunes",
9+
"update_url": "/updates?queries=",
10+
"port": 8080,
11+
"approach": "Realistic",
12+
"classification": "Micro",
13+
"database": "postgres",
14+
"framework": "Rage",
15+
"language": "Ruby",
16+
"flavor": "None",
17+
"orm": "Full",
18+
"platform": "Rack",
19+
"webserver": "Rage-Iodine",
20+
"os": "Linux",
21+
"database_os": "Linux",
22+
"display_name": "Rage-Sequel",
23+
"notes": "",
24+
"versus": "None"
25+
}
26+
}
27+
]
28+
}

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"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Rage.configure do
2+
config.server.workers_count = -1
3+
config.logger = Rage::Logger.new(STDOUT)
4+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Rage.configure do
2+
config.logger = nil
3+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
SEQUEL_NO_ASSOCIATIONS = true
4+
Sequel.extension :fiber_concurrency
5+
6+
# Determine thread pool size and timeout
7+
opts = {
8+
max_connections: 512,
9+
pool_timeout: 10
10+
}
11+
12+
DB = Sequel.connect \
13+
'%{adapter}://%{host}/%{database}?user=%{user}&password=%{password}' % {
14+
:adapter=>'postgres',
15+
:host=>'tfb-database',
16+
:database=>'hello_world',
17+
:user=>'benchmarkdbuser',
18+
:password=>'benchmarkdbpass'
19+
}, opts
20+
21+
# Define ORM models
22+
class World < Sequel::Model(:World)
23+
def self.batch_update(worlds)
24+
ids = []
25+
sql = String.new("UPDATE world SET randomnumber = CASE id ")
26+
worlds.each do |world|
27+
sql << "when #{world.id} then #{world.randomnumber} "
28+
ids << world.id
29+
end
30+
sql << "ELSE randomnumber END WHERE id IN ( #{ids.join(',')})"
31+
DB.run(sql)
32+
end
33+
end
34+
35+
class Fortune < Sequel::Model(:Fortune)
36+
# Allow setting id to zero (0) per benchmark requirements
37+
unrestrict_primary_key
38+
end
39+
40+
[World, Fortune].each(&:freeze)
41+
DB.freeze
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Rage.routes.draw do
2+
root to: ->(env) { [200, {}, "It works!"] }
3+
4+
get "db", to: "benchmarks#db"
5+
get "queries", to: "benchmarks#queries"
6+
get "fortunes", to: "benchmarks#fortunes"
7+
get "updates", to: "benchmarks#updates"
8+
end

frameworks/Ruby/rage-sequel/lib/.keep

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ruby:3.4
2+
3+
EXPOSE 8080
4+
WORKDIR /rage-sequel
5+
6+
COPY Gemfile* /rage-sequel/
7+
RUN bundle install --jobs=8
8+
COPY . /rage-sequel
9+
10+
ENV RUBY_YJIT_ENABLE=1
11+
ENV BUNDLE_FORCE_RUBY_PLATFORM=true
12+
13+
CMD bundle exec rage s -b 0.0.0.0 -p 8080 -e production

frameworks/Ruby/roda-sequel/roda-sequel-postgres-iodine-mri.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ ENV DBTYPE=postgresql
1818

1919
EXPOSE 8080
2020

21-
CMD bundle exec iodine -p 8080
21+
CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1)

0 commit comments

Comments
 (0)