diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ba608baafc..9880102ec2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: uses: ruby/actions/.github/workflows/ruby_versions.yml@master with: engine: cruby - min_version: 3.2 + min_version: 3.3 test: needs: ruby-versions runs-on: ${{ matrix.os }} @@ -38,8 +38,6 @@ jobs: - ruby-version: head - os: 'windows-11-arm' ruby-version: '3.3' - - os: 'windows-11-arm' - ruby-version: '3.2' env: RUBYOPT: "--disable-frozen_string_literal" name: Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }} diff --git a/README.md b/README.md index 0b092a89e5..43d5bbca83 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Fluentd: Open-Source Log Collector ### Prerequisites -- Ruby 3.2 or later +- Ruby 3.3 or later - git `git` should be in `PATH`. On Windows, you can use `Github for Windows` and `GitShell` for easy setup. diff --git a/fluentd.gemspec b/fluentd.gemspec index 50ed369766..74a09c207d 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |gem| gem.metadata["changelog_uri"] = "https://github.com/fluent/fluentd/blob/master/CHANGELOG.md" gem.metadata["bug_tracker_uri"] = "https://github.com/fluent/fluentd/issues" - gem.required_ruby_version = '>= 3.2' + gem.required_ruby_version = '>= 3.3' gem.add_runtime_dependency("bundler") gem.add_runtime_dependency("msgpack", [">= 1.3.1", "< 2.0.0"]) diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index b76a4dda1c..bb09cf35a9 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -780,6 +780,7 @@ def run_worker MessagePackFactory.init(enable_time_support: @system_config.enable_msgpack_time_support) Fluent::Engine.init(@system_config, start_in_parallel: ENV.key?("FLUENT_RUNNING_IN_PARALLEL_WITH_OLD")) Fluent::Engine.run_configure(@conf) + enable_ruby_jit if @system_config.enable_jit Fluent::Engine.run self.class.cleanup_socketmanager_path if @standalone_worker exit 0 @@ -1214,6 +1215,19 @@ def main_process(&block) exit!(unrecoverable_error ? 2 : 1) end + def enable_ruby_jit + unless defined?(RubyVM::YJIT) && RubyVM::YJIT.respond_to?(:enable) + $log.info "Ruby JIT is not available on this Ruby" + return + end + + if RubyVM::YJIT.enable + $log.info "enabled Ruby JIT" + else + $log.warn "failed to enable Ruby JIT" + end + end + def build_system_config(conf) system_config = SystemConfig.create(conf, @cl_opt[:strict_config_value]) # Prefer the options explicitly specified in the command line @@ -1281,11 +1295,6 @@ def build_spawn_command fluentd_spawn_cmd << '-Eascii-8bit:ascii-8bit' end - if @system_config.enable_jit - $log.info "enable Ruby JIT for workers (--jit)" - fluentd_spawn_cmd << '--jit' - end - # Adding `-h` so that it can avoid ruby's command blocking # e.g. `ruby -Eascii-8bit:ascii-8bit` will block. but `ruby -Eascii-8bit:ascii-8bit -h` won't. _, e, s = Open3.capture3(*fluentd_spawn_cmd, "-h") diff --git a/lib/fluent/system_config.rb b/lib/fluent/system_config.rb index 2d9240b087..f55f06a3f0 100644 --- a/lib/fluent/system_config.rb +++ b/lib/fluent/system_config.rb @@ -53,7 +53,7 @@ class SystemConfig config_param :disable_shared_socket, :bool, default: nil config_param :enable_input_metrics, :bool, default: true config_param :enable_size_metrics, :bool, default: nil - config_param :enable_jit, :bool, default: false + config_param :enable_jit, :bool, default: true config_param :file_permission, default: nil do |v| v.to_i(8) end diff --git a/test/config/test_system_config.rb b/test/config/test_system_config.rb index a18cb693aa..a884ea12ab 100644 --- a/test/config/test_system_config.rb +++ b/test/config/test_system_config.rb @@ -78,7 +78,7 @@ def parse_text(text) assert_true(sc.enable_input_metrics) assert_nil(sc.enable_size_metrics) assert_nil(sc.enable_msgpack_time_support) - assert(!sc.enable_jit) + assert(sc.enable_jit) assert_nil(sc.log.path) assert_equal(:text, sc.log.format) assert_equal('%Y-%m-%d %H:%M:%S %z', sc.log.time_format) @@ -100,7 +100,7 @@ def parse_text(text) 'enable_msgpack_time_support' => ['enable_msgpack_time_support', true], 'enable_input_metrics' => ['enable_input_metrics', false], 'enable_size_metrics' => ['enable_size_metrics', true], - 'enable_jit' => ['enable_jit', true], + 'enable_jit' => ['enable_jit', false], 'umask' => ['umask', '0022'], ) test "accepts parameters" do |(k, v)| diff --git a/test/test_supervisor.rb b/test/test_supervisor.rb index 3f90b9d6f7..2da25d2b68 100644 --- a/test/test_supervisor.rb +++ b/test/test_supervisor.rb @@ -957,6 +957,52 @@ def server.config end end + sub_test_case "enable_jit" do + setup do + omit "YJIT is not supported on Windows, and RubyVM::YJIT is not defined either" if Fluent.windows? + end + + def create_worker(enable_jit) + sv = Fluent::Supervisor.new({}) + conf = Fluent::Config::Element.new( + 'ROOT', '', {}, [Fluent::Config::Element.new('system', '', { 'enable_jit' => enable_jit.to_s }, [])] + ) + sv.instance_variable_set(:@system_config, sv.__send__(:build_system_config, conf)) + sv.instance_variable_set(:@conf, conf) + sv + end + + data("enabled" => [true, 1], + "disabled" => [false, 0]) + def test_run_worker((enable_jit, expected_count)) + sv = create_worker(enable_jit) + + stub(sv).install_main_process_signal_handlers + stub(Fluent::MessagePackFactory).init + stub(Fluent::Engine).init + stub(Fluent::Engine).run_configure + stub(Fluent::Engine).run + + enable_count = 0 + stub(RubyVM::YJIT).enable { enable_count += 1; true } + + assert_raise(SystemExit) { sv.run_worker } + assert_equal(expected_count, enable_count) + end + + data("succeeded" => [true, "enabled Ruby JIT"], + "failed" => [false, "failed to enable Ruby JIT"]) + def test_log_result((result, expected_message)) + sv = create_worker(true) + create_info_dummy_logger + + mock(RubyVM::YJIT).enable { result } + sv.__send__(:enable_ruby_jit) + + assert { $log.out.logs.any? { |log| log.include?(expected_message) } } + end + end + sub_test_case "zero_downtime_restart" do setup do omit "Not supported on Windows" if Fluent.windows?