Skip to content
Snippets Groups Projects
Commit 878a7c2a authored by Craig Tiller's avatar Craig Tiller
Browse files

Memory usage tweaks

- Improve estimation to give a more reliable slop space in the arena
- Improve measurement by issuing sufficient throw-away calls on a channel to allow call size estimation to settle
parent 6f1e443a
No related branches found
No related tags found
No related merge requests found
...@@ -194,13 +194,22 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, ...@@ -194,13 +194,22 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target,
size_t grpc_channel_get_call_size_estimate(grpc_channel *channel) { size_t grpc_channel_get_call_size_estimate(grpc_channel *channel) {
#define ROUND_UP_SIZE 256 #define ROUND_UP_SIZE 256
return ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) + /* We round up our current estimate to the NEXT value of ROUND_UP_SIZE.
ROUND_UP_SIZE) & This ensures:
~(size_t)(ROUND_UP_SIZE - 1); 1. a consistent size allocation when our estimate is drifting slowly
(which is common) - which tends to help most allocators reuse memory
2. a small amount of allowed growth over the estimate without hitting
the arena size doubling case, reducing overall memory usage */
size_t est = ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) +
2 * ROUND_UP_SIZE) &
~(size_t)(ROUND_UP_SIZE - 1);
gpr_log(GPR_DEBUG, "est: %d", (int)est);
return est;
} }
void grpc_channel_update_call_size_estimate(grpc_channel *channel, void grpc_channel_update_call_size_estimate(grpc_channel *channel,
size_t size) { size_t size) {
gpr_log(GPR_DEBUG, "used: %d", (int)size);
size_t cur = (size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate); size_t cur = (size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate);
if (cur < size) { if (cur < size) {
/* size grew: update estimate */ /* size grew: update estimate */
......
...@@ -237,6 +237,11 @@ int main(int argc, char **argv) { ...@@ -237,6 +237,11 @@ int main(int argc, char **argv) {
0, grpc_slice_from_static_string("Reflector/GetAfterSvrCreation")); 0, grpc_slice_from_static_string("Reflector/GetAfterSvrCreation"));
// warmup period // warmup period
for (int i = 0; i < warmup_iterations; i++) {
send_snapshot_request(
0, grpc_slice_from_static_string("Reflector/SimpleSnapshot"));
}
for (call_idx = 0; call_idx < warmup_iterations; ++call_idx) { for (call_idx = 0; call_idx < warmup_iterations; ++call_idx) {
init_ping_pong_request(call_idx + 1); init_ping_pong_request(call_idx + 1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment