griffin 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61289d32bbb5830ad446ea08b51604a4f4cf0340f59ec596dcc92c32cf29f7ac
4
- data.tar.gz: dc61c80a41aa8c79294d88c9b2042b3e7babb728c108be7fe7a581e6c6324559
3
+ metadata.gz: 853f045042c1e48f339bbccbf5cfad440f93140c5731339387f297fcc94043b6
4
+ data.tar.gz: 89c07719af930c53773099f827e1e97658b6dbeaf6575b612a963cc03b92f744
5
5
  SHA512:
6
- metadata.gz: c0629cb8f5fe58daa29b9c44d0e27cf37f29885e26bbc8fefb4a9aac624be4efed3436e98053fd554bcff1576fa0c9c4e26c313baf1e059ededae9ab0237b601
7
- data.tar.gz: ea6576f3ab391cc2f632872375926c26e1f374006ee1d7b9f38be37bbe8af053ebdc208f933db309e95a262e1fa14272efcbf17b45941d07be0998fb16cc6f18
6
+ metadata.gz: a3f7098832322baa01051bb48a0a4d5222c2807ba70139fcef4a3c57b5e9ebac0edd99a29aa0eed2eb46ce40a585c2e41e03e7d019983f0e45d33ad449effab0
7
+ data.tar.gz: 92fe69659ed318b4c3b56471de2e5decc26e30caf708e0d577f769954fd0de0938404e04d40a4965ccfe034372783974aee2c1f699aaece922c9af6e5cd4c052
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'griffin/listener'
4
-
5
3
  module Griffin
6
4
  module Engine
7
5
  module Server
8
- attr_reader :core, :listener
6
+ attr_reader :core, :socket_manager_path
9
7
 
10
8
  def initialize
11
9
  @core = Griffin::Server.new(
@@ -16,6 +14,8 @@ module Griffin
16
14
  max_connection_size: config[:max_connection_size],
17
15
  interceptors: config[:interceptors],
18
16
  )
17
+ @socket_manager_path = ServerEngine::SocketManager::Server.generate_path
18
+ @socket_manager_server = ServerEngine::SocketManager::Server.open(@socket_manager_path)
19
19
  end
20
20
 
21
21
  def before_run
@@ -26,6 +26,7 @@ module Griffin
26
26
 
27
27
  def stop(stop_graceful)
28
28
  super # needed
29
+ @socket_manager_server.close
29
30
  end
30
31
 
31
32
  # def after_start; end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'griffin/server'
4
- require 'griffin/listener'
5
4
 
6
5
  module Griffin
7
6
  module Engine
@@ -20,7 +19,8 @@ module Griffin
20
19
  def initialize(server, config)
21
20
  @server = server
22
21
  @config = config
23
- @listener = Griffin::Listener.new(@config[:bind], @config[:port])
22
+ @sock = TCPServer.new(@config[:bind], @config[:port])
23
+ @sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
24
24
  end
25
25
 
26
26
  def run
@@ -31,7 +31,8 @@ module Griffin
31
31
  install_handler
32
32
 
33
33
  @server.before_run
34
- @server.run(@listener.listen)
34
+ @sock.listen(Socket::SOMAXCONN)
35
+ @server.run(@sock)
35
36
  end
36
37
 
37
38
  def install_handler
@@ -1,19 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'griffin/listener'
4
-
5
3
  module Griffin
6
4
  module Engine
7
5
  module Worker
6
+ def initialize
7
+ @socket_manager = ServerEngine::SocketManager::Client.new(server.socket_manager_path)
8
+ end
9
+
8
10
  def before_fork
9
- @listener = Griffin::Listener.new(config[:bind], config[:port])
10
11
  server.core.before_run(worker_id)
11
12
  end
12
13
 
13
14
  def run
14
- server.core.run(@listener.listen)
15
+ @lsock = @socket_manager.listen_tcp(config[:bind], config[:port])
16
+ @lsock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
17
+ server.core.run(@lsock)
15
18
  ensure
16
- @listener.close
19
+ @lsock.close if @lsock
17
20
  end
18
21
 
19
22
  def stop
@@ -95,9 +95,15 @@ module Griffin
95
95
  break if handle_command
96
96
  end
97
97
 
98
+ # @thread_pool.schedule could block and accepted socket would be timeout.
99
+ # So call Thread.pass other workers having resources to handle a request would accept.
100
+ unless @thread_pool.resouce_available?
101
+ break
102
+ end
103
+
98
104
  begin
99
105
  conn = sock.accept_nonblock
100
- @thread_pool.schedule(conn[0])
106
+ @thread_pool.schedule(conn)
101
107
  rescue IO::WaitReadable, Errno::EINTR => e
102
108
  Griffin.logger.debug("Error raised #{e}")
103
109
  # nothing
@@ -8,7 +8,7 @@ module Griffin
8
8
  SERVERENGIEN_FIXED_CONFIGS = %i[daemonize worker_type worker_process_name].freeze
9
9
 
10
10
  # The default size of thread pool TCP Connection
11
- DEFAULT_POOL_SIZE = 30
11
+ DEFAULT_POOL_SIZE = 20
12
12
  DEFAULT_CONNECTION_SIZE = 3
13
13
 
14
14
  GRIFFIN_CONFIGS = [
@@ -41,6 +41,10 @@ module Griffin
41
41
  end
42
42
  end
43
43
 
44
+ def resouce_available?
45
+ (@waiting != 0) || (@spawned != @max_pool_size)
46
+ end
47
+
44
48
  def shutdown
45
49
  @shutdown = true
46
50
  @max_pool_size.times { @tasks.push(nil) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Griffin
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: griffin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Iwama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,7 +146,6 @@ files:
146
146
  - lib/griffin/engine/server.rb
147
147
  - lib/griffin/engine/single.rb
148
148
  - lib/griffin/engine/worker.rb
149
- - lib/griffin/listener.rb
150
149
  - lib/griffin/logger.rb
151
150
  - lib/griffin/server.rb
152
151
  - lib/griffin/server_config_builder.rb
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'socket'
4
-
5
- module Griffin
6
- class Listener
7
- DEFAULT_BACKLOG_SIZE = 1024
8
-
9
- # @params host [String]
10
- # @params port [Integer]
11
- # @params backlog [Integer]
12
- def initialize(host, port, backlog: DEFAULT_BACKLOG_SIZE)
13
- @host = host
14
- @port = port
15
- @backlog = backlog
16
- end
17
-
18
- def listen(tcp_opt: true)
19
- @sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
20
- if tcp_opt
21
- @sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
22
- end
23
-
24
- @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true)
25
-
26
- @sock.bind(Addrinfo.tcp(@host, @port))
27
- @sock.listen(@backlog)
28
- Griffin.logger.info("Start listening #{@host}:#{@port}")
29
- @sock
30
- end
31
-
32
- def close
33
- @sock.close
34
- end
35
- end
36
- end