Add stats for server request serving path

pull/12398/head
Craig Tiller 7 years ago
parent 83db6312c6
commit 561dc32247
  1. 44
      src/core/lib/debug/stats_data.c
  2. 23
      src/core/lib/debug/stats_data.h
  3. 6
      src/core/lib/debug/stats_data.yaml
  4. 5
      src/core/lib/surface/server.c

@ -48,10 +48,13 @@ const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = {
"executor_scheduled_to_self", "executor_scheduled_to_self",
"executor_wakeup_initiated", "executor_wakeup_initiated",
"executor_queue_drained", "executor_queue_drained",
"server_requested_calls",
"server_slowpath_requests_queued",
}; };
const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = {
"tcp_write_size", "tcp_write_iov_size", "tcp_read_size", "tcp_write_size", "tcp_write_iov_size", "tcp_read_size",
"tcp_read_offer", "tcp_read_iov_size", "http2_send_message_size", "tcp_read_offer", "tcp_read_iov_size", "http2_send_message_size",
"server_cqs_checked",
}; };
const int grpc_stats_table_0[64] = { const int grpc_stats_table_0[64] = {
0, 1, 2, 3, 4, 6, 8, 11, 0, 1, 2, 3, 4, 6, 8, 11,
@ -81,6 +84,8 @@ const uint8_t grpc_stats_table_3[104] = {
24, 24, 25, 25, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 24, 24, 25, 25, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33,
34, 34, 35, 36, 36, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 42, 43, 34, 34, 35, 36, 36, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 42, 43,
44, 45, 45, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 51}; 44, 45, 45, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 51};
const int grpc_stats_table_4[8] = {0, 1, 2, 4, 8, 16, 32, 64};
const uint8_t grpc_stats_table_5[4] = {0, 1, 2, 3};
void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) { void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) {
value = GPR_CLAMP(value, 0, 16777216); value = GPR_CLAMP(value, 0, 16777216);
if (value < 5) { if (value < 5) {
@ -233,12 +238,39 @@ void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx,
grpc_stats_histo_find_bucket_slow( grpc_stats_histo_find_bucket_slow(
(exec_ctx), value, grpc_stats_table_0, 64)); (exec_ctx), value, grpc_stats_table_0, 64));
} }
const int grpc_stats_histo_buckets[6] = {64, 64, 64, 64, 64, 64}; void grpc_stats_inc_server_cqs_checked(grpc_exec_ctx *exec_ctx, int value) {
const int grpc_stats_histo_start[6] = {0, 64, 128, 192, 256, 320}; value = GPR_CLAMP(value, 0, 64);
const int *const grpc_stats_histo_bucket_boundaries[6] = { if (value < 3) {
GRPC_STATS_INC_HISTOGRAM((exec_ctx),
GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, value);
return;
}
union {
double dbl;
uint64_t uint;
} _val, _bkt;
_val.dbl = value;
if (_val.uint < 4627448617123184640ull) {
int bucket =
grpc_stats_table_5[((_val.uint - 4613937818241073152ull) >> 52)] + 3;
_bkt.dbl = grpc_stats_table_4[bucket];
bucket -= (_val.uint < _bkt.uint);
GRPC_STATS_INC_HISTOGRAM((exec_ctx),
GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED, bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED,
grpc_stats_histo_find_bucket_slow(
(exec_ctx), value, grpc_stats_table_4, 8));
}
const int grpc_stats_histo_buckets[7] = {64, 64, 64, 64, 64, 64, 8};
const int grpc_stats_histo_start[7] = {0, 64, 128, 192, 256, 320, 384};
const int *const grpc_stats_histo_bucket_boundaries[7] = {
grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0,
grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0, grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0,
grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0}; grpc_stats_table_4};
void (*const grpc_stats_inc_histogram[6])(grpc_exec_ctx *exec_ctx, int x) = { void (*const grpc_stats_inc_histogram[7])(grpc_exec_ctx *exec_ctx, int x) = {
grpc_stats_inc_tcp_write_size, grpc_stats_inc_tcp_write_iov_size, grpc_stats_inc_tcp_write_size, grpc_stats_inc_tcp_write_iov_size,
grpc_stats_inc_tcp_read_size, grpc_stats_inc_tcp_read_offer, grpc_stats_inc_tcp_read_size, grpc_stats_inc_tcp_read_offer,
grpc_stats_inc_tcp_read_iov_size, grpc_stats_inc_http2_send_message_size}; grpc_stats_inc_tcp_read_iov_size, grpc_stats_inc_http2_send_message_size,
grpc_stats_inc_server_cqs_checked};

@ -50,6 +50,8 @@ typedef enum {
GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF, GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF,
GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED, GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED,
GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED, GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED,
GRPC_STATS_COUNTER_SERVER_REQUESTED_CALLS,
GRPC_STATS_COUNTER_SERVER_SLOWPATH_REQUESTS_QUEUED,
GRPC_STATS_COUNTER_COUNT GRPC_STATS_COUNTER_COUNT
} grpc_stats_counters; } grpc_stats_counters;
extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT];
@ -60,6 +62,7 @@ typedef enum {
GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, GRPC_STATS_HISTOGRAM_TCP_READ_OFFER,
GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE,
GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE,
GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED,
GRPC_STATS_HISTOGRAM_COUNT GRPC_STATS_HISTOGRAM_COUNT
} grpc_stats_histograms; } grpc_stats_histograms;
extern const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT]; extern const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT];
@ -76,7 +79,9 @@ typedef enum {
GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE_BUCKETS = 64, GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE_BUCKETS = 64,
GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_FIRST_SLOT = 320, GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_FIRST_SLOT = 320,
GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_BUCKETS = 64, GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_BUCKETS = 64,
GRPC_STATS_HISTOGRAM_BUCKETS = 384 GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED_FIRST_SLOT = 384,
GRPC_STATS_HISTOGRAM_SERVER_CQS_CHECKED_BUCKETS = 8,
GRPC_STATS_HISTOGRAM_BUCKETS = 392
} grpc_stats_histogram_constants; } grpc_stats_histogram_constants;
#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ #define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED)
@ -139,6 +144,11 @@ typedef enum {
GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED) GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED)
#define GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(exec_ctx) \ #define GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(exec_ctx) \
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED)
#define GRPC_STATS_INC_SERVER_REQUESTED_CALLS(exec_ctx) \
GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_REQUESTED_CALLS)
#define GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(exec_ctx) \
GRPC_STATS_INC_COUNTER((exec_ctx), \
GRPC_STATS_COUNTER_SERVER_SLOWPATH_REQUESTS_QUEUED)
#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ #define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \
grpc_stats_inc_tcp_write_size((exec_ctx), (int)(value)) grpc_stats_inc_tcp_write_size((exec_ctx), (int)(value))
void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int x); void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int x);
@ -157,10 +167,13 @@ void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(exec_ctx, value) \ #define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(exec_ctx, value) \
grpc_stats_inc_http2_send_message_size((exec_ctx), (int)(value)) grpc_stats_inc_http2_send_message_size((exec_ctx), (int)(value))
void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, int x); void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, int x);
extern const int grpc_stats_histo_buckets[6]; #define GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, value) \
extern const int grpc_stats_histo_start[6]; grpc_stats_inc_server_cqs_checked((exec_ctx), (int)(value))
extern const int *const grpc_stats_histo_bucket_boundaries[6]; void grpc_stats_inc_server_cqs_checked(grpc_exec_ctx *exec_ctx, int x);
extern void (*const grpc_stats_inc_histogram[6])(grpc_exec_ctx *exec_ctx, extern const int grpc_stats_histo_buckets[7];
extern const int grpc_stats_histo_start[7];
extern const int *const grpc_stats_histo_bucket_boundaries[7];
extern void (*const grpc_stats_inc_histogram[7])(grpc_exec_ctx *exec_ctx,
int x); int x);
#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */

@ -65,3 +65,9 @@
- counter: executor_scheduled_to_self - counter: executor_scheduled_to_self
- counter: executor_wakeup_initiated - counter: executor_wakeup_initiated
- counter: executor_queue_drained - counter: executor_queue_drained
# server
- counter: server_requested_calls
- histogram: server_cqs_checked
buckets: 8
max: 64
- counter: server_slowpath_requests_queued

@ -29,6 +29,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
@ -538,6 +539,7 @@ static void publish_new_rpc(grpc_exec_ctx *exec_ctx, void *arg,
if (request_id == -1) { if (request_id == -1) {
continue; continue;
} else { } else {
GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, i);
gpr_mu_lock(&calld->mu_state); gpr_mu_lock(&calld->mu_state);
calld->state = ACTIVATED; calld->state = ACTIVATED;
gpr_mu_unlock(&calld->mu_state); gpr_mu_unlock(&calld->mu_state);
@ -548,6 +550,7 @@ static void publish_new_rpc(grpc_exec_ctx *exec_ctx, void *arg,
} }
/* no cq to take the request found: queue it on the slow list */ /* no cq to take the request found: queue it on the slow list */
GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED(exec_ctx);
gpr_mu_lock(&server->mu_call); gpr_mu_lock(&server->mu_call);
gpr_mu_lock(&calld->mu_state); gpr_mu_lock(&calld->mu_state);
calld->state = PENDING; calld->state = PENDING;
@ -1429,6 +1432,7 @@ grpc_call_error grpc_server_request_call(
grpc_call_error error; grpc_call_error error;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
requested_call *rc = gpr_malloc(sizeof(*rc)); requested_call *rc = gpr_malloc(sizeof(*rc));
GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx);
GRPC_API_TRACE( GRPC_API_TRACE(
"grpc_server_request_call(" "grpc_server_request_call("
"server=%p, call=%p, details=%p, initial_metadata=%p, " "server=%p, call=%p, details=%p, initial_metadata=%p, "
@ -1475,6 +1479,7 @@ grpc_call_error grpc_server_request_registered_call(
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
requested_call *rc = gpr_malloc(sizeof(*rc)); requested_call *rc = gpr_malloc(sizeof(*rc));
registered_method *rm = rmp; registered_method *rm = rmp;
GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx);
GRPC_API_TRACE( GRPC_API_TRACE(
"grpc_server_request_registered_call(" "grpc_server_request_registered_call("
"server=%p, rmp=%p, call=%p, deadline=%p, initial_metadata=%p, " "server=%p, rmp=%p, call=%p, deadline=%p, initial_metadata=%p, "

Loading…
Cancel
Save