client_memory_usage_client.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env ruby
  2. # Copyright 2018 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. require_relative './end2end_common'
  16. require 'objspace'
  17. def main
  18. parent_controller_port = ''
  19. server_port = ''
  20. loop_count = 200
  21. OptionParser.new do |opts|
  22. opts.on('--parent_controller_port=P', String) do |p|
  23. parent_controller_port = p
  24. end
  25. opts.on('--server_port=P', String) do |p|
  26. server_port = p
  27. end
  28. end.parse!
  29. report_controller_port_to_parent(parent_controller_port, 0)
  30. loop_count.times do
  31. stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", :this_channel_is_insecure)
  32. stub.echo(Echo::EchoRequest.new(request: 'client/child'))
  33. # Get memory usage of all objects
  34. ObjectSpace.memsize_of_all
  35. end
  36. STDERR.puts "Succeeded in getting memory usage for #{loop_count} times"
  37. end
  38. main