Add channel memory benchmark into memory_diff.py (#30507)

* Added the channel benchmark to the python script

* removing warning

* Automated change: Fix sanity tests

* added label function for channel and skip for minstack channel

* Automated change: Fix sanity tests

Co-authored-by: nancylucy01 <nancylucy01@users.noreply.github.com>
pull/30515/head
nancylucy01 3 years ago committed by GitHub
parent 65fc31a988
commit cc96858f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      test/core/memory_usage/callback_client.cc
  2. 1
      test/core/memory_usage/callback_server.cc
  3. 1
      test/core/memory_usage/memstats.cc
  4. 64
      tools/profiling/memory/memory_diff.py

@ -17,6 +17,7 @@
*/
#include <limits.h>
#include <stdio.h>
#include <chrono>
#include <memory>
@ -150,16 +151,6 @@ int main(int argc, char** argv) {
// Getting peak memory usage
long peak_server_memory = GetMemUsage(absl::GetFlag(FLAGS_server_pid));
long peak_client_memory = GetMemUsage();
gpr_log(GPR_INFO, "Before Server Mem: %ld", before_server_memory);
gpr_log(GPR_INFO, "Before Client Mem: %ld", before_client_memory);
gpr_log(GPR_INFO, "Peak Server Mem: %ld", peak_server_memory);
gpr_log(GPR_INFO, "Peak Client Mem: %ld", peak_client_memory);
gpr_log(GPR_INFO, "Server Per Channel Memory: %f",
static_cast<float>(peak_server_memory - before_server_memory) /
static_cast<float>(size));
gpr_log(GPR_INFO, "Client Per Channel Memory: %f",
static_cast<float>(peak_client_memory - before_client_memory) /
static_cast<float>(size));
// Checking that all channels are still open
for (int i = 0; i < size; ++i) {
@ -168,6 +159,15 @@ int main(int argc, char** argv) {
std::chrono::system_clock::now() +
std::chrono::milliseconds(1)));
}
printf("---------Client channel stats--------\n");
printf("client channel memory usage: %f bytes per channel\n",
static_cast<double>(peak_client_memory - before_client_memory) / size *
1024);
printf("---------Server channel stats--------\n");
printf("server channel memory usage: %f bytes per channel\n",
static_cast<double>(peak_server_memory - before_server_memory) / size *
1024);
gpr_log(GPR_INFO, "Client Done");
return 0;
}

@ -90,7 +90,6 @@ int main(int argc, char** argv) {
// Get initial process memory usage before creating server
long before_server_create = GetMemUsage();
gpr_log(GPR_INFO, "Server Before Mem: %ld", before_server_create);
ServerCallbackImpl callback_server(before_server_create);
grpc::ServerBuilder builder;

@ -52,5 +52,6 @@ long GetMemUsage(absl::optional<int> pid) {
// Calculations in case x86-64 is configured to use 2MB pages
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024;
resident_set = rss * page_size_kb;
// Memory in KB
return resident_set;
}

@ -43,10 +43,14 @@ argp.add_argument('-j', '--jobs', type=int, default=multiprocessing.cpu_count())
args = argp.parse_args()
_INTERESTING = {
'client call':
'call/client':
(rb'client call memory usage: ([0-9\.]+) bytes per call', float),
'server call':
'call/server':
(rb'server call memory usage: ([0-9\.]+) bytes per call', float),
'channel/client':
(rb'client channel memory usage: ([0-9\.]+) bytes per channel', float),
'channel/server':
(rb'server channel memory usage: ([0-9\.]+) bytes per channel', float),
}
_SCENARIOS = {
@ -54,6 +58,11 @@ _SCENARIOS = {
'minstack': ['--scenario_config=minstack'],
}
_BENCHMARKS = {
'call': ['--benchmark_names=call', '--size=50000'],
'channel': ['--benchmark_names=channel', '--size=10000'],
}
def _run():
"""Build with Bazel, then run, and extract interesting lines from the output."""
@ -62,21 +71,23 @@ def _run():
'test/core/memory_usage/memory_usage_test'
])
ret = {}
for scenario, extra_args in _SCENARIOS.items():
try:
output = subprocess.check_output([
'bazel-bin/test/core/memory_usage/memory_usage_test',
'--benchmark_names=call',
'--size=50000',
] + extra_args)
except subprocess.CalledProcessError as e:
print('Error running benchmark:', e)
continue
for line in output.splitlines():
for key, (pattern, conversion) in _INTERESTING.items():
m = re.match(pattern, line)
if m:
ret[scenario + ': ' + key] = conversion(m.group(1))
for name, benchmark_args in _BENCHMARKS.items():
for scenario, extra_args in _SCENARIOS.items():
#TODO(chenancy) Remove when minstack is implemented for channel
if name == 'channel' and scenario == 'minstack':
continue
try:
output = subprocess.check_output([
'bazel-bin/test/core/memory_usage/memory_usage_test',
] + benchmark_args + extra_args)
except subprocess.CalledProcessError as e:
print('Error running benchmark:', e)
continue
for line in output.splitlines():
for key, (pattern, conversion) in _INTERESTING.items():
m = re.match(pattern, line)
if m:
ret[scenario + ': ' + key] = conversion(m.group(1))
return ret
@ -101,7 +112,8 @@ if old is None:
text += '{}: {}\n'.format(key, value)
else:
print(cur, old)
diff_size = 0
call_diff_size = 0
channel_diff_size = 0
for scenario in _SCENARIOS.keys():
for key, value in sorted(_INTERESTING.items()):
key = scenario + ': ' + key
@ -109,11 +121,19 @@ else:
if key not in old:
text += '{}: {}\n'.format(key, cur[key])
else:
diff_size += cur[key] - old[key]
text += '{}: {} -> {}\n'.format(key, old[key], cur[key])
print("DIFF_SIZE: %f" % diff_size)
check_on_pr.label_increase_decrease_on_pr('per-call-memory', diff_size, 64)
if key == 'call/client' or 'call/server':
call_diff_size += cur[key] - old[key]
else:
channel_diff_size += cur[key] - old[key]
print("CALL_DIFF_SIZE: %f" % call_diff_size)
print("CHANNEL_DIFF_SIZE: %f" % channel_diff_size)
check_on_pr.label_increase_decrease_on_pr('per-call-memory', call_diff_size,
64)
check_on_pr.label_increase_decrease_on_pr('per-channel-memory',
channel_diff_size, 1000)
#TODO(chennancy)Change significant value when minstack also runs for channel
print(text)
check_on_pr.check_on_pr('Memory Difference', '```\n%s\n```' % text)

Loading…
Cancel
Save