vjpai | 75291c9 | 2016-03-21 14:59:26 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 20:57:36 | [diff] [blame] | 3 | # Copyright 2016 gRPC authors. |
vjpai | 75291c9 | 2016-03-21 14:59:26 | [diff] [blame] | 4 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 20:57:36 | [diff] [blame] | 5 | # 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 |
vjpai | 75291c9 | 2016-03-21 14:59:26 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 20:57:36 | [diff] [blame] | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
vjpai | 75291c9 | 2016-03-21 14:59:26 | [diff] [blame] | 10 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 20:57:36 | [diff] [blame] | 11 | # 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. |
vjpai | 75291c9 | 2016-03-21 14:59:26 | [diff] [blame] | 16 | |
| 17 | # Worker and worker service implementation |
| 18 | |
| 19 | this_dir = File.expand_path(File.dirname(__FILE__)) |
| 20 | lib_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 | |
| 24 | require 'grpc' |
| 25 | require 'qps-common' |
Ken Payson | 5a2c918 | 2016-07-27 00:15:08 | [diff] [blame] | 26 | require 'src/proto/grpc/testing/messages_pb' |
kpayson64 | 7a20c96 | 2018-04-18 22:19:55 | [diff] [blame] | 27 | require 'src/proto/grpc/testing/benchmark_service_services_pb' |
Ken Payson | 5a2c918 | 2016-07-27 00:15:08 | [diff] [blame] | 28 | require 'src/proto/grpc/testing/stats_pb' |
vjpai | 75291c9 | 2016-03-21 14:59:26 | [diff] [blame] | 29 | |
| 30 | class 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 Polcyn | 689e89c | 2016-09-20 01:36:33 | [diff] [blame] | 37 | PingPongEnumerator.new(reqs).each_item |
vjpai | 75291c9 | 2016-03-21 14:59:26 | [diff] [blame] | 38 | end |
| 39 | end |
| 40 | |
vjpai | 45be26e | 2016-03-30 00:21:28 | [diff] [blame] | 41 | class BenchmarkServer |
| 42 | def initialize(config, port) |
| 43 | if config.security_params |
| 44 | certs = load_test_certs |
vjpai | cf36f85 | 2016-03-30 19:35:34 | [diff] [blame] | 45 | cred = GRPC::Core::ServerCredentials.new( |
| 46 | nil, [{private_key: certs[1], cert_chain: certs[2]}], false) |
vjpai | 45be26e | 2016-03-30 00:21:28 | [diff] [blame] | 47 | else |
| 48 | cred = :this_port_is_insecure |
| 49 | end |
Alexander Polcyn | 847f9ec | 2016-08-16 01:44:14 | [diff] [blame] | 50 | # Make sure server can handle the large number of calls in benchmarks |
Alex Polcyn | 419934a | 2016-10-27 17:40:56 | [diff] [blame] | 51 | # 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) |
vjpai | 45be26e | 2016-03-30 00:21:28 | [diff] [blame] | 54 | @port = @server.add_http2_port("0.0.0.0:" + port.to_s, cred) |
| 55 | @server.handle(BenchmarkServiceImpl.new) |
| 56 | @start_time = Time.now |
murgatroid99 | 2939e2f | 2016-05-23 20:41:32 | [diff] [blame] | 57 | t = Thread.new { |
vjpai | 45be26e | 2016-03-30 00:21:28 | [diff] [blame] | 58 | @server.run |
| 59 | } |
murgatroid99 | 2939e2f | 2016-05-23 20:41:32 | [diff] [blame] | 60 | t.abort_on_exception |
vjpai | 45be26e | 2016-03-30 00:21:28 | [diff] [blame] | 61 | end |
| 62 | def mark(reset) |
vjpai | ed25a33 | 2016-03-30 19:16:25 | [diff] [blame] | 63 | s = Grpc::Testing::ServerStats.new(time_elapsed: |
murgatroid99 | 2939e2f | 2016-05-23 20:41:32 | [diff] [blame] | 64 | (Time.now-@start_time).to_f) |
vjpai | ad1c1cc | 2016-03-30 16:58:46 | [diff] [blame] | 65 | @start_time = Time.now if reset |
vjpai | 45be26e | 2016-03-30 00:21:28 | [diff] [blame] | 66 | s |
| 67 | end |
| 68 | def get_port |
| 69 | @port |
| 70 | end |
Jan Tattermusch | b54f2ae | 2016-04-19 01:08:23 | [diff] [blame] | 71 | def stop |
| 72 | @server.stop |
| 73 | end |
vjpai | 45be26e | 2016-03-30 00:21:28 | [diff] [blame] | 74 | end |