griffin 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +86 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -2
- data/LICENSE.txt +1 -1
- data/README.md +42 -9
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/examples/helloworld/helloworld.proto +37 -0
- data/examples/helloworld/helloworld_pb.rb +18 -0
- data/examples/helloworld/helloworld_services_pb.rb +22 -0
- data/examples/helloworld_client.rb +12 -0
- data/examples/helloworld_server.rb +22 -0
- data/examples/interceptors/client_logging_interceptor.rb +48 -0
- data/examples/interceptors/server_logging_interceptor.rb +44 -0
- data/examples/routeguide/routeguide.json +601 -0
- data/examples/routeguide/routeguide.proto +110 -0
- data/examples/routeguide/routeguide_pb.rb +37 -0
- data/examples/routeguide/routeguide_services_pb.rb +61 -0
- data/examples/routeguide_client.rb +83 -0
- data/examples/routeguide_server.rb +118 -0
- data/griffin.gemspec +18 -12
- data/lib/griffin/connection_pool/multi_timed_stack.rb +78 -0
- data/lib/griffin/connection_pool/pool.rb +56 -0
- data/lib/griffin/counting_semaphore.rb +19 -0
- data/lib/griffin/engine/server.rb +29 -0
- data/lib/griffin/engine/single.rb +41 -0
- data/lib/griffin/engine/worker.rb +27 -0
- data/lib/griffin/engine.rb +20 -0
- data/lib/griffin/listener.rb +36 -0
- data/lib/griffin/server.rb +118 -0
- data/lib/griffin/server_config_builder.rb +55 -0
- data/lib/griffin/thread_pool.rb +88 -0
- data/lib/griffin/version.rb +3 -1
- data/lib/griffin.rb +10 -2
- metadata +87 -6
- data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 79c985d4054a2fc70cc7f1b55041b5c648fb2edc847540ba610bb79ac0f96cb1
|
4
|
+
data.tar.gz: a3089cfff259dc1a8742ea1e776d4577ca06f4e400e3c2ab9417745b893588e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73fa55a2b5fb9dbe1d00829e5add7769cb76ffb03c6d03600c50c9a3d2c2c8465442d80e2f2ed652135cc0a8dad02417e42c6fb1cab0c4d90b98baee9b3261ff
|
7
|
+
data.tar.gz: 101657f06a41028df869bf0e1aa3e33dd88ced2385554daf82e9c01a7d39479044930026456d9257accb36671393c4d6d7eb4fb8c5ede9394f6acb1d72983ba7
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- '**/**/*_pb.rb' # auto-generated
|
4
|
+
- "vendor/**/*"
|
5
|
+
DisplayCopNames: true
|
6
|
+
TargetRubyVersion: 2.5
|
7
|
+
|
8
|
+
Style/AndOr:
|
9
|
+
EnforcedStyle: conditionals
|
10
|
+
|
11
|
+
Style/AsciiComments:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/DoubleNegation:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/EmptyElse:
|
21
|
+
EnforcedStyle: empty
|
22
|
+
|
23
|
+
Style/FormatString:
|
24
|
+
EnforcedStyle: percent
|
25
|
+
|
26
|
+
Style/IfUnlessModifier:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/TrailingCommaInHashLiteral:
|
30
|
+
EnforcedStyleForMultiline: comma
|
31
|
+
|
32
|
+
Style/TrailingCommaInArguments:
|
33
|
+
EnforcedStyleForMultiline: comma
|
34
|
+
|
35
|
+
Style/SafeNavigation:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Naming/PredicateName:
|
39
|
+
NamePrefixBlacklist:
|
40
|
+
- "is_"
|
41
|
+
- "have_"
|
42
|
+
NamePrefix:
|
43
|
+
- "is_"
|
44
|
+
- "have_"
|
45
|
+
|
46
|
+
Style/SignalException:
|
47
|
+
EnforcedStyle: only_raise
|
48
|
+
|
49
|
+
Style/SingleLineBlockParams:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/NumericLiterals:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Style/GuardClause:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/NumericPredicate:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Metrics/ParameterLists:
|
62
|
+
CountKeywordArgs: false
|
63
|
+
|
64
|
+
Lint/UnderscorePrefixedVariableName:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Metrics/AbcSize:
|
68
|
+
Max: 50
|
69
|
+
|
70
|
+
Metrics/CyclomaticComplexity:
|
71
|
+
Max: 10
|
72
|
+
|
73
|
+
Metrics/LineLength:
|
74
|
+
Max: 160
|
75
|
+
|
76
|
+
Metrics/MethodLength:
|
77
|
+
Max: 40
|
78
|
+
|
79
|
+
Metrics/PerceivedComplexity:
|
80
|
+
Max: 20
|
81
|
+
|
82
|
+
Metrics/ClassLength:
|
83
|
+
Max: 200
|
84
|
+
|
85
|
+
Metrics/BlockLength:
|
86
|
+
Max: 40
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in griffin.gemspec
|
6
8
|
gemspec
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# Griffin
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/griffin.svg)](https://badge.fury.io/rb/griffin)
|
4
4
|
|
5
|
-
|
5
|
+
|
6
|
+
__UNDER DEVELOPMENT__
|
7
|
+
|
8
|
+
Griffin is [gRPC](https://grpc.io/) server which supports multi process by using [serverengine](https://github.com/treasure-data/serverengine).
|
9
|
+
Griffin also supports building gRPC client.
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
@@ -14,25 +18,54 @@ gem 'griffin'
|
|
14
18
|
|
15
19
|
And then execute:
|
16
20
|
|
17
|
-
|
21
|
+
```
|
22
|
+
$ bundle
|
23
|
+
```
|
18
24
|
|
19
25
|
Or install it yourself as:
|
20
26
|
|
21
|
-
|
27
|
+
```
|
28
|
+
gem install griffin
|
29
|
+
```
|
22
30
|
|
23
31
|
## Usage
|
24
32
|
|
25
|
-
|
33
|
+
#### Server
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class GreeterServer < Helloworld::Greeter::Service
|
37
|
+
def say_hello(hello_req, _unused_call)
|
38
|
+
Helloworld::HelloReply.new(message: "Hello #{hello_req.name}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Griffin::Server.configure do |c|
|
43
|
+
c.bind '127.0.0.1'
|
44
|
+
|
45
|
+
c.port 50051
|
46
|
+
|
47
|
+
c.services GreeterServer.new
|
48
|
+
|
49
|
+
c.worker 2 # A number of worker process
|
50
|
+
end
|
51
|
+
|
52
|
+
Griffin::Server.run
|
53
|
+
|
54
|
+
```
|
26
55
|
|
27
56
|
## Development
|
28
57
|
|
29
|
-
|
58
|
+
```
|
59
|
+
bundle install
|
60
|
+
```
|
61
|
+
|
62
|
+
## Requirements
|
30
63
|
|
31
|
-
|
64
|
+
* [nghttp2](https://nghttp2.org/)
|
32
65
|
|
33
66
|
## Contributing
|
34
67
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ganmacs/griffin.
|
36
69
|
|
37
70
|
## License
|
38
71
|
|
@@ -40,4 +73,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
73
|
|
41
74
|
## Code of Conduct
|
42
75
|
|
43
|
-
|
76
|
+
TODO
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'griffin'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "griffin"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Copyright 2015 gRPC authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
syntax = "proto3";
|
16
|
+
|
17
|
+
option java_multiple_files = true;
|
18
|
+
option java_package = "io.grpc.examples.helloworld";
|
19
|
+
option java_outer_classname = "HelloWorldProto";
|
20
|
+
|
21
|
+
package helloworld;
|
22
|
+
|
23
|
+
// The greeting service definition.
|
24
|
+
service Greeter {
|
25
|
+
// Sends a greeting
|
26
|
+
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
27
|
+
}
|
28
|
+
|
29
|
+
// The request message containing the user's name.
|
30
|
+
message HelloRequest {
|
31
|
+
string name = 1;
|
32
|
+
}
|
33
|
+
|
34
|
+
// The response message containing the greetings
|
35
|
+
message HelloReply {
|
36
|
+
string message = 1;
|
37
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: helloworld.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_message "helloworld.HelloRequest" do
|
8
|
+
optional :name, :string, 1
|
9
|
+
end
|
10
|
+
add_message "helloworld.HelloReply" do
|
11
|
+
optional :message, :string, 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Helloworld
|
16
|
+
HelloRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("helloworld.HelloRequest").msgclass
|
17
|
+
HelloReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("helloworld.HelloReply").msgclass
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# Source: helloworld.proto for package 'helloworld'
|
3
|
+
|
4
|
+
require 'grpc'
|
5
|
+
require 'helloworld_pb'
|
6
|
+
|
7
|
+
module Helloworld
|
8
|
+
module Greeter
|
9
|
+
class Service
|
10
|
+
|
11
|
+
include GRPC::GenericService
|
12
|
+
|
13
|
+
self.marshal_class_method = :encode
|
14
|
+
self.unmarshal_class_method = :decode
|
15
|
+
self.service_name = 'helloworld.Greeter'
|
16
|
+
|
17
|
+
rpc :SayHello, HelloRequest, HelloReply
|
18
|
+
end
|
19
|
+
|
20
|
+
Stub = Service.rpc_stub_class
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('./examples/helloworld')
|
4
|
+
|
5
|
+
require 'griffin'
|
6
|
+
require 'socket'
|
7
|
+
require 'pry'
|
8
|
+
require 'helloworld_services_pb'
|
9
|
+
|
10
|
+
stub = Helloworld::Greeter::Stub.new('localhost', 50051)
|
11
|
+
message = stub.say_hello(Helloworld::HelloRequest.new(name: 'ganmacs')).message
|
12
|
+
p message
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('./examples/helloworld')
|
4
|
+
|
5
|
+
require 'griffin'
|
6
|
+
require 'helloworld_services_pb'
|
7
|
+
|
8
|
+
class GreeterServer < Helloworld::Greeter::Service
|
9
|
+
def say_hello(hello_req, _unused_call)
|
10
|
+
Helloworld::HelloReply.new(message: "Hello #{hello_req.name}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Griffin::Server.configure do |c|
|
15
|
+
c.bind '127.0.0.1'
|
16
|
+
|
17
|
+
c.port 50051
|
18
|
+
|
19
|
+
c.services GreeterServer.new
|
20
|
+
end
|
21
|
+
|
22
|
+
Griffin::Server.run
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'grpc_kit'
|
4
|
+
|
5
|
+
class LoggingInterceptor < GRPC::ClientInterceptor
|
6
|
+
def request_response(request: nil, method: nil, **)
|
7
|
+
now = Time.now.to_i
|
8
|
+
GrpcKit.logger.info("Started request #{request}, method=#{method.name}, service_name=#{method.receiver.class.service_name}")
|
9
|
+
yield.tap do
|
10
|
+
GrpcKit.logger.info("Elapsed Time: #{Time.now.to_i - now}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def client_streamer(call: nil, method: nil, **)
|
15
|
+
GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
|
16
|
+
yield(LoggingStream.new(call))
|
17
|
+
end
|
18
|
+
|
19
|
+
def server_streamer(call: nil, method: nil, **)
|
20
|
+
GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
|
21
|
+
yield(LoggingStream.new(call))
|
22
|
+
end
|
23
|
+
|
24
|
+
def bidi_streamer(**)
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
|
28
|
+
class LoggingStream
|
29
|
+
def initialize(stream)
|
30
|
+
@stream = stream
|
31
|
+
end
|
32
|
+
|
33
|
+
def send_msg(msg, **opts)
|
34
|
+
GrpcKit.logger.info("logging interceptor send #{msg}")
|
35
|
+
@stream.send_msg(msg, opts)
|
36
|
+
end
|
37
|
+
|
38
|
+
def recv(**opt)
|
39
|
+
@stream.recv(opt).tap do |v|
|
40
|
+
GrpcKit.logger.info("logging interceptor recv #{v}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def close_and_recv
|
45
|
+
@stream.close_and_recv
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'grpc_kit'
|
4
|
+
|
5
|
+
class LoggingInterceptor < GRPC::ServerInterceptor
|
6
|
+
def request_response(request: nil, call: nil, method: nil)
|
7
|
+
now = Time.now.to_i
|
8
|
+
GrpcKit.logger.info("Started request #{request}, method=#{method.name}, service_name=#{method.receiver.class.service_name}")
|
9
|
+
yield(request, call).tap do
|
10
|
+
GrpcKit.logger.info("Elapsed Time: #{Time.now.to_i - now}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def client_streamer(call: nil, method: nil)
|
15
|
+
GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
|
16
|
+
yield(LoggingStream.new(call))
|
17
|
+
end
|
18
|
+
|
19
|
+
def server_streamer(call: nil, method: nil, **)
|
20
|
+
GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
|
21
|
+
yield(LoggingStream.new(call))
|
22
|
+
end
|
23
|
+
|
24
|
+
def bidi_streamer(**)
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
|
28
|
+
class LoggingStream
|
29
|
+
def initialize(stream)
|
30
|
+
@stream = stream
|
31
|
+
end
|
32
|
+
|
33
|
+
def send_msg(msg, **opt)
|
34
|
+
GrpcKit.logger.info("logging interceptor send #{msg}")
|
35
|
+
@stream.send_msg(msg, opt)
|
36
|
+
end
|
37
|
+
|
38
|
+
def recv(**opt)
|
39
|
+
@stream.recv(**opt).tap do |v|
|
40
|
+
GrpcKit.logger.info("logging interceptor recv #{v}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|