|
32 | 32 | #include <netinet/tcp.h>
|
33 | 33 | #include <openssl/ssl.h>
|
34 | 34 | #include <sys/socket.h>
|
| 35 | +#include <sys/syscall.h> |
35 | 36 | #include <sys/types.h>
|
36 | 37 |
|
37 | 38 | #include "error.h"
|
38 | 39 | #include "event_loop.h"
|
39 | 40 | #include "global_data.h"
|
40 | 41 | #include "thread.h"
|
| 42 | +#include "utility.h" |
41 | 43 |
|
| 44 | +#define CONN_NUM_SAMPLE_PERIOD 2500 |
42 | 45 | #define DEFAULT_TCP_FASTOPEN_QUEUE_LEN 4096
|
43 | 46 |
|
44 | 47 | static void accept_connection(h2o_socket_t *listener, const char *err);
|
@@ -72,6 +75,7 @@ static void accept_connection(h2o_socket_t *listener, const char *err)
|
72 | 75 | if (!sock)
|
73 | 76 | break;
|
74 | 77 |
|
| 78 | + ctx->event_loop.accepted_conn_num++; |
75 | 79 | ctx->event_loop.conn_num++;
|
76 | 80 | sock->on_close.cb = on_close_connection;
|
77 | 81 | sock->on_close.data = &ctx->event_loop.conn_num;
|
@@ -277,11 +281,36 @@ static void start_accept_polling(const config_t *config,
|
277 | 281 |
|
278 | 282 | void event_loop(struct thread_context_t *ctx)
|
279 | 283 | {
|
| 284 | + uint64_t last_sample = 0; |
| 285 | + |
280 | 286 | while (!ctx->shutdown || ctx->event_loop.conn_num) {
|
281 | 287 | h2o_evloop_run(ctx->event_loop.h2o_ctx.loop, INT32_MAX);
|
282 | 288 | process_messages(&ctx->global_thread_data->h2o_receiver,
|
283 | 289 | &ctx->event_loop.local_messages);
|
| 290 | + |
| 291 | + const uint64_t now = h2o_now(ctx->event_loop.h2o_ctx.loop); |
| 292 | + |
| 293 | + if (now - last_sample > CONN_NUM_SAMPLE_PERIOD || last_sample > now) { |
| 294 | + const size_t i = ctx->event_loop.conn_num_sample_idx; |
| 295 | + |
| 296 | + ctx->event_loop.conn_num_sample[i] = ctx->event_loop.conn_num; |
| 297 | + ctx->event_loop.conn_num_sample_idx = |
| 298 | + (i + 1) % ARRAY_SIZE(ctx->event_loop.conn_num_sample); |
| 299 | + last_sample = now; |
| 300 | + } |
284 | 301 | }
|
| 302 | + |
| 303 | + flockfile(stdout); |
| 304 | + printf("Thread %ld statistics:\nAccepted connections: %zu\nConnection number samples: %zu", |
| 305 | + syscall(SYS_gettid), |
| 306 | + ctx->event_loop.accepted_conn_num, |
| 307 | + *ctx->event_loop.conn_num_sample); |
| 308 | + |
| 309 | + for (size_t i = 1; i < ARRAY_SIZE(ctx->event_loop.conn_num_sample); i++) |
| 310 | + printf(",%zu", ctx->event_loop.conn_num_sample[i]); |
| 311 | + |
| 312 | + putc_unlocked('\n', stdout); |
| 313 | + funlockfile(stdout); |
285 | 314 | }
|
286 | 315 |
|
287 | 316 | void free_event_loop(event_loop_t *event_loop, h2o_multithread_receiver_t *h2o_receiver)
|
|
0 commit comments