Skip to content

root_agent: system_config: Handle maxstdio parameter to increase limit of opening files at once #4960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions lib/fluent/command/fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
cmd_opts[:enable_size_metrics] = b
}

op.on('--maxstdio NUMBER', "specify maxstdio number for increasing the number of opening files at once") {|s|
cmd_opts[:maxstdio] = s.to_i
}

op.on('-v', '--verbose', "increase verbose level (-v: debug, -vv: trace)", TrueClass) {|b|
return unless b
cur_level = cmd_opts.fetch(:log_level, default_opts[:log_level])
Expand Down
1 change: 1 addition & 0 deletions lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def initialize(log:, system_config: SystemConfig.new, start_in_parallel: false)
@source_only_mode = SourceOnlyMode.new(system_config.with_source_only, start_in_parallel)
@source_only_buffer_agent = nil
@enable_input_metrics = system_config.enable_input_metrics || false
@maxstdio = system_config.maxstdio

suppress_interval(system_config.emit_error_log_interval) unless system_config.emit_error_log_interval.nil?
end
Expand Down
11 changes: 11 additions & 0 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ def self.default_options
conf_encoding: 'utf-8',
disable_shared_socket: nil,
config_file_type: :guess,
maxstdio: nil,
}
end

Expand Down Expand Up @@ -681,6 +682,7 @@ def initialize(cl_opt)
@log_path = opt[:log_path]
@log_rotate_age = opt[:log_rotate_age]
@log_rotate_size = opt[:log_rotate_size]
@maxstdio = opt[:maxstdio]

@finished = false
end
Expand Down Expand Up @@ -754,6 +756,14 @@ def options
}
end

def setup_maxstdio
if Fluent.windows?
require "fluent/win32api"
Win32API._setmaxstdio(@maxstdio)
$log.debug "Current maxstdio is #{Win32API._getmaxstdio}"
end
end

def run_worker
Process.setproctitle("worker:#{@system_config.process_name}") if @process_name

Expand All @@ -766,6 +776,7 @@ def run_worker
end

install_main_process_signal_handlers
setup_maxstdio

# This is the only log messsage for @standalone_worker
$log.info "starting fluentd-#{Fluent::VERSION} without supervision", pid: Process.pid, ruby: RUBY_VERSION if @standalone_worker
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SystemConfig
:file_permission, :dir_permission, :counter_server, :counter_client,
:strict_config_value, :enable_msgpack_time_support, :disable_shared_socket,
:metrics, :enable_input_metrics, :enable_size_metrics, :enable_jit, :source_only_buffer,
:config_include_dir
:config_include_dir, :maxstdio
]

config_param :workers, :integer, default: 1
Expand Down Expand Up @@ -61,6 +61,7 @@ class SystemConfig
v.to_i(8)
end
config_param :config_include_dir, default: Fluent::DEFAULT_CONFIG_INCLUDE_DIR
config_param :maxstdio, :integer, default: nil
config_section :log, required: false, init: true, multi: false do
config_param :path, :string, default: nil
config_param :format, :enum, list: [:text, :json], default: :text
Expand Down
2 changes: 2 additions & 0 deletions lib/fluent/win32api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ module Win32API
extern "intptr_t _get_osfhandle(int)"
extern "BOOL GetFileInformationByHandle(HANDLE, void *)"
extern "BOOL GetFileInformationByHandleEx(HANDLE, int, void *, DWORD)"
extern 'int _setmaxstdio(int)'
extern 'int _getmaxstdio(void)'
end if Fluent.windows?
end
2 changes: 2 additions & 0 deletions test/config/test_system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def parse_text(text)
assert_nil(sc.enable_msgpack_time_support)
assert(!sc.enable_jit)
assert_nil(sc.log.path)
assert_nil(sc.maxstdio)
assert_equal(:text, sc.log.format)
assert_equal('%Y-%m-%d %H:%M:%S %z', sc.log.time_format)
end
Expand All @@ -100,6 +101,7 @@ def parse_text(text)
'enable_input_metrics' => ['enable_input_metrics', true],
'enable_size_metrics' => ['enable_size_metrics', true],
'enable_jit' => ['enable_jit', true],
'maxstdio' => ['maxstdio', 768],
)
test "accepts parameters" do |(k, v)|
conf = parse_text(<<-EOS)
Expand Down
26 changes: 26 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,32 @@
end
end

