diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d13e16ce..eab4cbf5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: - ruby: ruby - ruby: head - ruby: truffleruby - skip: protoboeuf-encode + skip: protoboeuf-encode shipit if: ${{ github.event_name != 'schedule' || github.repository == 'Shopify/yjit-bench' }} steps: - uses: actions/checkout@v3 diff --git a/benchmarks.yml b/benchmarks.yml index aa85d7ed..827e8285 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -25,6 +25,9 @@ liquid-render: lobsters: desc: test a wide variety of routes in the Lobste.rs Rails app category: headline +shipit: + desc: test a wide variety of routes, both HTML and JSON API in the shipit Rails app + category: headline mail: desc: mail tests the Mail gem by repeatedly creating an email from a text file and converting it to a string for sending. category: headline diff --git a/benchmarks/shipit/.gitattributes b/benchmarks/shipit/.gitattributes new file mode 100644 index 00000000..8dc43234 --- /dev/null +++ b/benchmarks/shipit/.gitattributes @@ -0,0 +1,9 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored +config/credentials/*.yml.enc diff=rails_credentials +config/credentials.yml.enc diff=rails_credentials diff --git a/benchmarks/shipit/.gitignore b/benchmarks/shipit/.gitignore new file mode 100644 index 00000000..6698a6c8 --- /dev/null +++ b/benchmarks/shipit/.gitignore @@ -0,0 +1,36 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# Temporary files generated by your text editor or operating system +# belong in git's global ignore instead: +# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore` + +data/ + +# Ignore bundler config. +/.bundle + +# Ignore all environment files. +/.env* + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +/public/assets + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/benchmarks/shipit/Gemfile b/benchmarks/shipit/Gemfile new file mode 100644 index 00000000..91da1254 --- /dev/null +++ b/benchmarks/shipit/Gemfile @@ -0,0 +1,15 @@ +source "https://rubygems.org" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 8.0.2" +# Use sqlite3 as the database for Active Record +gem "sqlite3", ">= 2.1" +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", ">= 5.0" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data", platforms: %i[ windows jruby ] + +# Reduces boot times through caching; required in config/boot.rb +gem "bootsnap", require: false +gem "shipit-engine", ">= 0.40.0" diff --git a/benchmarks/shipit/Gemfile.lock b/benchmarks/shipit/Gemfile.lock new file mode 100644 index 00000000..518a3189 --- /dev/null +++ b/benchmarks/shipit/Gemfile.lock @@ -0,0 +1,421 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (8.0.2) + actionpack (= 8.0.2) + activesupport (= 8.0.2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.0.2) + actionpack (= 8.0.2) + activejob (= 8.0.2) + activerecord (= 8.0.2) + activestorage (= 8.0.2) + activesupport (= 8.0.2) + mail (>= 2.8.0) + actionmailer (8.0.2) + actionpack (= 8.0.2) + actionview (= 8.0.2) + activejob (= 8.0.2) + activesupport (= 8.0.2) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.2) + actionview (= 8.0.2) + activesupport (= 8.0.2) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.2) + actionpack (= 8.0.2) + activerecord (= 8.0.2) + activestorage (= 8.0.2) + activesupport (= 8.0.2) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.0.2) + activesupport (= 8.0.2) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + active_model_serializers (0.9.13) + activemodel (>= 3.2) + concurrent-ruby (~> 1.0) + activejob (8.0.2) + activesupport (= 8.0.2) + globalid (>= 0.3.6) + activemodel (8.0.2) + activesupport (= 8.0.2) + activerecord (8.0.2) + activemodel (= 8.0.2) + activesupport (= 8.0.2) + timeout (>= 0.4.0) + activestorage (8.0.2) + actionpack (= 8.0.2) + activejob (= 8.0.2) + activerecord (= 8.0.2) + activesupport (= 8.0.2) + marcel (~> 1.0) + activesupport (8.0.2) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + ansi_stream (0.0.6) + autoprefixer-rails (6.4.1.1) + execjs + axiom-types (0.1.1) + descendants_tracker (~> 0.0.4) + ice_nine (~> 0.11.0) + thread_safe (~> 0.3, >= 0.3.1) + base64 (0.3.0) + benchmark (0.4.1) + bigdecimal (3.2.2) + bootsnap (1.18.6) + msgpack (~> 1.2) + builder (3.3.0) + coercible (1.0.0) + descendants_tracker (~> 0.0.1) + coffee-rails (5.0.0) + coffee-script (>= 2.2.0) + railties (>= 5.2.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.3.5) + connection_pool (2.5.3) + crass (1.0.6) + date (3.4.1) + descendants_tracker (0.0.4) + thread_safe (~> 0.3, >= 0.3.1) + drb (2.2.3) + equalizer (0.0.11) + erb (5.0.1) + erubi (1.13.1) + execjs (2.10.0) + explicit-parameters (0.4.2) + actionpack (>= 6.0) + activemodel (>= 6.0) + ostruct + virtus (~> 1.0) + faraday (1.10.4) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.1) + faraday-excon (1.1.0) + faraday-http-cache (2.5.1) + faraday (>= 0.8) + faraday-httpclient (1.0.1) + faraday-multipart (1.1.1) + multipart-post (~> 2.0) + faraday-net_http (1.0.2) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + ffi (1.17.2-aarch64-linux-gnu) + ffi (1.17.2-aarch64-linux-musl) + ffi (1.17.2-arm-linux-gnu) + ffi (1.17.2-arm-linux-musl) + ffi (1.17.2-arm64-darwin) + ffi (1.17.2-x86_64-darwin) + ffi (1.17.2-x86_64-linux-gnu) + ffi (1.17.2-x86_64-linux-musl) + gemoji (2.1.0) + globalid (1.2.1) + activesupport (>= 6.1) + hashie (5.0.0) + i18n (1.14.7) + concurrent-ruby (~> 1.0) + ice_nine (0.11.2) + io-console (0.8.0) + irb (1.15.2) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jquery-rails (4.6.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jwt (3.1.2) + base64 + lodash-rails (4.17.21) + railties (>= 3.1) + logger (1.7.0) + loofah (2.24.1) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + mini_mime (1.1.5) + minitest (5.25.5) + msgpack (1.8.0) + multi_xml (0.7.2) + bigdecimal (~> 3.1) + multipart-post (2.4.1) + net-imap (0.5.9) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.1) + net-protocol + nio4r (2.7.4) + nokogiri (1.18.8-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.8-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.18.8-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.8-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.18.8-arm64-darwin) + racc (~> 1.4) + nokogiri (1.18.8-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.18.8-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.8-x86_64-linux-musl) + racc (~> 1.4) + oauth2 (2.0.12) + faraday (>= 0.17.3, < 4.0) + jwt (>= 1.0, < 4.0) + logger (~> 1.2) + multi_xml (~> 0.5) + rack (>= 1.2, < 4) + snaky_hash (~> 2.0, >= 2.0.3) + version_gem (>= 1.1.8, < 3) + octokit (5.6.1) + faraday (>= 1, < 3) + sawyer (~> 0.9) + omniauth (1.9.2) + hashie (>= 3.4.6) + rack (>= 1.6.2, < 3) + omniauth-github (1.4.0) + omniauth (~> 1.5) + omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-oauth2 (1.7.3) + oauth2 (>= 1.4, < 3) + omniauth (>= 1.9, < 3) + ostruct (0.6.2) + paquito (1.0.0) + msgpack (>= 1.5.2) + pp (0.6.2) + prettyprint + prettyprint (0.2.0) + psych (5.2.6) + date + stringio + public_suffix (6.0.2) + pubsubstub (0.3.1) + logger + rack + redis (~> 4.0) + puma (6.6.0) + nio4r (~> 2.0) + racc (1.8.1) + rack (2.2.17) + rack-session (1.0.2) + rack (< 3) + rack-test (2.2.0) + rack (>= 1.3) + rackup (1.0.1) + rack (< 3) + webrick + rails (8.0.2) + actioncable (= 8.0.2) + actionmailbox (= 8.0.2) + actionmailer (= 8.0.2) + actionpack (= 8.0.2) + actiontext (= 8.0.2) + actionview (= 8.0.2) + activejob (= 8.0.2) + activemodel (= 8.0.2) + activerecord (= 8.0.2) + activestorage (= 8.0.2) + activesupport (= 8.0.2) + bundler (>= 1.15.0) + railties (= 8.0.2) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + rails-timeago (2.13.0) + actionpack (>= 3.1) + activesupport (>= 3.1) + rails_autolink (1.1.8) + actionview (> 3.1) + activesupport (> 3.1) + railties (> 3.1) + railties (8.0.2) + actionpack (= 8.0.2) + activesupport (= 8.0.2) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.3.0) + rdoc (6.14.1) + erb + psych (>= 4.0.0) + redis (4.8.1) + redis-objects (1.7.0) + redis + reline (0.6.1) + io-console (~> 0.5) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) + ruby2_keywords (0.0.5) + safe_yaml (1.0.5) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + sawyer (0.9.2) + addressable (>= 2.3.5) + faraday (>= 0.17.3, < 3) + securecompare (1.0.0) + securerandom (0.4.1) + shipit-engine (0.40.0) + active_model_serializers (~> 0.9.3) + ansi_stream (~> 0.0.6) + autoprefixer-rails (~> 6.4.1) + coffee-rails (~> 5.0) + explicit-parameters (~> 0.4.0) + faraday (~> 1.3) + faraday-http-cache (~> 2.2) + gemoji (~> 2.1) + jquery-rails (~> 4.4) + lodash-rails (~> 4.17) + octokit (~> 5.6.0) + omniauth-github (~> 1.4) + paquito + pubsubstub (~> 0.2) + rails (~> 8.0.1) + rails-timeago (~> 2.13.0) + rails_autolink (~> 1.1.6) + rake + redis-objects (~> 1.5) + responders (~> 3.0) + safe_yaml (~> 1.0.4) + sass-rails (>= 5.0) + securecompare (~> 1.0.0) + sprockets (< 4) + sprockets-rails (>= 2.3.2) + state_machines-activerecord (~> 0.8.0) + validate_url (~> 1.0.0) + snaky_hash (2.0.3) + hashie (>= 0.1.0, < 6) + version_gem (>= 1.1.8, < 3) + sprockets (3.7.5) + base64 + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + sprockets (>= 3.0.0) + sqlite3 (2.7.1-aarch64-linux-gnu) + sqlite3 (2.7.1-aarch64-linux-musl) + sqlite3 (2.7.1-arm-linux-gnu) + sqlite3 (2.7.1-arm-linux-musl) + sqlite3 (2.7.1-arm64-darwin) + sqlite3 (2.7.1-x86_64-darwin) + sqlite3 (2.7.1-x86_64-linux-gnu) + sqlite3 (2.7.1-x86_64-linux-musl) + state_machines (0.31.0) + state_machines-activemodel (0.31.0) + activemodel (>= 7.1) + state_machines (>= 0.31.0) + state_machines-activerecord (0.8.0) + activerecord (>= 5.1) + state_machines-activemodel (>= 0.8.0) + stringio (3.1.7) + thor (1.3.2) + thread_safe (0.3.6) + tilt (2.6.0) + timeout (0.4.3) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uri (1.0.3) + useragent (0.16.11) + validate_url (1.0.15) + activemodel (>= 3.0.0) + public_suffix + version_gem (1.1.8) + virtus (1.0.5) + axiom-types (~> 0.1) + coercible (~> 1.0) + descendants_tracker (~> 0.0, >= 0.0.3) + equalizer (~> 0.0, >= 0.0.9) + webrick (1.9.1) + websocket-driver (0.8.0) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.7.3) + +PLATFORMS + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl + +DEPENDENCIES + bootsnap + puma (>= 5.0) + rails (~> 8.0.2) + shipit-engine (>= 0.40.0) + sqlite3 (>= 2.1) + tzinfo-data + +BUNDLED WITH + 2.6.7 diff --git a/benchmarks/shipit/Procfile b/benchmarks/shipit/Procfile new file mode 100644 index 00000000..c4c2519c --- /dev/null +++ b/benchmarks/shipit/Procfile @@ -0,0 +1,2 @@ +web: bundle exec rails s -p $PORT +worker: bundle exec sidekiq -C config/sidekiq.yml diff --git a/benchmarks/shipit/README.md b/benchmarks/shipit/README.md new file mode 100644 index 00000000..7db80e4c --- /dev/null +++ b/benchmarks/shipit/README.md @@ -0,0 +1,24 @@ +# README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... diff --git a/benchmarks/shipit/Rakefile b/benchmarks/shipit/Rakefile new file mode 100644 index 00000000..9a5ea738 --- /dev/null +++ b/benchmarks/shipit/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/benchmarks/shipit/app/assets/images/.keep b/benchmarks/shipit/app/assets/images/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/app/assets/stylesheets/application.css b/benchmarks/shipit/app/assets/stylesheets/application.css new file mode 100644 index 00000000..fe93333c --- /dev/null +++ b/benchmarks/shipit/app/assets/stylesheets/application.css @@ -0,0 +1,10 @@ +/* + * This is a manifest file that'll be compiled into application.css. + * + * With Propshaft, assets are served efficiently without preprocessing steps. You can still include + * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard + * cascading order, meaning styles declared later in the document or manifest will override earlier ones, + * depending on specificity. + * + * Consider organizing styles into separate files for maintainability. + */ diff --git a/benchmarks/shipit/app/controllers/application_controller.rb b/benchmarks/shipit/app/controllers/application_controller.rb new file mode 100644 index 00000000..0d95db22 --- /dev/null +++ b/benchmarks/shipit/app/controllers/application_controller.rb @@ -0,0 +1,4 @@ +class ApplicationController < ActionController::Base + # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. + allow_browser versions: :modern +end diff --git a/benchmarks/shipit/app/controllers/concerns/.keep b/benchmarks/shipit/app/controllers/concerns/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/app/helpers/application_helper.rb b/benchmarks/shipit/app/helpers/application_helper.rb new file mode 100644 index 00000000..de6be794 --- /dev/null +++ b/benchmarks/shipit/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/benchmarks/shipit/app/jobs/application_job.rb b/benchmarks/shipit/app/jobs/application_job.rb new file mode 100644 index 00000000..d394c3d1 --- /dev/null +++ b/benchmarks/shipit/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/benchmarks/shipit/app/models/application_record.rb b/benchmarks/shipit/app/models/application_record.rb new file mode 100644 index 00000000..b63caeb8 --- /dev/null +++ b/benchmarks/shipit/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/benchmarks/shipit/app/models/concerns/.keep b/benchmarks/shipit/app/models/concerns/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/app/views/layouts/application.html.erb b/benchmarks/shipit/app/views/layouts/application.html.erb new file mode 100644 index 00000000..9093f49a --- /dev/null +++ b/benchmarks/shipit/app/views/layouts/application.html.erb @@ -0,0 +1,27 @@ + + + + <%= content_for(:title) || "Shipit" %> + + + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= yield :head %> + + <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %> + <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %> + + + + + + <%# Includes all stylesheet files in app/assets/stylesheets %> + <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> + + + + <%= yield %> + + diff --git a/benchmarks/shipit/benchmark.rb b/benchmarks/shipit/benchmark.rb new file mode 100644 index 00000000..f0c8d9bb --- /dev/null +++ b/benchmarks/shipit/benchmark.rb @@ -0,0 +1,67 @@ +require 'securerandom' + +ENV['RAILS_ENV'] ||= 'production' +ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = '1' # Benchmarks don't really have 'production', so trash it at will. +ENV['SECRET_KEY_BASE'] = SecureRandom.hex(128) +ENV['SHIPIT_DISABLE_AUTH'] = '1' # Saves us lots of trouble + +require_relative '../../harness/loader' + +Dir.chdir __dir__ +use_gemfile + +require_relative 'config/environment' +require_relative "route_generator" + +# For an in-mem DB, we need to load all data on every boot +mem_db = ActiveRecord::Base.connection.raw_connection +file_db = SQLite3::Database.new('db/production.committed.sqlite3') +b = SQLite3::Backup.new(mem_db, 'main', file_db, 'main') +b.step(-1) # import until finished +b.finish # destroy the Backup object + +app = Rails.application + +api_key = Shipit::ApiClient.create!( + permissions: Shipit::ApiClient::PERMISSIONS, + creator: Shipit::User.first, + name: "Bench key", +).authentication_token + +generator = RouteGenerator.new(app, api_key: api_key) +generator.routes # Make sure routes have been pregenerated + +# Track ActiveRecord time +if ENV['TRACK_AR_TIME'] + ar_total_duration = 0.0 + process_start_t = Time.now + + # Track sql.active_record events + ActiveSupport::Notifications.subscribe "sql.active_record" do |name, started, finished, unique_id, data| + duration = finished - started + ar_total_duration += duration + end + + at_exit do + process_duration = Time.now - process_start_t + ar_percent = ar_total_duration * 100.0 / process_duration + puts "ActiveRecord time: #{ar_total_duration.round(2)}s (#{ar_percent.round(2)}%) PID: #{Process.pid}" + end +end + +run_benchmark(10) do + # Routes are from ./routes_generator.rb + generator.routes.each_with_index do |env, idx| + path = env["PATH_INFO"] # app.call mutates the path + response_array = generator.visit(env) # Track HTTP cookies as we go along + unless response_array.first == 200 + puts response_array.inspect + raise "HTTP status is #{response_array.first} instead of 200 for req #{idx}/#{generator.routes.size}, #{path.inspect}. Is the benchmark app properly set up? See README.md." + end + response_array.last.close # Response might be a Rack::BodyProxy and MUST be closed. + end +end + +# This benchmark will keep writing the production log on every request. It adds up. +# Let's not fill the disk. +File.unlink(File.join(__dir__, "log/#{ENV['RAILS_ENV']}.log")) rescue nil diff --git a/benchmarks/shipit/bin/dev b/benchmarks/shipit/bin/dev new file mode 100755 index 00000000..5f91c205 --- /dev/null +++ b/benchmarks/shipit/bin/dev @@ -0,0 +1,2 @@ +#!/usr/bin/env ruby +exec "./bin/rails", "server", *ARGV diff --git a/benchmarks/shipit/bin/rails b/benchmarks/shipit/bin/rails new file mode 100755 index 00000000..efc03774 --- /dev/null +++ b/benchmarks/shipit/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/benchmarks/shipit/bin/rake b/benchmarks/shipit/bin/rake new file mode 100755 index 00000000..4fbf10b9 --- /dev/null +++ b/benchmarks/shipit/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/benchmarks/shipit/bin/setup b/benchmarks/shipit/bin/setup new file mode 100755 index 00000000..be3db3c0 --- /dev/null +++ b/benchmarks/shipit/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require "fileutils" + +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args, exception: true) +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + unless ARGV.include?("--skip-server") + puts "\n== Starting development server ==" + STDOUT.flush # flush the output before exec(2) so that it displays + exec "bin/dev" + end +end diff --git a/benchmarks/shipit/config.ru b/benchmarks/shipit/config.ru new file mode 100644 index 00000000..4a3c09a6 --- /dev/null +++ b/benchmarks/shipit/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/benchmarks/shipit/config/application.rb b/benchmarks/shipit/config/application.rb new file mode 100644 index 00000000..fd49ce2f --- /dev/null +++ b/benchmarks/shipit/config/application.rb @@ -0,0 +1,76 @@ +require_relative "boot" + +require "rails" +# Pick the frameworks you want: +require "active_model/railtie" +require "active_job/railtie" +require "active_record/railtie" +# require "active_storage/engine" +require "action_controller/railtie" +# require "action_mailer/railtie" +# require "action_mailbox/engine" +# require "action_text/engine" +require "action_view/railtie" +# require "action_cable/engine" +require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Shipit + class Application < Rails::Application + Pubsubstub.use_persistent_connections = false + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 8.0 + + config.active_job.queue_adapter = :test + + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + end +end + +# Bencmark mods: +require "shipit" + +module Shipit + def secrets + @secrets ||= build_secrets + end + + FakeSecrets = Struct.new(:app_name, :user_access_tokens_key, :secret_key_base, :host, :redis_url, :github, keyword_init: true) + GitHubConfig = Struct.new(:domain, :app_id, :installation_id, :webhook_secret, :private_key, :oauth, keyword_init: true) + OauthConfig = Struct.new(:id, :secret, keyword_init: true) + + def build_secrets + secrets = ActiveSupport::OrderedOptions.new + secrets.app_name = "Shipit" + secrets.user_access_tokens_key = "unused" + secrets.secret_key_base = ENV.fetch('SECRET_KEY_BASE', "secret" * 20) + secrets.host = "localhost" + secrets.redis_url = "localhost" # Not actually used + + github = secrets.github = ActiveSupport::OrderedOptions.new + github.domain = nil # defaults to github.com + github.app_id = "random_unused_id" + github.installation_id = "random_unused_id" + github.webhook_secret = "random_unused_secret" + github.private_key = "random_unused_secret" + github.oauth = nil + + secrets + end +end +# +# p Pubsubstub::StreamAction \ No newline at end of file diff --git a/benchmarks/shipit/config/boot.rb b/benchmarks/shipit/config/boot.rb new file mode 100644 index 00000000..988a5ddc --- /dev/null +++ b/benchmarks/shipit/config/boot.rb @@ -0,0 +1,4 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/benchmarks/shipit/config/credentials.yml.enc b/benchmarks/shipit/config/credentials.yml.enc new file mode 100644 index 00000000..e2828bfe --- /dev/null +++ b/benchmarks/shipit/config/credentials.yml.enc @@ -0,0 +1 @@ +1yho4tuCzpdbeAVj1+GSUteL1jiDSqkM6W/z9z34hbDoscsApqu+3MZMHdtpvWdpoQUIgpPpDNHJsbLjaH4nGKoRGgROlpsvb63iUtLMho2NJ7HGOGAwCrfeE+XOn/kCEggdFbYDVEfi/lWJ4PJquoyzF6SGNqP/SZg6fweZfQ84uCJ65ZlMxD3Y26szH+oCPTQ4Gxd+bdirr98GvotwAlwj7Bo+bWsWaG6mdQ0wmRDoyAa7b0dKmW0DsVyieE3649KHHboubYISTJuKzzfmXyHjFNtIqb3K+ampoQlXYflQ7HrCm8Jf1Y0Ne0kB3pyzcpwUctQdrUh9Bhm9d0aXIIkr7A1FJTKQOVzxL+x7CeT18FVZ+5Rwbc3aLbE2BuN7+Ks6T994H+Mj7nQnRe79/zvteFrSePUB4XSAANS96KCDPzyK3lzokAKohe68Se9o+CziFXovA7O9fY2EglOMWgj1hdscWDukSTM6ruTwNpyztBhNF+9TbYhY--A8sLL8tJ4WM+AC6g--lOqUi2mfBsQDyaRytnGygA== \ No newline at end of file diff --git a/benchmarks/shipit/config/database.yml b/benchmarks/shipit/config/database.yml new file mode 100644 index 00000000..4fde1543 --- /dev/null +++ b/benchmarks/shipit/config/database.yml @@ -0,0 +1,20 @@ +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: ":memory:" + # database: "db/production.committed.sqlite3" diff --git a/benchmarks/shipit/config/deploy.yml b/benchmarks/shipit/config/deploy.yml new file mode 100644 index 00000000..a9123da7 --- /dev/null +++ b/benchmarks/shipit/config/deploy.yml @@ -0,0 +1,116 @@ +# Name of your application. Used to uniquely configure containers. +service: shipit + +# Name of the container image. +image: your-user/shipit + +# Deploy to these servers. +servers: + web: + - 192.168.0.1 + # job: + # hosts: + # - 192.168.0.1 + # cmd: bin/jobs + +# Enable SSL auto certification via Let's Encrypt and allow for multiple apps on a single web server. +# Remove this section when using multiple web servers and ensure you terminate SSL at your load balancer. +# +# Note: If using Cloudflare, set encryption mode in SSL/TLS setting to "Full" to enable CF-to-app encryption. +proxy: + ssl: true + host: app.example.com + +# Credentials for your image host. +registry: + # Specify the registry server, if you're not using Docker Hub + # server: registry.digitalocean.com / ghcr.io / ... + username: your-user + + # Always use an access token rather than real password when possible. + password: + - KAMAL_REGISTRY_PASSWORD + +# Inject ENV variables into containers (secrets come from .kamal/secrets). +env: + secret: + - RAILS_MASTER_KEY + clear: + # Run the Solid Queue Supervisor inside the web server's Puma process to do jobs. + # When you start using multiple servers, you should split out job processing to a dedicated machine. + SOLID_QUEUE_IN_PUMA: true + + # Set number of processes dedicated to Solid Queue (default: 1) + # JOB_CONCURRENCY: 3 + + # Set number of cores available to the application on each server (default: 1). + # WEB_CONCURRENCY: 2 + + # Match this to any external database server to configure Active Record correctly + # Use shipit-db for a db accessory server on same machine via local kamal docker network. + # DB_HOST: 192.168.0.2 + + # Log everything from Rails + # RAILS_LOG_LEVEL: debug + +# Aliases are triggered with "bin/kamal ". You can overwrite arguments on invocation: +# "bin/kamal logs -r job" will tail logs from the first server in the job section. +aliases: + console: app exec --interactive --reuse "bin/rails console" + shell: app exec --interactive --reuse "bash" + logs: app logs -f + dbc: app exec --interactive --reuse "bin/rails dbconsole" + + +# Use a persistent storage volume for sqlite database files and local Active Storage files. +# Recommended to change this to a mounted volume path that is backed up off server. +volumes: + - "shipit_storage:/rails/storage" + + +# Bridge fingerprinted assets, like JS and CSS, between versions to avoid +# hitting 404 on in-flight requests. Combines all files from new and old +# version inside the asset_path. +asset_path: /rails/public/assets + +# Configure the image builder. +builder: + arch: amd64 + + # # Build image via remote server (useful for faster amd64 builds on arm64 computers) + # remote: ssh://docker@docker-builder-server + # + # # Pass arguments and secrets to the Docker build process + # args: + # RUBY_VERSION: ruby-3.4.3 + # secrets: + # - GITHUB_TOKEN + # - RAILS_MASTER_KEY + +# Use a different ssh user than root +# ssh: +# user: app + +# Use accessory services (secrets come from .kamal/secrets). +# accessories: +# db: +# image: mysql:8.0 +# host: 192.168.0.2 +# # Change to 3306 to expose port to the world instead of just local network. +# port: "127.0.0.1:3306:3306" +# env: +# clear: +# MYSQL_ROOT_HOST: '%' +# secret: +# - MYSQL_ROOT_PASSWORD +# files: +# - config/mysql/production.cnf:/etc/mysql/my.cnf +# - db/production.sql:/docker-entrypoint-initdb.d/setup.sql +# directories: +# - data:/var/lib/mysql +# redis: +# image: redis:7.0 +# host: 192.168.0.2 +# port: 6379 +# directories: +# - data:/data diff --git a/benchmarks/shipit/config/environment.rb b/benchmarks/shipit/config/environment.rb new file mode 100644 index 00000000..cac53157 --- /dev/null +++ b/benchmarks/shipit/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/benchmarks/shipit/config/environments/development.rb b/benchmarks/shipit/config/environments/development.rb new file mode 100644 index 00000000..5ae50225 --- /dev/null +++ b/benchmarks/shipit/config/environments/development.rb @@ -0,0 +1,57 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Make code changes take effect immediately without server restart. + config.enable_reloading = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing. + config.server_timing = true + + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" } + else + config.action_controller.perform_caching = false + end + + # Change to :null_store to avoid any caching. + config.cache_store = :memory_store + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Append comments with runtime information tags to SQL queries in logs. + config.active_record.query_log_tags_enabled = true + + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! +end diff --git a/benchmarks/shipit/config/environments/production.rb b/benchmarks/shipit/config/environments/production.rb new file mode 100644 index 00000000..a50ba702 --- /dev/null +++ b/benchmarks/shipit/config/environments/production.rb @@ -0,0 +1,75 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # config.cache_store = :redis_cache_store, { url: Shipit.redis_url.to_s, expires_in: 90.minutes } + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). + config.eager_load = true + + # Full error reports are disabled. + config.consider_all_requests_local = false + + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true + + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = true + + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + + # Log to STDOUT with the current request id as a default log tag. + config.log_tags = [ :request_id ] + config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) + + # Change to "debug" to log everything (including potentially personally-identifiable information!) + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = "/up" + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Replace the default in-process memory cache store with a durable alternative. + # config.cache_store = :mem_cache_store + + # Replace the default in-process and non-durable queuing backend for Active Job. + # config.active_job.queue_adapter = :resque + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [ :id ] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } + + # Benchmark mods: + config.logger = nil # disable logging + config.yjit = false +end diff --git a/benchmarks/shipit/config/environments/test.rb b/benchmarks/shipit/config/environments/test.rb new file mode 100644 index 00000000..14bc29e0 --- /dev/null +++ b/benchmarks/shipit/config/environments/test.rb @@ -0,0 +1,42 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with cache-control for performance. + config.public_file_server.headers = { "cache-control" => "public, max-age=3600" } + + # Show full error reports. + config.consider_all_requests_local = true + config.cache_store = :null_store + + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true +end diff --git a/benchmarks/shipit/config/initializers/assets.rb b/benchmarks/shipit/config/initializers/assets.rb new file mode 100644 index 00000000..48732442 --- /dev/null +++ b/benchmarks/shipit/config/initializers/assets.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = "1.0" + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path diff --git a/benchmarks/shipit/config/initializers/content_security_policy.rb b/benchmarks/shipit/config/initializers/content_security_policy.rb new file mode 100644 index 00000000..b3076b38 --- /dev/null +++ b/benchmarks/shipit/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header + +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src style-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true +# end diff --git a/benchmarks/shipit/config/initializers/filter_parameter_logging.rb b/benchmarks/shipit/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000..c0b717f7 --- /dev/null +++ b/benchmarks/shipit/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc +] diff --git a/benchmarks/shipit/config/initializers/inflections.rb b/benchmarks/shipit/config/initializers/inflections.rb new file mode 100644 index 00000000..3860f659 --- /dev/null +++ b/benchmarks/shipit/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/benchmarks/shipit/config/locales/en.yml b/benchmarks/shipit/config/locales/en.yml new file mode 100644 index 00000000..6c349ae5 --- /dev/null +++ b/benchmarks/shipit/config/locales/en.yml @@ -0,0 +1,31 @@ +# Files in the config/locales directory are used for internationalization and +# are automatically loaded by Rails. If you want to use locales other than +# English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more about the API, please read the Rails Internationalization guide +# at https://guides.rubyonrails.org/i18n.html. +# +# Be aware that YAML interprets the following case-insensitive strings as +# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings +# must be quoted to be interpreted as strings. For example: +# +# en: +# "yes": yup +# enabled: "ON" + +en: + hello: "Hello world" diff --git a/benchmarks/shipit/config/puma.rb b/benchmarks/shipit/config/puma.rb new file mode 100644 index 00000000..a248513b --- /dev/null +++ b/benchmarks/shipit/config/puma.rb @@ -0,0 +1,41 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. +# +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"] + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/benchmarks/shipit/config/routes.rb b/benchmarks/shipit/config/routes.rb new file mode 100644 index 00000000..ea6924d3 --- /dev/null +++ b/benchmarks/shipit/config/routes.rb @@ -0,0 +1,15 @@ +Rails.application.routes.draw do + mount Shipit::Engine, at: '/' + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. + # 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 + + # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb) + # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest + # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker + + # Defines the root path route ("/") + # root "posts#index" +end diff --git a/benchmarks/shipit/config/secrets.example.yml b/benchmarks/shipit/config/secrets.example.yml new file mode 100644 index 00000000..600a5ba3 --- /dev/null +++ b/benchmarks/shipit/config/secrets.example.yml @@ -0,0 +1,51 @@ +development: + app_name: My Shipit + secret_key_base: d96514647c865790ce32354f97d4b8aab2b30a5deacf41567dc8ad93f9dd3e0ec5871213f0a8fca147fe73b8780faa83ee12fb06d0e904b7c8c4e515c192efd6 + host: 'http://localhost:3000' + redis_url: redis://localhost + github: + domain: # defaults to github.com + bot_login: + app_id: + installation_id: + webhook_secret: + private_key: + oauth: + id: + secret: + # team: MyOrg/developers # Enable this setting to restrict access to only the member of a team + +test: + app_name: My Shipit + secret_key_base: eb84da32cb39b9f4074b7b17ef682bbe11b10224054cf0aa937ae3fb188fa202bd1e4317b7a5a8b2b984fa00b0409f93add1747430eee396cd3ffb286af23cd4 + host: 'http://localhost:4000' + redis_url: redis://localhost + github: + domain: # defaults to github.com + bot_login: + app_id: + installation_id: + webhook_secret: + private_key: + oauth: + id: <%= ENV['GITHUB_OAUTH_ID'] %> + secret: <%= ENV['GITHUB_OAUTH_SECRET'] %> + # teams: MyOrg/developers # Enable this setting to restrict access to only the member of a team + +production: + app_name: My Shipit + secret_key_base: <%= ENV['SECRET_KEY_BASE'] %> + host: <%= ENV['SHIPIT_HOST'] %> + redis_url: <%= ENV['REDIS_URL'] %> + github: + domain: # defaults to github.com + app_id: <%= ENV['GITHUB_APP_ID'] %> + installation_id: <%= ENV['GITHUB_INSTALLATION_ID'] %> + webhook_secret: + private_key: + oauth: + id: <%= ENV['GITHUB_OAUTH_ID'] %> + secret: <%= ENV['GITHUB_OAUTH_SECRET'] %> + # teams: MyOrg/developers # Enable this setting to restrict access to only the member of a team + env: + # SSH_AUTH_SOCK: /foo/bar # You can set environment variable that will be present during deploys. diff --git a/benchmarks/shipit/config/secrets.yml b/benchmarks/shipit/config/secrets.yml new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/config/sidekiq.yml b/benchmarks/shipit/config/sidekiq.yml new file mode 100644 index 00000000..2ca005a9 --- /dev/null +++ b/benchmarks/shipit/config/sidekiq.yml @@ -0,0 +1,6 @@ +:concurrency: 1 +:queues: + - default + - deploys + - hooks + - low diff --git a/benchmarks/shipit/db/production.committed.sqlite3 b/benchmarks/shipit/db/production.committed.sqlite3 new file mode 100644 index 00000000..c57a8064 Binary files /dev/null and b/benchmarks/shipit/db/production.committed.sqlite3 differ diff --git a/benchmarks/shipit/db/schema.rb b/benchmarks/shipit/db/schema.rb new file mode 100644 index 00000000..0f651a43 --- /dev/null +++ b/benchmarks/shipit/db/schema.rb @@ -0,0 +1,14 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.0].define(version: 0) do +end diff --git a/benchmarks/shipit/db/seeds.rb b/benchmarks/shipit/db/seeds.rb new file mode 100644 index 00000000..4fbd6ed9 --- /dev/null +++ b/benchmarks/shipit/db/seeds.rb @@ -0,0 +1,9 @@ +# This file should ensure the existence of records required to run the application in every environment (production, +# development, test). The code here should be idempotent so that it can be executed at any point in every environment. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Example: +# +# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| +# MovieGenre.find_or_create_by!(name: genre_name) +# end diff --git a/benchmarks/shipit/db/test.sqlite3 b/benchmarks/shipit/db/test.sqlite3 new file mode 100644 index 00000000..57c6196b Binary files /dev/null and b/benchmarks/shipit/db/test.sqlite3 differ diff --git a/benchmarks/shipit/lib/tasks/.keep b/benchmarks/shipit/lib/tasks/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/log/.keep b/benchmarks/shipit/log/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/public/400.html b/benchmarks/shipit/public/400.html new file mode 100644 index 00000000..282dbc8c --- /dev/null +++ b/benchmarks/shipit/public/400.html @@ -0,0 +1,114 @@ + + + + + + + The server cannot process the request due to a client error (400 Bad Request) + + + + + + + + + + + + + +
+
+ +
+
+

