From f960cfb43c9956c5d402e45f3df29109e7a61925 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Wed, 20 Dec 2023 10:50:43 +0100 Subject: [PATCH 1/6] Use Ruby 3.3.0-rc1 --- .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 16 +++++++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.ruby-version b/.ruby-version index 72b3400..89104b5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.2.1 +ruby-3.3.0-rc1 diff --git a/Gemfile b/Gemfile index aa61588..d6d5a34 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -ruby "3.2.1" +ruby "3.3.0.rc1" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.1.2" diff --git a/Gemfile.lock b/Gemfile.lock index c50b23c..b21a527 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -128,6 +128,7 @@ GEM marcel (1.0.2) matrix (0.4.2) mini_mime (1.1.5) + mini_portile2 (2.8.5) minitest (5.20.0) msgpack (1.7.2) mutex_m (0.2.0) @@ -141,11 +142,8 @@ GEM net-smtp (0.4.0) net-protocol nio4r (2.7.0) - nokogiri (1.15.5-aarch64-linux) - racc (~> 1.4) - nokogiri (1.15.5-arm64-darwin) - racc (~> 1.4) - nokogiri (1.15.5-x86_64-linux) + nokogiri (1.15.5) + mini_portile2 (~> 2.8.2) racc (~> 1.4) pg (1.5.4) propshaft (0.8.0) @@ -213,9 +211,8 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - sqlite3 (1.6.9-aarch64-linux) - sqlite3 (1.6.9-arm64-darwin) - sqlite3 (1.6.9-x86_64-linux) + sqlite3 (1.6.9) + mini_portile2 (~> 2.8.0) stimulus-rails (1.3.0) railties (>= 6.0.0) stringio (3.1.0) @@ -244,6 +241,7 @@ GEM PLATFORMS aarch64-linux arm64-darwin-21 + arm64-darwin-23 x86_64-linux DEPENDENCIES @@ -267,7 +265,7 @@ DEPENDENCIES web-console RUBY VERSION - ruby 3.2.1p31 + ruby 3.3.0.rc1 BUNDLED WITH 2.4.19 From b0f392fe5a12de513b5a1501ab6cf37a2dfa4f89 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Wed, 20 Dec 2023 10:52:21 +0100 Subject: [PATCH 2/6] Use GET instead of POST for benchmarking requests (wrk compatibility) When benchmarking with the popular benchmarking tool wrk, doing POST requests require creating a LUA script which is annoying. No reason to use POST for these benchmarking routes. --- app/controllers/benchmarking_controller.rb | 7 +++---- config/routes.rb | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/benchmarking_controller.rb b/app/controllers/benchmarking_controller.rb index 2f6d006..7627e94 100644 --- a/app/controllers/benchmarking_controller.rb +++ b/app/controllers/benchmarking_controller.rb @@ -1,8 +1,7 @@ class BenchmarkingController < ApplicationController - skip_before_action :verify_authenticity_token before_action :set_user_update_last_seen_at - # POST /benchmarking/read_heavy + # GET /benchmarking/read_heavy def read_heavy act_and_respond( post_create: 0.10, @@ -15,7 +14,7 @@ def read_heavy ) end - # POST /benchmarking/write_heavy + # GET /benchmarking/write_heavy def write_heavy act_and_respond( post_create: 0.25, @@ -28,7 +27,7 @@ def write_heavy ) end - # POST /benchmarking/balanced + # GET /benchmarking/balanced def balanced act_and_respond( post_create: 0.17, diff --git a/config/routes.rb b/config/routes.rb index d7628a4..d4df5a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,9 +19,9 @@ # Can be used by load balancers and uptime monitors to verify that the app is live. get "up" => "rails/health#show", as: :rails_health_check - post "benchmarking/read_heavy" => "benchmarking#read_heavy" - post "benchmarking/write_heavy" => "benchmarking#write_heavy" - post "benchmarking/balanced" => "benchmarking#balanced" + get "benchmarking/read_heavy" + get "benchmarking/write_heavy" + get "benchmarking/balanced" # Defines the root path route ("/") root to: "posts#index" From f1f0bf6eeb1ce2218fc226668790308616092d7c Mon Sep 17 00:00:00 2001 From: David Backeus Date: Wed, 20 Dec 2023 10:52:44 +0100 Subject: [PATCH 3/6] Remove the blasphemous production SQLite warning. --- config/environments/production.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/environments/production.rb b/config/environments/production.rb index d9541af..1c3bd2b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -88,4 +88,6 @@ # ] # Skip DNS rebinding protection for the default health check endpoint. # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } + + config.active_record.sqlite3_production_warning = false end From e958f1c14684a42fce28595bf84c62e549f69812 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Wed, 20 Dec 2023 10:54:03 +0100 Subject: [PATCH 4/6] Fix missing template error on post_destroy --- app/controllers/benchmarking_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/benchmarking_controller.rb b/app/controllers/benchmarking_controller.rb index 7627e94..a720a84 100644 --- a/app/controllers/benchmarking_controller.rb +++ b/app/controllers/benchmarking_controller.rb @@ -88,7 +88,7 @@ def act_and_respond(actions_with_weighted_distribution) head :created when :comment_create head :created - when :comment_destroy + when :comment_destroy, :post_destroy head :no_content when :post_show render "posts/show", status: :ok From 48e2e648cd552ef4aba9106f48f4428985bcb5c9 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Wed, 20 Dec 2023 10:54:26 +0100 Subject: [PATCH 5/6] Add long running query benchmarking endpoint (for concurrency tests) --- app/controllers/benchmarking_controller.rb | 19 +++++++++++++++++++ config/routes.rb | 1 + 2 files changed, 20 insertions(+) diff --git a/app/controllers/benchmarking_controller.rb b/app/controllers/benchmarking_controller.rb index a720a84..7e6e6e4 100644 --- a/app/controllers/benchmarking_controller.rb +++ b/app/controllers/benchmarking_controller.rb @@ -40,6 +40,25 @@ def balanced ) end + # GET /benchmarking/long_running + def long_running + ActiveRecord::Base.connection_pool.with_connection do |conn| + # Since SQLite doesn't have a sleep function, we'll use a recursive CTE + # which takes approximately 1 second to execute. + conn.raw_connection.execute <<~SQL + WITH RECURSIVE r(i) AS ( + VALUES(0) + UNION ALL + SELECT i FROM r + LIMIT 10000000 + ) + SELECT i FROM r WHERE i = 1; + SQL + end + + head :ok + end + private def set_user_update_last_seen_at diff --git a/config/routes.rb b/config/routes.rb index d4df5a4..43c5a87 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,7 @@ get "benchmarking/read_heavy" get "benchmarking/write_heavy" get "benchmarking/balanced" + get "benchmarking/long_running" # Defines the root path route ("/") root to: "posts#index" From 48d03e51400fbd1531f4d34a93b077959e932787 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Thu, 21 Dec 2023 08:20:38 +0100 Subject: [PATCH 6/6] Add the activerecord-enhancedsqlite3-adapter with extralite branch Also bundle update --- Gemfile | 8 +++++--- Gemfile.lock | 38 +++++++++++++++++++++++++------------- config/database.yml | 2 ++ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index d6d5a34..e5f7fc3 100644 --- a/Gemfile +++ b/Gemfile @@ -8,9 +8,6 @@ gem "rails", "~> 7.1.2" # The modern asset pipeline for Rails [https://github.com/rails/propshaft] gem "propshaft" -# Use sqlite3 as the database for Active Record -gem "sqlite3", "~> 1.4" - # Use the Puma web server [https://github.com/puma/puma] gem "puma", ">= 5.0" @@ -44,6 +41,11 @@ gem "bootsnap", require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" +# SQLite +gem "activerecord-enhancedsqlite3-adapter", git: "https://github.com/dbackeus/activerecord-enhancedsqlite3-adapter.git", branch: "extralite" +gem "sqlite3" +gem "extralite" + group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri windows ] diff --git a/Gemfile.lock b/Gemfile.lock index b21a527..4f5c546 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +GIT + remote: https://github.com/dbackeus/activerecord-enhancedsqlite3-adapter.git + revision: 77b3d6b4d55b553d9cf681e7605144ee585f66ac + branch: extralite + specs: + activerecord-enhancedsqlite3-adapter (0.4.0) + activerecord (>= 7.1) + sqlite3 (~> 1.6) + GEM remote: https://rubygems.org/ specs: @@ -75,10 +84,10 @@ GEM minitest (>= 5.1) mutex_m tzinfo (~> 2.0) - addressable (2.8.5) + addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) base64 (0.2.0) - bigdecimal (3.1.4) + bigdecimal (3.1.5) bindex (0.8.1) bootsnap (1.17.0) msgpack (~> 1.2) @@ -99,20 +108,21 @@ GEM cssbundling-rails (1.3.3) railties (>= 6.0.0) date (3.3.4) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) + debug (1.9.0) + irb (~> 1.10) + reline (>= 0.3.8) drb (2.2.0) ruby2_keywords erubi (1.12.0) + extralite (2.3) faker (3.2.2) i18n (>= 1.8.11, < 2) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.10.1) + io-console (0.7.1) + irb (1.11.0) rdoc reline (>= 0.3.8) jsbundling-rails (1.2.1) @@ -132,7 +142,7 @@ GEM minitest (5.20.0) msgpack (1.7.2) mutex_m (0.2.0) - net-imap (0.4.7) + net-imap (0.4.8) date net-protocol net-pop (0.1.2) @@ -151,7 +161,7 @@ GEM activesupport (>= 7.0.0) rack railties (>= 7.0.0) - psych (5.1.1.1) + psych (5.1.2) stringio public_suffix (5.0.4) puma (6.4.0) @@ -195,11 +205,11 @@ GEM thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rake (13.1.0) - rdoc (6.6.1) + rdoc (6.6.2) psych (>= 4.0.0) redis (5.0.8) redis-client (>= 0.17.0) - redis-client (0.18.0) + redis-client (0.19.0) connection_pool regexp_parser (2.8.3) reline (0.4.1) @@ -215,7 +225,7 @@ GEM mini_portile2 (~> 2.8.0) stimulus-rails (1.3.0) railties (>= 6.0.0) - stringio (3.1.0) + stringio (3.1.1) thor (1.3.0) timeout (0.4.1) turbo-rails (1.5.0) @@ -245,11 +255,13 @@ PLATFORMS x86_64-linux DEPENDENCIES + activerecord-enhancedsqlite3-adapter! bootsnap browser (~> 5.3) capybara cssbundling-rails debug + extralite faker (~> 3.2) jsbundling-rails pg (~> 1.5) @@ -258,7 +270,7 @@ DEPENDENCIES rails (~> 7.1.2) redis (>= 4.0.1) selenium-webdriver - sqlite3 (~> 1.4) + sqlite3 stimulus-rails turbo-rails tzinfo-data diff --git a/config/database.yml b/config/database.yml index 796466b..03bf2aa 100644 --- a/config/database.yml +++ b/config/database.yml @@ -8,6 +8,8 @@ default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 + client: <%= ENV["DB_CLIENT"] %> + strict: false development: <<: *default