data("Default", {})
data("Small", {maxstdio: 100})
data("Large", {maxstdio: 3000})
data("Very large", {maxstdio: 10000})
def test_maxstdio(cl_opt)
# TODO assert

omit "maxstdio is only for Windows" unless Fluent.windows?

supervisor = Fluent::Supervisor.new(cl_opt)
supervisor.setup_maxstdio

Check failure on line 1173 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.3 on windows-latest

Error

TypeError: no implicit conversion from nil to integer D:/a/fluentd/fluentd/lib/fluent/win32api.rb:38:in `call' D:/a/fluentd/fluentd/lib/fluent/win32api.rb:38:in `_setmaxstdio' D:/a/fluentd/fluentd/lib/fluent/supervisor.rb:762:in `setup_maxstdio' D:/a/fluentd/fluentd/test/test_supervisor.rb:1173:in `test_maxstdio'

Check failure on line 1173 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.4 on windows-latest

Error

TypeError: no implicit conversion from nil to integer D:/a/fluentd/fluentd/lib/fluent/win32api.rb:38:in 'Fiddle::Function#call' D:/a/fluentd/fluentd/lib/fluent/win32api.rb:38:in 'Fluent::Win32API._setmaxstdio' D:/a/fluentd/fluentd/lib/fluent/supervisor.rb:762:in 'Fluent::Supervisor#setup_maxstdio' D:/a/fluentd/fluentd/test/test_supervisor.rb:1173:in 'SupervisorTest#test_maxstdio'

Check failure on line 1173 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.2 on windows-latest

Error

TypeError: no implicit conversion from nil to integer D:/a/fluentd/fluentd/lib/fluent/win32api.rb:38:in `call' D:/a/fluentd/fluentd/lib/fluent/win32api.rb:38:in `_setmaxstdio' D:/a/fluentd/fluentd/lib/fluent/supervisor.rb:762:in `setup_maxstdio' D:/a/fluentd/fluentd/test/test_supervisor.rb:1173:in `test_maxstdio'

files = []
begin
10000.times do |i|
file = File.open(File.join(@tmp_dir, "#{i}.txt"), "w")

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.3 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/c0cb461ded1cd871597c/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `block in test_maxstdio' <internal:numeric>:237:in `times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.3 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/154259d261e726b4b2ed/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `block in test_maxstdio' <internal:numeric>:237:in `times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.3 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/87f2e97d39ff7cb9da93/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `block in test_maxstdio' <internal:numeric>:237:in `times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.4 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/15e918c69dc355128a4d/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'File#initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'IO.open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'block in SupervisorTest#test_maxstdio' <internal:numeric>:257:in 'Integer#times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in 'SupervisorTest#test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.4 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/22ae349c33fd68382ba8/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'File#initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'IO.open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'block in SupervisorTest#test_maxstdio' <internal:numeric>:257:in 'Integer#times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in 'SupervisorTest#test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.4 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/2f3f767ab4b4d5ac6585/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'File#initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'IO.open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in 'block in SupervisorTest#test_maxstdio' <internal:numeric>:257:in 'Integer#times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in 'SupervisorTest#test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.2 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/450e4b9baa58a6b8d10d/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `block in test_maxstdio' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.2 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/fd67183b9888d2f28169/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `block in test_maxstdio' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `test_maxstdio'

Check failure on line 1178 in test/test_supervisor.rb

View workflow job for this annotation

GitHub Actions / Ruby 3.2 on windows-latest

Error

Errno::EMFILE: Too many open files @ rb_sysopen - D:/a/fluentd/fluentd/test/tmp/supervisor/0b354ff58ce6f24a9dbd/8131.txt D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `initialize' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `open' D:/a/fluentd/fluentd/test/test_supervisor.rb:1178:in `block in test_maxstdio' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `times' D:/a/fluentd/fluentd/test/test_supervisor.rb:1177:in `test_maxstdio'
files.append(file)
end
ensure
puts files.length
files.each do |file|
file.close
end
end
end

def create_debug_dummy_logger
dl_opts = {}
dl_opts[:log_level] = ServerEngine::DaemonLogger::DEBUG
Expand Down
Loading