Last active
March 9, 2016 14:06
-
-
Save zhuochun/0b3bc724208559e1dca1 to your computer and use it in GitHub Desktop.
Ruby GRPC Memory Leak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample app that connects to a Greeter service. | |
# | |
# Usage: $ path/to/greeter_client.rb | |
this_dir = File.expand_path(File.dirname(__FILE__)) | |
lib_dir = File.join(this_dir, 'lib') | |
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) | |
require 'grpc' | |
require 'helloworld_services' | |
def main | |
stub = Helloworld::Greeter::Stub.new('localhost:50051', :this_channel_is_insecure) | |
loop do | |
stub.say_hello(Helloworld::HelloRequest.new(name: Time.now.to_s * 100)) | |
end | |
end | |
main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample gRPC server that implements the Greeter::Helloworld service. | |
# | |
# Usage: $ path/to/greeter_server.rb | |
this_dir = File.expand_path(File.dirname(__FILE__)) | |
lib_dir = File.join(this_dir, 'lib') | |
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) | |
require 'grpc' | |
require 'helloworld_services' | |
# GreeterServer is simple server that implements the Helloworld Greeter server. | |
class GreeterServer < Helloworld::Greeter::Service | |
# say_hello implements the SayHello rpc method. | |
def say_hello(hello_req, _unused_call) | |
Helloworld::HelloReply.new(message: "Hello #{hello_req.name}" * 10000) # Longer text | |
end | |
end | |
# main starts an RpcServer that receives requests to GreeterServer at the sample | |
# server port. | |
def main | |
s = GRPC::RpcServer.new | |
s.add_http2_port('0.0.0.0:50051', :this_port_is_insecure) | |
s.handle(GreeterServer) | |
s.run_till_terminated | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment