Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ gem "ostruct"
gem "csv"

gem "minitest", "~> 5.0"

gem "solid_queue"
26 changes: 19 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rails_performance (1.6.0)
rails_performance (1.7.0.beta1)
browser
railties
redis
Expand Down Expand Up @@ -132,7 +132,13 @@ GEM
zeitwerk (~> 2.6)
erb (5.1.1)
erubi (1.13.1)
et-orbi (1.4.0)
tzinfo
ffi (1.17.2)
ffi (1.17.2-arm64-darwin)
fugit (1.11.2)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
get_process_mem (1.0.0)
bigdecimal (>= 2.0)
ffi (~> 1.0)
Expand Down Expand Up @@ -168,7 +174,6 @@ GEM
nokogiri (~> 1)
rake
mini_mime (1.1.5)
mini_portile2 (2.8.9)
minitest (5.26.0)
mustermann (3.0.4)
ruby2_keywords (~> 0.0.1)
Expand All @@ -184,8 +189,7 @@ GEM
net-smtp (0.5.1)
net-protocol
nio4r (2.7.4)
nokogiri (1.18.10)
mini_portile2 (~> 2.8.2)
nokogiri (1.18.10-arm64-darwin)
racc (~> 1.4)
orm_adapter (0.5.0)
ostruct (0.6.3)
Expand All @@ -202,6 +206,7 @@ GEM
stringio
puma (7.0.4)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.2.3)
rack-session (2.1.1)
Expand Down Expand Up @@ -289,6 +294,13 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
solid_queue (1.2.1)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11.0)
railties (>= 7.1)
thor (>= 1.3.1)
sprockets (4.2.2)
concurrent-ruby (~> 1.0)
logger
Expand All @@ -297,8 +309,7 @@ GEM
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sqlite3 (2.7.4)
mini_portile2 (~> 2.8.0)
sqlite3 (2.7.4-arm64-darwin)
standard (1.51.1)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
Expand Down Expand Up @@ -339,7 +350,7 @@ GEM
zeitwerk (2.7.3)

PLATFORMS
ruby
arm64-darwin-24

DEPENDENCIES
actionmailer
Expand All @@ -360,6 +371,7 @@ DEPENDENCIES
rails_performance!
sidekiq
simplecov
solid_queue
sprockets-rails
sqlite3
standard
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ It allows you to track:
- simple 500-crashes reports
- deployment events (or custom events)
- Sidekiq jobs
- SolidQueue jobs
- ActiveJob jobs
- Delayed Job jobs
- Grape API inside Rails app
- Rake tasks performance
Expand Down Expand Up @@ -310,8 +312,12 @@ Just clone the repo, setup dummy app (`rails db:migrate`).

After this:

- rails s
- rake test
- `rails s`
- `cd test/dummy` and `bundle exec rails db:migrate:queue`
- `cd test/dummy` and `bundle exec bin/jobs` (if you want to test ActiveJob)
- `rake test`

If you need to start with solid queue `SOLID_QUEUE_IN_PUMA=true rails s`.

If you need quickly clear Redis data, you can use `rails runner 'RailsPerformance.redis.flushdb'`.

Expand Down Expand Up @@ -360,6 +366,14 @@ The idea of this gem grew from curiosity how many RPM my app receiving per day.
4. Run `rails s` in the root folder
5. Run `rails test` to run tests

## Running with different versions of Rails

```bash
BUNDLE_GEMFILE=gemfiles/rails_7.2.gemfile bundle
BUNDLE_GEMFILE=gemfiles/rails_8.0.gemfile bundle
BUNDLE_GEMFILE=gemfiles/rails_8.1.gemfile bundle
```

## Contributing

You are welcome to contribute. I've a big list of TODO.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def requests
end
end

def jobs
@datasource = RailsPerformance::DataSource.new(**prepare_query, type: :jobs)
db = @datasource.db
@throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
@response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
@recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
end

def recent
@datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :requests)
db = @datasource.db
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/rails_performance/rails_performance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def report_name(h)

def status_tag(status)
klass = case status.to_s
when /error/
when /error/, /exception/
"tag is-danger"
when /^5/
"tag is-danger"
Expand Down Expand Up @@ -140,6 +140,8 @@ def active?(section)
"is-active" if controller_name == "rails_performance" && action_name == "rake"
when :custom
"is-active" if controller_name == "rails_performance" && action_name == "custom"
when :jobs
"is-active" if controller_name == "rails_performance" && action_name == "jobs"
end
end
end
Expand Down
69 changes: 69 additions & 0 deletions app/views/rails_performance/rails_performance/jobs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<title>ActiveJob</title>

<% unless @datasource.default? %>
<%#= link_to raw("&larr; Back"), rails_performance_path, class: "back_link" %>
<% end %>

<div class="card">
<div class="card-content">
<h2 class="subtitle">ActiveJob Workers Throughput Report</h2>
<rails-performance-chart id="throughput_report_chart" type="TIR" legend="Jobs" units="jobs / minute" class="chart">
<%= raw @throughput_report_data.to_json %>
</rails-performance-chart>
<p class="content is-small">All active jobs in the application</p>
</div>
</div>

<br/>

<div class="card">
<div class="card-content">
<h2 class="subtitle">Average Execution Time</h2>
<rails-performance-chart id="response_time_report_chart" type="RT" legend="Response Time" class="chart">
<%= raw @response_time_report_data.to_json %>
</rails-performance-chart>
<p class="content is-small">All workers in the application</p>
</div>
</div>

<br/>

<div class="card">
<div class="card-content">
<h2 class="subtitle">Recent Jobs (last <%= RailsPerformance.recent_requests_time_window / 60 %> minutes)<h2>

<table class="table is-fullwidth is-hoverable is-narrow">
<thead>
<tr>
<th data-sort="string">Datetime</th>
<th data-sort="string">Job ID</th>
<th data-sort="string">Queue</th>
<th data-sort="string">Worker</th>
<th data-sort="string">Status</th>
<th data-sort="float">Duration</th>
</tr>
</thead>
<tbody>
<% if @recent_report_data.empty? %>
<tr>
<td colspan="10">Nothing to show here. Try to make a few requests in the main app.</td>
</tr>
<% end %>
<% @recent_report_data.each do |e| %>
<tr>
<td><%= format_datetime e[:datetime] %></td>
<td><%= e[:jid] %></td>
<td><%= e[:queue] %></td>
<td><%= e[:worker] %></td>
<td>
<%= status_tag e[:status] %>
</td>
<td class="nowrap">
<%= ms e[:duration], 1 %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/rails_performance/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<% end %>
<%= link_to 'Slow Requests', rails_performance.rails_performance_slow_url, class: "navbar-item #{active?(:slow)}" %>
<%= link_to '500 Errors', rails_performance.rails_performance_crashes_url, class: "navbar-item #{active?(:crashes)}" %>
<% if defined?(::ActiveJob) %>
<%= link_to 'ActiveJob', rails_performance.rails_performance_jobs_url, class: "navbar-item #{active?(:jobs)}" %>
<% end %>
<% if defined?(Sidekiq) %>
<%= link_to 'Sidekiq', rails_performance.rails_performance_sidekiq_url, class: "navbar-item #{active?(:sidekiq)}" %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get "/rake" => "rails_performance#rake", :as => :rails_performance_rake
get "/custom" => "rails_performance#custom", :as => :rails_performance_custom
get "/resources" => "rails_performance#resources", :as => :rails_performance_resources
get "/jobs" => "rails_performance#jobs", :as => :rails_performance_jobs
end

Rails.application.routes.draw do
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "debug"
gem "sqlite3"
gem "simplecov", require: false, group: :test
gem "sidekiq"
gem "solid_queue"
gem "grape"
gem "mimemagic", "0.4.3"
gem "delayed_job_active_record"
Expand Down
16 changes: 15 additions & 1 deletion gemfiles/rails_7.2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rails_performance (1.6.0)
rails_performance (1.7.0.beta1)
browser
railties
redis
Expand Down Expand Up @@ -139,6 +139,8 @@ GEM
zeitwerk (~> 2.6)
erb (6.0.1)
erubi (1.13.1)
et-orbi (1.4.0)
tzinfo
ffi (1.17.3-aarch64-linux-gnu)
ffi (1.17.3-aarch64-linux-musl)
ffi (1.17.3-arm-linux-gnu)
Expand All @@ -147,6 +149,9 @@ GEM
ffi (1.17.3-x86_64-darwin)
ffi (1.17.3-x86_64-linux-gnu)
ffi (1.17.3-x86_64-linux-musl)
fugit (1.12.1)
et-orbi (~> 1.4)
raabro (~> 1.4)
get_process_mem (1.0.0)
bigdecimal (>= 2.0)
ffi (~> 1.0)
Expand Down Expand Up @@ -230,6 +235,7 @@ GEM
stringio
puma (7.1.0)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.2.4)
rack-session (2.1.1)
Expand Down Expand Up @@ -319,6 +325,13 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
solid_queue (1.3.0)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11)
railties (>= 7.1)
thor (>= 1.3.1)
sprockets (4.2.2)
concurrent-ruby (~> 1.0)
logger
Expand Down Expand Up @@ -402,6 +415,7 @@ DEPENDENCIES
rails_performance!
sidekiq
simplecov
solid_queue
sprockets-rails
sqlite3
standard
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_8.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "debug"
gem "sqlite3"
gem "simplecov", require: false, group: :test
gem "sidekiq"
gem "solid_queue"
gem "grape"
gem "mimemagic", "0.4.3"
gem "delayed_job_active_record"
Expand Down
16 changes: 15 additions & 1 deletion gemfiles/rails_8.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rails_performance (1.6.0)
rails_performance (1.7.0.beta1)
browser
railties
redis
Expand Down Expand Up @@ -136,6 +136,8 @@ GEM
zeitwerk (~> 2.6)
erb (6.0.1)
erubi (1.13.1)
et-orbi (1.4.0)
tzinfo
ffi (1.17.3-aarch64-linux-gnu)
ffi (1.17.3-aarch64-linux-musl)
ffi (1.17.3-arm-linux-gnu)
Expand All @@ -144,6 +146,9 @@ GEM
ffi (1.17.3-x86_64-darwin)
ffi (1.17.3-x86_64-linux-gnu)
ffi (1.17.3-x86_64-linux-musl)
fugit (1.12.1)
et-orbi (~> 1.4)
raabro (~> 1.4)
get_process_mem (1.0.0)
bigdecimal (>= 2.0)
ffi (~> 1.0)
Expand Down Expand Up @@ -227,6 +232,7 @@ GEM
stringio
puma (7.1.0)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.2.4)
rack-session (2.1.1)
Expand Down Expand Up @@ -315,6 +321,13 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
solid_queue (1.3.0)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11)
railties (>= 7.1)
thor (>= 1.3.1)
sprockets (4.2.2)
concurrent-ruby (~> 1.0)
logger
Expand Down Expand Up @@ -399,6 +412,7 @@ DEPENDENCIES
rails_performance!
sidekiq
simplecov
solid_queue
sprockets-rails
sqlite3
standard
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_8.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "debug"
gem "sqlite3"
gem "simplecov", require: false, group: :test
gem "sidekiq"
gem "solid_queue"
gem "grape"
gem "mimemagic", "0.4.3"
gem "delayed_job_active_record"
Expand Down
Loading