The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/benchmarks/shipit/public/404.html b/benchmarks/shipit/public/404.html new file mode 100644 index 00000000..c0670bc8 --- /dev/null +++ b/benchmarks/shipit/public/404.html @@ -0,0 +1,114 @@ + + + + + + + The page you were looking for doesn’t exist (404 Not found) + + + + + + + + + + + + + +
+
+ +
+
+

The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/benchmarks/shipit/public/406-unsupported-browser.html b/benchmarks/shipit/public/406-unsupported-browser.html new file mode 100644 index 00000000..9532a9cc --- /dev/null +++ b/benchmarks/shipit/public/406-unsupported-browser.html @@ -0,0 +1,114 @@ + + + + + + + Your browser is not supported (406 Not Acceptable) + + + + + + + + + + + + + +
+
+ +
+
+

Your browser is not supported.
Please upgrade your browser to continue.

+
+
+ + + + diff --git a/benchmarks/shipit/public/422.html b/benchmarks/shipit/public/422.html new file mode 100644 index 00000000..8bcf0601 --- /dev/null +++ b/benchmarks/shipit/public/422.html @@ -0,0 +1,114 @@ + + + + + + + The change you wanted was rejected (422 Unprocessable Entity) + + + + + + + + + + + + + +
+
+ +
+
+

