treasure-data / serverengine

A framework to implement robust multiprocess servers like Unicorn
Apache License 2.0
759 stars 86 forks source link

Fix behavior of start_worker_delay option #131

Closed daipom closed 2 years ago

daipom commented 2 years ago

The behavior of start_worker_delay is a little weird.

While not a major problem, there seems to be a minor mistake in the implementation.

Although Fluentd doesn't use this option, if we use the option as follows, then this works as follows.

--- a/lib/fluent/supervisor.rb
+++ b/lib/fluent/supervisor.rb
@@ -494,7 +494,8 @@ module Fluent
         main_cmd: params['main_cmd'],
         signame: params['signame'],
-        disable_shared_socket: params['disable_shared_socket']
+        disable_shared_socket: params['disable_shared_socket'],
+        start_worker_delay: 3
       }
       if daemonize
         se_config[:pid_path] = pid_path

The current behavior

2022-06-10 16:02:08 +0900 [info]: using configuration file: <ROOT>
  <system>
    workers 6
  </system>
  <source>
    @type forward
    port 24224
    bind "0.0.0.0"
  </source>
  <match test.**>
    @type stdout
  </match>
</ROOT>
2022-06-10 16:02:08 +0900 [info]: starting fluentd-1.14.6 pid=353261 ruby="2.7.5"
2022-06-10 16:02:08 +0900 [info]: #0 fluentd worker is now running worker=0
2022-06-10 16:02:11 +0900 [info]: #2 fluentd worker is now running worker=2
2022-06-10 16:02:11 +0900 [info]: #1 fluentd worker is now running worker=1
2022-06-10 16:02:14 +0900 [info]: #4 fluentd worker is now running worker=4
2022-06-10 16:02:14 +0900 [info]: #3 fluentd worker is now running worker=3
2022-06-10 16:02:17 +0900 [info]: #5 fluentd worker is now running worker=5

The behavior with this fix

2022-06-10 15:56:47 +0900 [info]: using configuration file: <ROOT>
  <system>
    workers 6
  </system>
  <source>
    @type forward
    port 24224
    bind "0.0.0.0"
  </source>
  <match test.**>
    @type stdout
  </match>
</ROOT>
2022-06-10 15:56:47 +0900 [info]: starting fluentd-1.14.6 pid=352530 ruby="2.7.5"
2022-06-10 15:56:47 +0900 [info]: #0 fluentd worker is now running worker=0
2022-06-10 15:56:50 +0900 [info]: #1 fluentd worker is now running worker=1
2022-06-10 15:56:53 +0900 [info]: #2 fluentd worker is now running worker=2
2022-06-10 15:56:56 +0900 [info]: #3 fluentd worker is now running worker=3
2022-06-10 15:56:59 +0900 [info]: #4 fluentd worker is now running worker=4
2022-06-10 15:57:02 +0900 [info]: #5 fluentd worker is now running worker=5
daipom commented 2 years ago

I rebased this for checking tests.

ashie commented 2 years ago

:+1:

daipom commented 2 years ago

Thanks for the merge!