|
|
@ -29,6 +29,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <errno.h> |
|
|
|
#include <errno.h> |
|
|
|
#include <fcntl.h> |
|
|
|
#include <fcntl.h> |
|
|
|
|
|
|
|
#include <inttypes.h> |
|
|
|
#include <netinet/in.h> |
|
|
|
#include <netinet/in.h> |
|
|
|
#include <netinet/tcp.h> |
|
|
|
#include <netinet/tcp.h> |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
@ -61,6 +62,8 @@ |
|
|
|
#include "src/core/lib/iomgr/unix_sockets_posix.h" |
|
|
|
#include "src/core/lib/iomgr/unix_sockets_posix.h" |
|
|
|
#include "src/core/lib/resource_quota/api.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, |
|
|
|
static grpc_error_handle tcp_server_create(grpc_closure* shutdown_complete, |
|
|
|
const grpc_channel_args* args, |
|
|
|
const grpc_channel_args* args, |
|
|
|
grpc_tcp_server** server) { |
|
|
|
grpc_tcp_server** server) { |
|
|
@ -221,7 +224,14 @@ static void on_read(void* arg, grpc_error_handle err) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (sp->server->memory_quota->IsMemoryPressureHigh()) { |
|
|
|
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); |
|
|
|
close(fd); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|