The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/benchmarks/shipit/public/500.html b/benchmarks/shipit/public/500.html new file mode 100644 index 00000000..d77718c3 --- /dev/null +++ b/benchmarks/shipit/public/500.html @@ -0,0 +1,114 @@ + + + + + + + We’re sorry, but something went wrong (500 Internal Server Error) + + + + + + + + + + + + + +
+
+ +
+
+

We’re sorry, but something went wrong.
If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/benchmarks/shipit/public/icon.png b/benchmarks/shipit/public/icon.png new file mode 100644 index 00000000..c4c9dbfb Binary files /dev/null and b/benchmarks/shipit/public/icon.png differ diff --git a/benchmarks/shipit/public/icon.svg b/benchmarks/shipit/public/icon.svg new file mode 100644 index 00000000..04b34bf8 --- /dev/null +++ b/benchmarks/shipit/public/icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/benchmarks/shipit/public/robots.txt b/benchmarks/shipit/public/robots.txt new file mode 100644 index 00000000..c19f78ab --- /dev/null +++ b/benchmarks/shipit/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/benchmarks/shipit/route_generator.rb b/benchmarks/shipit/route_generator.rb new file mode 100644 index 00000000..5cc1d2a4 --- /dev/null +++ b/benchmarks/shipit/route_generator.rb @@ -0,0 +1,77 @@ +# Generate a set of routes for Lobsters + +class RouteGenerator + # Take a variety of routes and randomise order, distribution and specific data items (comments, users.) + ROUTE_GROUPS = [ + { num: 5, method: :GET, routes: ["/"] }, # Stacks#index + { num: 15, method: :GET, routes: ["/:stack_id"] }, # Stacks#show + { num: 10, method: :GET, routes: [ + "/:stack_id/tasks?since=33", # Paginated deploys + "/:stack_id/statistics", + ]}, + { num: 2, method: :GET, routes: [ "/:stack_id/settings" ]}, + + # API routes + { num: 5, method: :GET, routes: ["/api/stacks"] }, + { num: 10, method: :GET, routes: ["/api/stacks/:stack_id/deploys"] }, + { num: 10, method: :GET, routes: ["/api/stacks/:stack_id/commits"] }, + ] + + def initialize(app, rng: nil, api_key:) + @app = app + + @auth_token = nil + @resp_cookie_header = nil + @logged_in = false + + @api_key = api_key + creds = ["#{@api_key}:"].pack("m") + @auth_header = "Basic #{creds}" + @rng = rng || Random.new(0x1be52551fc152997) + end + + def routes + @routes ||= generate_routes + end + + def visit(route) + @app.call(route) + end + + private + + def generate_routes + db_ids = { + stack_id: Shipit::Stack.all.map(&:to_param) + } + + # We want to randomise the order, but we need to make sure a user, comment, etc. exists when it's referenced. + # So we start by creating a set of references to "this group is at this point in the order" and then + # fill them in, keeping track of data items as we go along. + group_list = ROUTE_GROUPS.flat_map { |group| (1..group[:num]).map { group } } # group[:num] references to each group + group_list.shuffle!(random: @rng) + + route_group_envs = [] + group_list.each do |group| + route = group[:routes].sample(random: @rng) + if route.include?(":") + route = route.gsub(/:(\w+)/) do |match| + db_ids[$1.to_sym].sample(random: @rng) + end + end + env = Rack::MockRequest::env_for("https://localhost#{route}", method: group[:method]) + if route.start_with?("/api/") + env["HTTP_AUTHORIZATION"] = @auth_header + end + route_group_envs << env + + # Do we need to mess with our list of data items? + # If we figure out comment upvote/flag/delete etc. we'll need some of this. + # For now, ignore. + #if group[:method] != :GET && group[:post_opts] + #end + end + + route_group_envs + end +end diff --git a/benchmarks/shipit/script/.keep b/benchmarks/shipit/script/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/storage/.keep b/benchmarks/shipit/storage/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/test/application_system_test_case.rb b/benchmarks/shipit/test/application_system_test_case.rb new file mode 100644 index 00000000..cee29fd2 --- /dev/null +++ b/benchmarks/shipit/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] +end diff --git a/benchmarks/shipit/test/controllers/.keep b/benchmarks/shipit/test/controllers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/test/fixtures/files/.keep b/benchmarks/shipit/test/fixtures/files/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/test/helpers/.keep b/benchmarks/shipit/test/helpers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/test/integration/.keep b/benchmarks/shipit/test/integration/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/test/models/.keep b/benchmarks/shipit/test/models/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/test/system/.keep b/benchmarks/shipit/test/system/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/test/test_helper.rb b/benchmarks/shipit/test/test_helper.rb new file mode 100644 index 00000000..0c22470e --- /dev/null +++ b/benchmarks/shipit/test/test_helper.rb @@ -0,0 +1,15 @@ +ENV["RAILS_ENV"] ||= "test" +require_relative "../config/environment" +require "rails/test_help" + +module ActiveSupport + class TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... + end +end diff --git a/benchmarks/shipit/tmp/.keep b/benchmarks/shipit/tmp/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/tmp/pids/.keep b/benchmarks/shipit/tmp/pids/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/tmp/storage/.keep b/benchmarks/shipit/tmp/storage/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/shipit/vendor/.keep b/benchmarks/shipit/vendor/.keep new file mode 100644 index 00000000..e69de29b