From bae00e08cc021a9d7fbc9778dd87495ca253bf26 Mon Sep 17 00:00:00 2001 From: everysick Date: Thu, 29 Mar 2018 02:23:46 +0900 Subject: Add test for verifying to get memory usage in client request --- src/ruby/end2end/client_memory_usage_client.rb | 44 ++++++++++++++++++++++++++ src/ruby/end2end/client_memory_usage_driver.rb | 36 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100755 src/ruby/end2end/client_memory_usage_client.rb create mode 100755 src/ruby/end2end/client_memory_usage_driver.rb (limited to 'src/ruby/end2end') diff --git a/src/ruby/end2end/client_memory_usage_client.rb b/src/ruby/end2end/client_memory_usage_client.rb new file mode 100755 index 0000000000..c6268b4469 --- /dev/null +++ b/src/ruby/end2end/client_memory_usage_client.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require_relative './end2end_common' +require 'objspace' + +def main + server_port = '' + loop_count = 200 + + OptionParser.new do |opts| + opts.on('--client_control_port=P', String) do + STDERR.puts 'client_control_port ignored' + end + opts.on('--server_port=P', String) do |p| + server_port = p + end + end.parse! + + loop_count.times do + stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", :this_channel_is_insecure) + stub.echo(Echo::EchoRequest.new(request: 'client/child')) + + # Get memory usage of all objects + ObjectSpace.memsize_of_all + end + + STDERR.puts "Succeeded in getting memory usage for #{loop_count} times" +end + +main diff --git a/src/ruby/end2end/client_memory_usage_driver.rb b/src/ruby/end2end/client_memory_usage_driver.rb new file mode 100755 index 0000000000..9e46d7e529 --- /dev/null +++ b/src/ruby/end2end/client_memory_usage_driver.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby + +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require_relative './end2end_common' + +def main + STDERR.puts 'start server' + server_runner = ServerRunner.new(EchoServerImpl) + server_port = server_runner.run + STDERR.puts 'start client' + _, client_pid = start_client('client_memory_usage_client.rb', server_port) + + Process.wait(client_pid) + + client_exit_code = $CHILD_STATUS + if client_exit_code != 0 + raise "Getting memory usage was failed, exit code #{client_exit_code}" + end +ensure + server_runner.stop +end + +main -- cgit v1.2.3 From d3594987dfc612e24fb21db8f2604e9d5bd33a48 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Thu, 5 Apr 2018 03:12:27 -0700 Subject: fix race whereby we can call watch_connectivity_state on a destroyed channel --- src/ruby/end2end/multiple_killed_watching_threads_driver.rb | 6 ++++++ src/ruby/ext/grpc/extconf.rb | 2 +- src/ruby/ext/grpc/rb_channel.c | 12 ++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'src/ruby/end2end') diff --git a/src/ruby/end2end/multiple_killed_watching_threads_driver.rb b/src/ruby/end2end/multiple_killed_watching_threads_driver.rb index 8f078cfbed..8ec2073d98 100755 --- a/src/ruby/end2end/multiple_killed_watching_threads_driver.rb +++ b/src/ruby/end2end/multiple_killed_watching_threads_driver.rb @@ -54,8 +54,14 @@ def run_multiple_killed_watches(num_threads, sleep_time) end def main + STDERR.puts '10 iterations, sleep 0.1 before killing thread' run_multiple_killed_watches(10, 0.1) + STDERR.puts '1000 iterations, sleep 0.001 before killing thread' run_multiple_killed_watches(1000, 0.001) + STDERR.puts '10000 iterations, sleep 0.00001 before killing thread' + run_multiple_killed_watches(10_000, 0.00001) + STDERR.puts '20000 iterations, sleep 0.00001 before killing thread' + run_multiple_killed_watches(20_000, 0.00001) end main diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index e8e87e4f15..4760f33e38 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -84,7 +84,7 @@ if grpc_config == 'gcov' end if grpc_config == 'dbg' - $CFLAGS << ' -O0' + $CFLAGS << ' -O0 -ggdb3' end $LDFLAGS << ' -Wl,-wrap,memcpy' if RUBY_PLATFORM =~ /linux/ diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index e8bfeb32a0..3f0dc530cf 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -315,7 +315,7 @@ static VALUE grpc_rb_channel_get_connectivity_state(int argc, VALUE* argv, } typedef struct watch_state_stack { - grpc_channel* channel; + bg_watched_channel* bg_wrapped; gpr_timespec deadline; int last_state; } watch_state_stack; @@ -328,15 +328,15 @@ static void* wait_for_watch_state_op_complete_without_gvl(void* arg) { gpr_mu_lock(&global_connection_polling_mu); // its unsafe to do a "watch" after "channel polling abort" because the cq has // been shut down. - if (abort_channel_polling) { + if (abort_channel_polling || stack->bg_wrapped->channel_destroyed) { gpr_mu_unlock(&global_connection_polling_mu); return (void*)0; } op = gpr_zalloc(sizeof(watch_state_op)); op->op_type = WATCH_STATE_API; - grpc_channel_watch_connectivity_state(stack->channel, stack->last_state, - stack->deadline, channel_polling_cq, - op); + grpc_channel_watch_connectivity_state(stack->bg_wrapped->channel, + stack->last_state, stack->deadline, + channel_polling_cq, op); while (!op->op.api_callback_args.called_back) { gpr_cv_wait(&global_connection_polling_cv, &global_connection_polling_mu, @@ -388,7 +388,7 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self, return Qnil; } - stack.channel = wrapper->bg_wrapped->channel; + stack.bg_wrapped = wrapper->bg_wrapped; stack.deadline = grpc_rb_time_timeval(deadline, 0), stack.last_state = NUM2LONG(last_state); -- cgit v1.2.3