File tree Expand file tree Collapse file tree 8 files changed +127
-1
lines changed Expand file tree Collapse file tree 8 files changed +127
-1
lines changed Original file line number Diff line number Diff line change
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
+ concurrency :
13
+ group : ${{ github.head_ref || github.sha }}-${{ github.workflow }}
14
+ cancel-in-progress : true
15
+
16
+ jobs :
17
+ test :
18
+ runs-on : ${{ matrix.os }}
19
+ continue-on-error : false
20
+ strategy :
21
+ fail-fast : false
22
+ matrix :
23
+ os : ['ubuntu-latest', 'macos-latest', 'windows-latest']
24
+ ruby-version : ['3.4']
25
+
26
+ name : Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
27
+ steps :
28
+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29
+ - name : Set up Ruby
30
+ uses : ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
31
+ with :
32
+ ruby-version : ${{ matrix.ruby-version }}
33
+ - name : Install dependencies
34
+ run : bundle install
35
+ - name : Run Benchmark
36
+ shell : bash # Ensure to use bash shell on all platforms
37
+ run : |
38
+ bundle exec rake benchmark:run:in_tail | tee -a $GITHUB_STEP_SUMMARY
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ fluent-cat
16
16
fluent-gem
17
17
fluentd
18
18
pkg /*
19
+ tmp /*
19
20
test /tmp /*
20
21
test /config /tmp /*
21
22
make_dist.sh
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ source 'https://rubygems.org/'
2
2
3
3
gemspec
4
4
5
+ gem 'benchmark'
6
+
5
7
local_gemfile = File . join ( File . dirname ( __FILE__ ) , "Gemfile.local" )
6
8
if File . exist? ( local_gemfile )
7
9
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ require 'fileutils'
5
5
require 'rake/testtask'
6
6
require 'rake/clean'
7
7
8
+ require_relative 'tasks/benchmark'
9
+
8
10
task test : [ :base_test ]
9
11
10
12
# 1. update ChangeLog and lib/fluent/version.rb
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
gem . files = Dir . chdir ( __dir__ ) do
14
14
`git ls-files -z` . split ( "\x0 " ) . reject do |f |
15
15
( File . expand_path ( f ) == __FILE__ ) ||
16
- f . start_with? ( *%w[ test/ .git Gemfile ] )
16
+ f . start_with? ( *%w[ tasks/ test/ .git Gemfile ] )
17
17
end
18
18
end
19
19
gem . executables = gem . files . grep ( %r{^bin/} ) . map { |f | File . basename ( f ) }
Original file line number Diff line number Diff line change
1
+ require "json"
2
+ require "fileutils"
3
+
4
+ BENCHMARK_FILE_SIZE = 1 * 1024 * 1024 * 1024
5
+ BENCHMARK_FILE_PATH = File . expand_path ( "./tmp/benchmark/data.log" )
6
+
7
+ namespace :benchmark do
8
+ task :init do
9
+ # Synchronize stdout because the output order is not as intended on Windows environment
10
+ STDOUT . sync = true
11
+ end
12
+
13
+ task :prepare_1GB do
14
+ FileUtils . mkdir_p ( File . dirname ( BENCHMARK_FILE_PATH ) )
15
+ File . open ( BENCHMARK_FILE_PATH , "w" ) do |f |
16
+ data = { "message" : "a" * 1024 } . to_json
17
+
18
+ loop do
19
+ f . puts data
20
+ break if File . size ( BENCHMARK_FILE_PATH ) > BENCHMARK_FILE_SIZE
21
+ end
22
+ end
23
+ end
24
+
25
+ task :show_info do
26
+ # Output the information with markdown format
27
+ puts "### Environment"
28
+ puts "```"
29
+ system "bundle exec ruby --version"
30
+ system "bundle exec ruby bin/fluentd --version"
31
+ puts "```\n "
32
+ end
33
+
34
+ desc "Run in_tail benchmark"
35
+ task :"run:in_tail" => [ :init , :prepare_1GB , :show_info ] do
36
+ # Output the results with markdown format
37
+ puts "### in_tail with 1 GB file"
38
+ puts "```"
39
+ 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"
40
+ puts "```"
41
+
42
+ Rake ::Task [ "benchmark:clean" ] . invoke
43
+ end
44
+
45
+ task :clean do
46
+ FileUtils . rm_rf ( File . dirname ( BENCHMARK_FILE_PATH ) )
47
+ end
48
+ end
Original file line number Diff line number Diff line change
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>
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments