Skip to content

Commit 09f0a4b

Browse files
committed
Add benchmark scripts
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent f2d5a55 commit 09f0a4b

8 files changed

Lines changed: 116 additions & 1 deletion

File tree

.github/workflows/benchmark.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Benchmark
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
workflow_dispatch:
9+
10+
permissions: read-all
11+
12+
jobs:
13+
test:
14+
runs-on: ${{ matrix.os }}
15+
continue-on-error: false
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
20+
ruby-version: ['3.4', '3.3', '3.2']
21+
22+
name: Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
23+
steps:
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
- name: Set up Ruby
26+
uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
27+
with:
28+
ruby-version: ${{ matrix.ruby-version }}
29+
- name: Install dependencies
30+
run: bundle install
31+
- name: Run Benchmark
32+
run: |
33+
bundle exec rake benchmark:run:in_tail

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fluent-cat
1616
fluent-gem
1717
fluentd
1818
pkg/*
19+
tmp/*
1920
test/tmp/*
2021
test/config/tmp/*
2122
make_dist.sh

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ source 'https://rubygems.org/'
22

33
gemspec
44

5+
gem 'benchmark'
6+
57
local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
68
if File.exist?(local_gemfile)
79
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ require 'fileutils'
55
require 'rake/testtask'
66
require 'rake/clean'
77

8+
require_relative 'tasks/benchmark'
9+
810
task test: [:base_test]
911

1012
# 1. update ChangeLog and lib/fluent/version.rb

fluentd.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
1313
gem.files = Dir.chdir(__dir__) do
1414
`git ls-files -z`.split("\x0").reject do |f|
1515
(File.expand_path(f) == __FILE__) ||
16-
f.start_with?(*%w[test/ .git Gemfile])
16+
f.start_with?(*%w[tasks/ test/ .git Gemfile])
1717
end
1818
end
1919
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }

tasks/benchmark.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require "json"
2+
require "fileutils"
3+
4+
namespace :benchmark do
5+
desc "Prepare benchmark data"
6+
task :prepare do
7+
FILE_SIZE = 1 * 1024 * 1024 * 1024
8+
FILE_PATH = File.expand_path "./tmp/benchmark/data.log"
9+
10+
unless File.exist?(FILE_PATH) && File.size(FILE_PATH) > FILE_SIZE
11+
FileUtils.mkdir_p(File.dirname(FILE_PATH))
12+
File.open(FILE_PATH, "w") do |f|
13+
data = { "message": "a" * 1024 }.to_json
14+
15+
loop do
16+
f.puts data
17+
break if File.size(FILE_PATH) > FILE_SIZE
18+
end
19+
end
20+
end
21+
end
22+
23+
desc "Run in_tail benchmark"
24+
task :"run:in_tail" => [:prepare, :show_environment] do
25+
puts "## in_tail with 1 GB file"
26+
27+
system "bundle exec ruby bin/fluentd -r ./tasks/benchmark/patch_in_tail.rb --no-supervisor -c ./tasks/benchmark/conf/in_tail.conf -o ./tmp/benchmark/fluent.log"
28+
29+
Rake::Task["benchmark:clean"].invoke
30+
end
31+
32+
task :show_environment do
33+
puts "## Environment"
34+
system "bundle exec ruby --version"
35+
system "bundle exec ruby bin/fluentd --version"
36+
puts ""
37+
end
38+
39+
task :clean do
40+
FileUtils.rm_rf "./tmp/benchmark"
41+
end
42+
end

tasks/benchmark/conf/in_tail.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<source>
2+
@type tail
3+
tag benchmark
4+
path "#{File.expand_path './tmp/benchmark/data.log'}"
5+
read_from_head true
6+
<parse>
7+
@type json
8+
</parse>
9+
</source>
10+
11+
<match **>
12+
@type file
13+
path "#{File.expand_path './tmp/benchmark/in_tail'}"
14+
</match>

tasks/benchmark/patch_in_tail.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'benchmark'
2+
require 'fluent/plugin/in_tail'
3+
4+
class Fluent::Plugin::TailInput::TailWatcher::IOHandler
5+
alias_method :original_with_io, :with_io
6+
7+
def with_io(&block)
8+
@benchmark_measured_in_tail ||= false
9+
# Measure the benchmark only once.
10+
return original_with_io(&block) if @benchmark_measured_in_tail
11+
12+
Benchmark.bm do |x|
13+
x.report {
14+
original_with_io(&block)
15+
@benchmark_measured_in_tail = true
16+
}
17+
end
18+
19+
exit 0
20+
end
21+
end

0 commit comments

Comments
 (0)