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 +4 -4
- data/lib/griffin/engine/server.rb +4 -3
- data/lib/griffin/engine/single.rb +4 -3
- data/lib/griffin/engine/worker.rb +8 -5
- data/lib/griffin/server.rb +7 -1
- data/lib/griffin/server_config_builder.rb +1 -1
- data/lib/griffin/thread_pool.rb +4 -0
- data/lib/griffin/version.rb +1 -1
- metadata +2 -3
- data/lib/griffin/listener.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 853f045042c1e48f339bbccbf5cfad440f93140c5731339387f297fcc94043b6
|
4
|
+
data.tar.gz: 89c07719af930c53773099f827e1e97658b6dbeaf6575b612a963cc03b92f744
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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, :
|
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
|
-
@
|
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
|
-
@
|
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
|
-
|
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
|
-
@
|
19
|
+
@lsock.close if @lsock
|
17
20
|
end
|
18
21
|
|
19
22
|
def stop
|
data/lib/griffin/server.rb
CHANGED
@@ -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
|
106
|
+
@thread_pool.schedule(conn)
|
101
107
|
rescue IO::WaitReadable, Errno::EINTR => e
|
102
108
|
Griffin.logger.debug("Error raised #{e}")
|
103
109
|
# nothing
|
data/lib/griffin/thread_pool.rb
CHANGED
data/lib/griffin/version.rb
CHANGED
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.
|
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-
|
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
|
data/lib/griffin/listener.rb
DELETED
@@ -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
|