#! /bin/sh /usr/share/dpatch/dpatch-run ## request_per_seconds.dpatch by ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Small patch for add request/sec in ngx_http_stub_status_module.c @DPATCH@ diff -r b7172015ac8d src/event/ngx_event.c --- a/src/event/ngx_event.c Mon Apr 28 18:18:26 2008 +0400 +++ b/src/event/ngx_event.c Sun May 04 20:41:34 2008 +0400 @@ -71,6 +71,12 @@ ngx_atomic_t *ngx_stat_reading = &ngx_stat_reading0; ngx_atomic_t ngx_stat_writing0; ngx_atomic_t *ngx_stat_writing = &ngx_stat_writing0; +ngx_atomic_t ngx_stat_requests_per_seconds0; +ngx_atomic_t *ngx_stat_requests_per_seconds = &ngx_stat_requests_per_seconds0; +ngx_atomic_t ngx_stat_requests_last_seconds0; +ngx_atomic_t *ngx_stat_requests_last_seconds = &ngx_stat_requests_last_seconds0; +ngx_atomic_t ngx_stat_requests_last0; +ngx_atomic_t *ngx_stat_requests_last = &ngx_stat_requests_last0; #endif @@ -501,7 +507,10 @@ + cl /* ngx_stat_requests */ + cl /* ngx_stat_active */ + cl /* ngx_stat_reading */ - + cl; /* ngx_stat_writing */ + + cl /* ngx_stat_writing */ + + cl /* ngx_stat_requests_per_seconds */ + + cl /* ngx_stat_requests_last_seconds */ + + cl; /* ngx_stat_requests_last */ #endif @@ -532,7 +541,9 @@ ngx_stat_active = (ngx_atomic_t *) (shared + 5 * cl); ngx_stat_reading = (ngx_atomic_t *) (shared + 6 * cl); ngx_stat_writing = (ngx_atomic_t *) (shared + 7 * cl); - + ngx_stat_requests_per_seconds = (ngx_atomic_t *) (shared + 8 * cl); + ngx_stat_requests_last_seconds = (ngx_atomic_t *) (shared + 9 * cl); + ngx_stat_requests_last = (ngx_atomic_t *) (shared + 10 * cl); #endif *ngx_connection_counter = 1; diff -r b7172015ac8d src/event/ngx_event.h --- a/src/event/ngx_event.h Mon Apr 28 18:18:26 2008 +0400 +++ b/src/event/ngx_event.h Sun May 04 20:41:34 2008 +0400 @@ -485,6 +485,10 @@ extern ngx_atomic_t *ngx_stat_active; extern ngx_atomic_t *ngx_stat_reading; extern ngx_atomic_t *ngx_stat_writing; +extern ngx_atomic_t *ngx_stat_requests_per_seconds; +extern ngx_atomic_t *ngx_stat_requests_last_seconds; +extern ngx_atomic_t *ngx_stat_requests_last; + #endif diff -r b7172015ac8d src/http/modules/ngx_http_stub_status_module.c --- a/src/http/modules/ngx_http_stub_status_module.c Mon Apr 28 18:18:26 2008 +0400 +++ b/src/http/modules/ngx_http_stub_status_module.c Sun May 04 20:41:34 2008 +0400 @@ -63,7 +63,7 @@ ngx_int_t rc; ngx_buf_t *b; ngx_chain_t out; - ngx_atomic_int_t ap, hn, ac, rq, rd, wr; + ngx_atomic_int_t ap, hn, ac, rq, rd, wr, rp; if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) { return NGX_HTTP_NOT_ALLOWED; @@ -91,7 +91,8 @@ size = sizeof("Active connections: \n") + NGX_ATOMIC_T_LEN + sizeof("server accepts handled requests\n") - 1 + 6 + 3 * NGX_ATOMIC_T_LEN - + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN; + + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN + + sizeof("Request/sec: \n") + NGX_ATOMIC_T_LEN; b = ngx_create_temp_buf(r->pool, size); if (b == NULL) { @@ -107,6 +108,7 @@ rq = *ngx_stat_requests; rd = *ngx_stat_reading; wr = *ngx_stat_writing; + rp = *ngx_stat_requests_per_seconds; b->last = ngx_sprintf(b->last, "Active connections: %uA \n", ac); @@ -117,6 +119,8 @@ b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n", rd, wr, ac - (rd + wr)); + b->last = ngx_sprintf(b->last, "Request/sec: %uA \n", + rp); r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = b->last - b->pos; diff -r b7172015ac8d src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c Mon Apr 28 18:18:26 2008 +0400 +++ b/src/http/ngx_http_request.c Sun May 04 20:41:34 2008 +0400 @@ -230,6 +230,13 @@ ngx_http_core_srv_conf_t *cscf; ngx_http_core_loc_conf_t *clcf; ngx_http_core_main_conf_t *cmcf; +#if (NGX_STAT_STUB) + ngx_int_t ct; + ngx_atomic_int_t ls; + ngx_atomic_int_t sr; + ngx_atomic_int_t rl; +#endif + #if (NGX_STAT_STUB) ngx_atomic_fetch_add(ngx_stat_reading, -1); @@ -446,6 +453,26 @@ ngx_atomic_fetch_add(ngx_stat_reading, 1); r->stat_reading = 1; ngx_atomic_fetch_add(ngx_stat_requests, 1); + + ct = ngx_time(); + ls = *ngx_stat_requests_last_seconds; + + if (ct > ls && + (ngx_accept_mutex_ptr == NULL || + (ngx_accept_mutex_ptr && ngx_atomic_cmp_set(ngx_accept_mutex_ptr, 0, ngx_pid)))) { + + sr = *ngx_stat_requests; + rl = *ngx_stat_requests_last; + + ngx_log_error(NGX_LOG_INFO, c->log, 0, "ct:%d ls:%d sr:%d rl:%d", ct, ls, sr, rl); + *ngx_stat_requests_per_seconds = (sr - rl) / (ct - ls); + *ngx_stat_requests_last = sr; + *ngx_stat_requests_last_seconds = ct; + + if (ngx_accept_mutex_ptr) { + ngx_atomic_cmp_set(ngx_accept_mutex_ptr, ngx_pid, 0); + } + } #endif rev->handler(rev);