Reduce spam log messages at server under high memory pressure (#29470)

* Reduce spam log messages at server under high memory pressure

* change atomic usage

* minor fix

* minor fix
pull/29482/head
Vignesh Babu 3 years ago committed by GitHub
parent dc4ed3d60d
commit 65f510c584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/core/lib/iomgr/tcp_server_posix.cc

@ -29,6 +29,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <string.h>
@ -61,6 +62,8 @@
#include "src/core/lib/iomgr/unix_sockets_posix.h"
#include "src/core/lib/resource_quota/api.h"
static std::atomic<int64_t> num_dropped_connections{0};
static grpc_error_handle tcp_server_create(grpc_closure* shutdown_complete,
const grpc_channel_args* args,
grpc_tcp_server** server) {
@ -221,7 +224,14 @@ static void on_read(void* arg, grpc_error_handle err) {
}
if (sp->server->memory_quota->IsMemoryPressureHigh()) {
gpr_log(GPR_INFO, "Drop incoming connection: high memory pressure");
int64_t dropped_connections_count =
num_dropped_connections.fetch_add(1, std::memory_order_relaxed) + 1;
if (dropped_connections_count % 1000 == 1) {
gpr_log(GPR_INFO,
"Dropped >= %" PRId64
" new connection attempts due to high memory pressure",
dropped_connections_count);
}
close(fd);
continue;
}

Loading…
Cancel
Save