Skip to content

Commit

Permalink
freshen ruby + add lint to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Mar 8, 2024
1 parent e6f543d commit 4fd3e6f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Rubocop

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
- name: Run rubocop
run: |
gem install rubocop --no-document --version 1.60.1
rubocop
2 changes: 1 addition & 1 deletion analyze.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ echo "Benchmark finished. Detailed results are located in: ${RESULTS_DIR}"
docker run --name analyzer --rm \
-v "${PWD}/analyze:/analyze:ro" \
-v "${PWD}/${RESULTS_DIR}:/reports:ro" \
ruby:2.7-slim-buster ruby /analyze/results_analyze.rb reports ||
ruby:3-slim-buster ruby /analyze/results_analyze.rb reports ||
exit 1

cat > ${RESULTS_DIR}/bench.params << EOF
Expand Down
31 changes: 13 additions & 18 deletions analyze/results_analyze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,25 @@

results = Hash.new { |hash, key| hash[key] = {} }
Dir.glob("#{report_directory}/*.report").each do |file|
begin
name = File.basename(file).split(/_bench.report/).first
results[name][:total_time] = File.read(file).scan(/Total:\s*((?:\d|\.)+)/)[0][0].to_f
results[name][:ok_responses] = begin
File.read(file).scan(/\[OK\]\s*(\d+)/)[0][0].to_f
rescue StandardError
0
end
results[name][:avg_resp_time] = File.read(file).scan(/\s*Average:\s*(.*\w)/)[0][0]
results[name][:_90pct] = File.read(file).scan(/\s*90 % in \s*(.*\w)/)[0][0]
results[name][:_95pct] = File.read(file).scan(/\s*95 % in \s*(.*\w)/)[0][0]
results[name][:_99pct] = File.read(file).scan(/\s*99 % in \s*(.*\w)/)[0][0]
results[name][:req_per_s] = results[name][:ok_responses] / results[name][:total_time]
name = File.basename(file).split(/_bench.report/).first
results[name][:total_time] = File.read(file).scan(/Total:\s*((?:\d|\.)+)/)[0][0].to_f
results[name][:ok_responses] = begin
File.read(file).scan(/\[OK\]\s*(\d+)/)[0][0].to_f
rescue StandardError
puts "Failed miserably analysing #{name}."
raise
0
end
results[name][:avg_resp_time] = File.read(file).scan(/\s*Average:\s*(.*\w)/)[0][0]
results[name][:_90pct] = File.read(file).scan(/\s*90 % in \s*(.*\w)/)[0][0]
results[name][:_95pct] = File.read(file).scan(/\s*95 % in \s*(.*\w)/)[0][0]
results[name][:_99pct] = File.read(file).scan(/\s*99 % in \s*(.*\w)/)[0][0]
results[name][:req_per_s] = results[name][:ok_responses] / results[name][:total_time]
end

Dir.glob("#{report_directory}/*.stats").each do |file|
name = File.basename(file).split(/_bench.stats/).first
stats = File
.read(file)
.scan(/([0-9\.]+)%\s+([0-9\.]+)(\w+)/)[0..-2] # ignore the last sample, not very reliable
.scan(/([0-9.]+)%\s+([0-9.]+)(\w+)/)[0..-2] # ignore the last sample, not very reliable
.map { |cpu, memory, mem_unit| [cpu.to_f, memory.to_f * (mem_unit == 'GiB' ? 1024 : 1)] }
.reject { |cpu, _mem| cpu < 1 }
.transpose
Expand Down Expand Up @@ -74,7 +69,7 @@
result[:_90pct],
result[:_95pct],
result[:_99pct],
result[:avg_cpu].round(2).to_s + '%',
result[:avg_mem].round(2).to_s + ' ' + result[:avg_mem_unit]]
"#{result[:avg_cpu].round(2)}%",
"#{result[:avg_mem].round(2)} #{result[:avg_mem_unit]}"]
end
make_horizontal_line[]
4 changes: 2 additions & 2 deletions ruby_grpc_bench/server.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Copyright 2015 gRPC authors.
#
Expand All @@ -18,7 +18,7 @@
#
# Usage: $ path/to/greeter_server.rb

this_dir = File.expand_path(File.dirname(__FILE__))
this_dir = File.expand_path(__dir__)
lib_dir = File.join(this_dir, 'lib')
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)

Expand Down

0 comments on commit 4fd3e6f

Please sign in to comment.