From fb6834a55b92ed740d54051e47317cc741e830b2 Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Wed, 15 Jan 2025 19:54:17 +0000 Subject: [PATCH] Add rage-sequel --- frameworks/Ruby/rage-sequel/Gemfile | 7 ++ frameworks/Ruby/rage-sequel/Gemfile.lock | 37 +++++++++ frameworks/Ruby/rage-sequel/README.md | 47 +++++++++++ frameworks/Ruby/rage-sequel/Rakefile | 1 + .../app/controllers/application_controller.rb | 2 + .../app/controllers/benchmarks_controller.rb | 79 +++++++++++++++++++ .../rage-sequel/app/views/fortunes.html.erb | 12 +++ .../Ruby/rage-sequel/benchmark_config.json | 30 +++++++ frameworks/Ruby/rage-sequel/config.ru | 3 + .../Ruby/rage-sequel/config/application.rb | 14 ++++ .../config/environments/development.rb | 4 + .../config/environments/production.rb | 3 + .../rage-sequel/config/initializers/sequel.rb | 43 ++++++++++ frameworks/Ruby/rage-sequel/config/routes.rb | 10 +++ frameworks/Ruby/rage-sequel/lib/.keep | 0 .../Ruby/rage-sequel/rage-sequel.dockerfile | 13 +++ 16 files changed, 305 insertions(+) create mode 100644 frameworks/Ruby/rage-sequel/Gemfile create mode 100644 frameworks/Ruby/rage-sequel/Gemfile.lock create mode 100755 frameworks/Ruby/rage-sequel/README.md create mode 100644 frameworks/Ruby/rage-sequel/Rakefile create mode 100644 frameworks/Ruby/rage-sequel/app/controllers/application_controller.rb create mode 100644 frameworks/Ruby/rage-sequel/app/controllers/benchmarks_controller.rb create mode 100644 frameworks/Ruby/rage-sequel/app/views/fortunes.html.erb create mode 100755 frameworks/Ruby/rage-sequel/benchmark_config.json create mode 100644 frameworks/Ruby/rage-sequel/config.ru create mode 100644 frameworks/Ruby/rage-sequel/config/application.rb create mode 100644 frameworks/Ruby/rage-sequel/config/environments/development.rb create mode 100644 frameworks/Ruby/rage-sequel/config/environments/production.rb create mode 100644 frameworks/Ruby/rage-sequel/config/initializers/sequel.rb create mode 100644 frameworks/Ruby/rage-sequel/config/routes.rb create mode 100644 frameworks/Ruby/rage-sequel/lib/.keep create mode 100644 frameworks/Ruby/rage-sequel/rage-sequel.dockerfile diff --git a/frameworks/Ruby/rage-sequel/Gemfile b/frameworks/Ruby/rage-sequel/Gemfile new file mode 100644 index 00000000000..4ee2e620f6e --- /dev/null +++ b/frameworks/Ruby/rage-sequel/Gemfile @@ -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 diff --git a/frameworks/Ruby/rage-sequel/Gemfile.lock b/frameworks/Ruby/rage-sequel/Gemfile.lock new file mode 100644 index 00000000000..d1ad00bb988 --- /dev/null +++ b/frameworks/Ruby/rage-sequel/Gemfile.lock @@ -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 diff --git a/frameworks/Ruby/rage-sequel/README.md b/frameworks/Ruby/rage-sequel/README.md new file mode 100755 index 00000000000..d299d0834ba --- /dev/null +++ b/frameworks/Ruby/rage-sequel/README.md @@ -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 diff --git a/frameworks/Ruby/rage-sequel/Rakefile b/frameworks/Ruby/rage-sequel/Rakefile new file mode 100644 index 00000000000..046f1fcbd8d --- /dev/null +++ b/frameworks/Ruby/rage-sequel/Rakefile @@ -0,0 +1 @@ +require_relative "config/application" diff --git a/frameworks/Ruby/rage-sequel/app/controllers/application_controller.rb b/frameworks/Ruby/rage-sequel/app/controllers/application_controller.rb new file mode 100644 index 00000000000..c3238c52392 --- /dev/null +++ b/frameworks/Ruby/rage-sequel/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < RageController::API +end diff --git a/frameworks/Ruby/rage-sequel/app/controllers/benchmarks_controller.rb b/frameworks/Ruby/rage-sequel/app/controllers/benchmarks_controller.rb new file mode 100644 index 00000000000..b02e2d19416 --- /dev/null +++ b/frameworks/Ruby/rage-sequel/app/controllers/benchmarks_controller.rb @@ -0,0 +1,79 @@ +# 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.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 diff --git a/frameworks/Ruby/rage-sequel/app/views/fortunes.html.erb b/frameworks/Ruby/rage-sequel/app/views/fortunes.html.erb new file mode 100644 index 00000000000..2614ca7a7b2 --- /dev/null +++ b/frameworks/Ruby/rage-sequel/app/views/fortunes.html.erb @@ -0,0 +1,12 @@ + + +
id | message |
---|---|
<%= record.id %> | <%= CGI.escape_html(record.message) %> |