Skip to content
Merged
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
38 changes: 38 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Benchmark

on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

permissions: read-all

concurrency:
group: ${{ github.head_ref || github.sha }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
continue-on-error: false
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
ruby-version: ['3.4']

name: Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Ruby
uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Install dependencies
run: bundle install
- name: Run Benchmark
shell: bash # Ensure to use bash shell on all platforms
run: |
bundle exec rake benchmark:run:in_tail | tee -a $GITHUB_STEP_SUMMARY
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fluent-cat
fluent-gem
fluentd
pkg/*
tmp/*
test/tmp/*
test/config/tmp/*
make_dist.sh
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source 'https://rubygems.org/'

gemspec

gem 'benchmark'

local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
if File.exist?(local_gemfile)
puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require 'fileutils'
require 'rake/testtask'
require 'rake/clean'

require_relative 'tasks/benchmark'

task test: [:base_test]

# 1. update ChangeLog and lib/fluent/version.rb
Expand Down
2 changes: 1 addition & 1 deletion fluentd.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
gem.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
(File.expand_path(f) == __FILE__) ||
f.start_with?(*%w[test/ .git Gemfile])
f.start_with?(*%w[tasks/ test/ .git Gemfile])
end
end
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
Expand Down
48 changes: 48 additions & 0 deletions tasks/benchmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "json"
require "fileutils"

BENCHMARK_FILE_SIZE = 1 * 1024 * 1024 * 1024
BENCHMARK_FILE_PATH = File.expand_path("./tmp/benchmark/data.log")

namespace :benchmark do
task :init do
# Synchronize stdout because the output order is not as intended on Windows environment
STDOUT.sync = true
end

task :prepare_1GB do
FileUtils.mkdir_p(File.dirname(BENCHMARK_FILE_PATH))
File.open(BENCHMARK_FILE_PATH, "w") do |f|
data = { "message": "a" * 1024 }.to_json

loop do
f.puts data
break if File.size(BENCHMARK_FILE_PATH) > BENCHMARK_FILE_SIZE
end
end
end

task :show_info do
# Output the information with markdown format
puts "### Environment"
puts "```"
system "bundle exec ruby --version"
system "bundle exec ruby bin/fluentd --version"
puts "```\n"
end

desc "Run in_tail benchmark"
task :"run:in_tail" => [:init, :prepare_1GB, :show_info] do
# Output the results with markdown format
puts "### in_tail with 1 GB file"
puts "```"
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"
puts "```"

Rake::Task["benchmark:clean"].invoke
end

task :clean do
FileUtils.rm_rf(File.dirname(BENCHMARK_FILE_PATH))
end
end
14 changes: 14 additions & 0 deletions tasks/benchmark/conf/in_tail.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<source>
@type tail
tag benchmark
path "#{File.expand_path './tmp/benchmark/data.log'}"
read_from_head true
<parse>
@type json
</parse>
</source>

<match **>
@type file
path "#{File.expand_path './tmp/benchmark/in_tail'}"
</match>
21 changes: 21 additions & 0 deletions tasks/benchmark/patch_in_tail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'benchmark'
require 'fluent/plugin/in_tail'

class Fluent::Plugin::TailInput::TailWatcher::IOHandler
alias_method :original_with_io, :with_io

def with_io(&block)
@benchmark_measured_in_tail ||= false
# Measure the benchmark only once.
return original_with_io(&block) if @benchmark_measured_in_tail

Benchmark.bm do |x|
x.report {
original_with_io(&block)
@benchmark_measured_in_tail = true
}
end

exit 0
end
end