Skip to content
Snippets Groups Projects
Commit 4847251d authored by Paco Guzman's avatar Paco Guzman
Browse files

Highest Throughput and Most Time consuming transaction scripts

Using already downsampled data
parent b61e6797
No related branches found
No related tags found
1 merge request!1Highest Throughput and Most Time consuming transaction scripts
Loading
Loading
@@ -18,6 +18,24 @@ Run a script of choice:
 
INFLUXDB_USER=alice INFLUXDB_PASSWORD=hunter2 ruby lib/SCRIPT.rb
 
## Scripts
* `common_methods.rb`
- This script calculates the minimum, maximum and 95th percentile of methods called
by more than 10% of all Rails actions taking place in the past 24 hours. The idea
of this script is to find commonly used slow methods.
* `app_transactions/highest_throughput.rb`
- This script calculates the actions with highest throughput in the past 24 hours.
* `app_transactions/most_time_consuming.rb`
- This script calculates the most time consuming actions in the past 24 hours.
The idea of this scripts is to find most resource consuming actions.
## License
 
All source code in this repository is subject to the terms of the MIT license,
Loading
Loading
# This script calculates the actions with highest throughput in the past 24
# hours.
require_relative '../config'
HOURS = (ENV.fetch('INTERVAL') { 24 }).to_i
rows = CLIENT.query(<<-SQL
SELECT sum("count") AS count
FROM "downsampled"./(grape|rails)_transaction_counts_per_action/
WHERE time > NOW() - #{HOURS}h
GROUP BY "action";
SQL
)
counts_per_action = Hash.new do |hash, key|
hash[key] = 0
end
rows.each do |row|
next unless row['tags'] && row['tags']['action']
action = row['tags']['action']
count = row['values'][0]['count']
counts_per_action[action] += count
end
rows = []
counts_per_action = Hash[counts_per_action.sort_by { |_key, value| - value }]
counts_per_action.each do |action, counts|
rows << [action, counts, (counts.to_f / (HOURS * 60)).to_i]
end
longest = rows.map { |row| row[0].length }.sort.last
headers = [
'Action'.ljust(longest, ' '),
'Calls',
'Throughput rpm'
]
puts headers.join(' ')
rows.each do |columns|
cells = columns.map.with_index do |col, index|
padding = headers[index].length
col.to_s.ljust(padding, ' ')
end
puts cells.join(' ')
end
# This script calculates the most time consuming actions in the past 24
# hours. The idea of this scripts is to find most resource consuming actions.
require_relative '../config'
HOURS = (ENV.fetch('INTERVAL') { 24 }).to_i
rows = CLIENT.query(<<-SQL
SELECT sum("duration_sum")
FROM "downsampled"./(grape|rails)_transaction_timings_per_action/
WHERE time > NOW() - #{HOURS}h
GROUP BY "action";
SQL
)
durations_per_action = Hash.new do |hash, key|
hash[key] = 0
end
total_durations = 0.0
rows.each do |row|
next unless row['tags'] && row['tags']['action']
action = row['tags']['action']
duration = row['values'][0]['sum']
durations_per_action[action] += duration
total_durations += duration
end
rows = []
durations_per_action = Hash[durations_per_action.sort_by { |_key, value| - value }]
durations_per_action.each do |action, duration|
percentage = (duration / total_durations) * 100
rows << [action, "%.2f" % percentage + "%", duration.to_i]
end
longest = rows.map { |row| row[0].length }.sort.last
headers = [
'Action'.ljust(longest, ' '),
'Percentage',
'Total (s)'
]
puts headers.join(' ')
rows.each do |columns|
cells = columns.map.with_index do |col, index|
padding = headers[index].length
col.to_s.ljust(padding, ' ')
end
puts cells.join(' ')
end
Loading
Loading
@@ -2,10 +2,12 @@ require 'influxdb'
 
user = ENV.fetch('INFLUXDB_USER')
pass = ENV.fetch('INFLUXDB_PASSWORD')
host = ENV.fetch('INFLUXDB_HOST') { 'performance.gitlab.net' }
db = ENV.fetch('INFLUXDB') { 'gitlab' }
 
CLIENT = InfluxDB::Client.new(
host: 'yorick-influxdb.gitlap.com',
database: 'gitlab',
host: host,
database: db,
username: user,
password: pass
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment