forked from TechEmpower/FrameworkBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "rage-rb", "~> 1.3" | ||
|
||
gem "pg", "~> 1.0" | ||
gem "activerecord", "~> 7.0.0", require: "active_record" | ||
|
||
# Build JSON APIs with ease | ||
# gem "alba" | ||
|
||
# Get 50% to 150% boost when parsing JSON. | ||
# Rage will automatically use FastJsonparser if it is available. | ||
# gem "fast_jsonparser" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Rage Benchmarking Test | ||
|
||
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: | ||
|
||
* [ActiveRecord](https://rubygems.org/gems/activerecord) | ||
* [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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require_relative "config/application" |
2 changes: 2 additions & 0 deletions
2
frameworks/Ruby/rage/app/controllers/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ApplicationController < RageController::API | ||
end |
77 changes: 77 additions & 0 deletions
77
frameworks/Ruby/rage/app/controllers/benchmarks_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 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 json | ||
render json: { message: "Hello, World!" } | ||
end | ||
|
||
def plaintext | ||
render plain: "Hello, World!" | ||
end | ||
|
||
def db | ||
render json: World.find(random_id) | ||
end | ||
|
||
def queries | ||
records = requested_ids.map do |id| | ||
World.find(id) | ||
end | ||
|
||
render json: records | ||
end | ||
|
||
def fortunes | ||
records = Fortune.pluck(:id, :message).map! { |id, message| { id:, message: } } | ||
|
||
records << Fortune.new(id: 0, message: "Additional fortune added at request time.") | ||
records.sort_by! { |record| record[:message] } | ||
|
||
render plain: FORTUNES_TEMPLATE.result(binding) | ||
headers["content-type"] = "text/html; charset=utf-8" | ||
end | ||
|
||
def updates | ||
records = requested_ids.map do |id| | ||
World.find(id) | ||
end | ||
|
||
updates = records.map do |record| | ||
new_value = random_id | ||
new_value = random_id until new_value != record.randomNumber | ||
|
||
record.randomNumber = new_value | ||
|
||
{ id: record.id, randomnumber: new_value } | ||
end | ||
|
||
World.upsert_all(updates.sort_by! { |u| u[:id] }) | ||
|
||
render json: records | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
primary_abstract_class | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Fortune < ApplicationRecord | ||
self.table_name = "Fortune" | ||
|
||
def as_json(*) | ||
attributes | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class World < ApplicationRecord | ||
self.table_name = "World" | ||
|
||
def as_json(*) | ||
attributes | ||
end | ||
|
||
alias_attribute(:randomNumber, :randomnumber) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"framework": "rage", | ||
"tests": [ | ||
{ | ||
"default": { | ||
"json_url": "/json", | ||
"plaintext_url": "/plaintext", | ||
"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", | ||
"notes": "", | ||
"versus": "None" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require_relative "config/application" | ||
|
||
run Rage.application | ||
Rage.load_middlewares(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Rage.configure do | ||
config.server.workers_count = -1 | ||
config.logger = ActiveRecord::Base.logger = Rage::Logger.new(STDOUT) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Rage.configure do | ||
config.logger = nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require "etc" | ||
|
||
connection = { | ||
adapter: "postgresql", | ||
host: "tfb-database", | ||
username: "benchmarkdbuser", | ||
password: "benchmarkdbpass", | ||
database: "hello_world", | ||
reaping_frequency: 0, | ||
pool: (2 * Math.log(256 / Etc.nprocessors)).floor | ||
} | ||
|
||
puts "ActiveRecord connection options: #{connection.inspect}" | ||
|
||
ActiveRecord::Base.establish_connection(connection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Rage.routes.draw do | ||
root to: ->(env) { [200, {}, "It works!"] } | ||
|
||
get "json", to: "benchmarks#json" | ||
get "plaintext", to: "benchmarks#plaintext" | ||
get "db", to: "benchmarks#db" | ||
get "queries", to: "benchmarks#queries" | ||
get "fortunes", to: "benchmarks#fortunes" | ||
get "updates", to: "benchmarks#updates" | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM ruby:3.3 | ||
|
||
EXPOSE 8080 | ||
WORKDIR /rage | ||
|
||
COPY Gemfile* /rage/ | ||
RUN bundle install --jobs=8 | ||
COPY . /rage | ||
|
||
ENV RUBY_YJIT_ENABLE=1 | ||
ENV RAGE_PATCH_AR_POOL=1 | ||
ENV BUNDLE_FORCE_RUBY_PLATFORM=true | ||
|
||
CMD bundle exec rage s -b 0.0.0.0 -p 8080 -e production |