-
Notifications
You must be signed in to change notification settings - Fork 42
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
Slow service start with Ruby 3 #84
Comments
Is there any reason using CreateThread Win32 API to call StartServiceCtrlDispatcher? https://github.com/chef/win32-service/blob/win32-service-2.3.2/lib/win32/daemon.rb#L257 Is it related to GVL? |
Looks like this PR tries to fix the same problem. |
daipom
added a commit
to fluent-plugins-nursery/win32-service
that referenced
this issue
Feb 26, 2024
This does not change any specification. This just changes to use a Ruby thread instead of `CreateThread`. It is very very fast to use a Ruby thread from the beginning. Service startup is noticeably slower with Ruby 3. (Please see chef#84). Windows service needs to finish `StartServiceCtrlDispatcher` in 30 seconds by default. With Ruby 3 or later, this problem can cause timeout errors. The more CPUs, the slower it tends to be. Maybe some implementation about threading has changed with Ruby 3 series. The current implementation switches between multiple Ruby threads and non-Ruby threads. This complex process may be unsuitable for Ruby 3. `CreateThread` makes a non-Ruby thread, and it calls Ruby Proc, and it makes a Ruby thread, and ... Signed-off-by: Daijiro Fukuda <[email protected]>
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Service startup is noticeably slower with Ruby 3.
I'm talking about the time to reach the
Running
state. In other words, the time to finish StartServiceCtrlDispatcher.With Ruby 2, it takes about 5 seconds, but with Ruby 3, it can take more than 20 seconds.
The application implementation is irrelevant.
Windows service needs to finish StartServiceCtrlDispatcher in 30 seconds by default.
With Ruby 3 or later, this problem can cause timeout errors.
EventID 7000
EventID 7009
This problem occurs when both of the following conditions are met.
Gem Version
2.3.2
Windows Version
I confirm this problem in the following:
Replication Case
Here is a graph of the number of seconds to start a sample service for each Ruby version:
(I will explain
322 with patch
at the end)Measured using a minimum implementation service:
Environment:
Steps:
C:\test\run.rb
)Additional Information
Possible causes and solutions
Maybe the problem is on Ruby's side, but I think it could be avoided by implementation on this side.
In the current implementation, it switches between multiple Ruby threads and non-Ruby threads.
This complex process may be unsuitable for Ruby 3.
https://github.com/chef/win32-service/blob/win32-service-2.3.2/lib/win32/daemon.rb#L257
CreateThread
makes a non-Ruby thread, and it calls Ruby Proc, and it makes a Ruby thread, and ...Also,
StartServiceCtrlDispatcher
creates a non-Ruby thread, and it makes a new Ruby thread again and executesService_Main
Ruby Proc...Although this is still PoC, I found that using Ruby thread from the beginning, as shown below, was very fast.
(It is
322 with patch
data in the above graph).The text was updated successfully, but these errors were encountered: