blob: dccc64e3009c65d17bd1821ee543ec55ec64b79d [file] [log] [blame]
vjpai75291c92016-03-21 14:59:261#!/usr/bin/env ruby
2
Jan Tattermusch7897ae92017-06-07 20:57:363# Copyright 2016 gRPC authors.
vjpai75291c92016-03-21 14:59:264#
Jan Tattermusch7897ae92017-06-07 20:57:365# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
vjpai75291c92016-03-21 14:59:268#
Jan Tattermusch7897ae92017-06-07 20:57:369# http://www.apache.org/licenses/LICENSE-2.0
vjpai75291c92016-03-21 14:59:2610#
Jan Tattermusch7897ae92017-06-07 20:57:3611# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
vjpai75291c92016-03-21 14:59:2616
17# Worker and worker service implementation
18
19this_dir = File.expand_path(File.dirname(__FILE__))
20lib_dir = File.join(File.dirname(this_dir), 'lib')
21$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
22$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
23
24require 'grpc'
25require 'qps-common'
Ken Payson5a2c9182016-07-27 00:15:0826require 'src/proto/grpc/testing/messages_pb'
kpayson647a20c962018-04-18 22:19:5527require 'src/proto/grpc/testing/benchmark_service_services_pb'
Ken Payson5a2c9182016-07-27 00:15:0828require 'src/proto/grpc/testing/stats_pb'
vjpai75291c92016-03-21 14:59:2629
30class BenchmarkServiceImpl < Grpc::Testing::BenchmarkService::Service
31 def unary_call(req, _call)
32 sr = Grpc::Testing::SimpleResponse
33 pl = Grpc::Testing::Payload
34 sr.new(payload: pl.new(body: nulls(req.response_size)))
35 end
36 def streaming_call(reqs)
Alexander Polcyn689e89c2016-09-20 01:36:3337 PingPongEnumerator.new(reqs).each_item
vjpai75291c92016-03-21 14:59:2638 end
39end
40
vjpai45be26e2016-03-30 00:21:2841class BenchmarkServer
42 def initialize(config, port)
43 if config.security_params
44 certs = load_test_certs
vjpaicf36f852016-03-30 19:35:3445 cred = GRPC::Core::ServerCredentials.new(
46 nil, [{private_key: certs[1], cert_chain: certs[2]}], false)
vjpai45be26e2016-03-30 00:21:2847 else
48 cred = :this_port_is_insecure
49 end
Alexander Polcyn847f9ec2016-08-16 01:44:1450 # Make sure server can handle the large number of calls in benchmarks
Alex Polcyn419934a2016-10-27 17:40:5651 # TODO: @apolcyn, if scenario config increases total outstanding
52 # calls then will need to increase the pool size too
53 @server = GRPC::RpcServer.new(pool_size: 1024, max_waiting_requests: 1024)
vjpai45be26e2016-03-30 00:21:2854 @port = @server.add_http2_port("0.0.0.0:" + port.to_s, cred)
55 @server.handle(BenchmarkServiceImpl.new)
56 @start_time = Time.now
murgatroid992939e2f2016-05-23 20:41:3257 t = Thread.new {
vjpai45be26e2016-03-30 00:21:2858 @server.run
59 }
murgatroid992939e2f2016-05-23 20:41:3260 t.abort_on_exception
vjpai45be26e2016-03-30 00:21:2861 end
62 def mark(reset)
vjpaied25a332016-03-30 19:16:2563 s = Grpc::Testing::ServerStats.new(time_elapsed:
murgatroid992939e2f2016-05-23 20:41:3264 (Time.now-@start_time).to_f)
vjpaiad1c1cc2016-03-30 16:58:4665 @start_time = Time.now if reset
vjpai45be26e2016-03-30 00:21:2866 s
67 end
68 def get_port
69 @port
70 end
Jan Tattermuschb54f2ae2016-04-19 01:08:2371 def stop
72 @server.stop
73 end
vjpai45be26e2016-03-30 00:21:2874end