lib/griffin/server.rb in griffin-0.1.9 vs lib/griffin/server.rb in griffin-0.2.0

- old
+ new

@@ -33,15 +33,19 @@ def config_builder @config_builder ||= Griffin::ServerConfigBuilder.new end end - # @param pool_size [Integer] Worker thread size + # @param min_pool_size [Integer] Worker thread mininum size + # @param max_pool_size [Integer] Worker thread maximun size + # @param min_connection_size [Integer] Maximun connection of TCP + # @param max_connection_size [Integer] Minimum connection of TCP # @param interceptors [Array<GrpcKit::GRPC::ServerInterceptor>] list of interceptors - def initialize(pool_size:, interceptors: [], **opts) - @worker_size = pool_size - @server = GrpcKit::Server.new(interceptors: interceptors) + def initialize(min_pool_size:, max_pool_size:, min_connection_size:, max_connection_size:, interceptors: [], **opts) + @min_connection_size = min_connection_size + @max_connection_size = max_connection_size + @server = GrpcKit::Server.new(interceptors: interceptors, min_pool_size: min_pool_size, max_pool_size: max_pool_size) @opts = opts @status = :run @worker_id = 0 end @@ -63,11 +67,11 @@ end def run(sock, blocking: true) @socks << sock - @thread_pool = Griffin::ThreadPool.new(@worker_size) do |conn| + @thread_pool = Griffin::ThreadPool.new(min: @min_connection_size, max: @max_connection_size) do |conn| @server.run(conn) end if blocking handle_server @@ -111,14 +115,16 @@ case @command.read(1) when FORCIBLE_SHUTDOWN Griffin.logger.info("Shutting down sever(id=#{@worker_id}) forcibly...") @status = :halt - @server.graceful_shutdown + @server.force_shutdown true when GRACEFUL_SHUTDOWN Griffin.logger.info("Shutting down sever(id=#{@worker_id}) gracefully...") + @status = :stop + @server.graceful_shutdown true end end end end