Status: introduced the "ngx_stat_waiting" counter.
And corresponding variable $connections_waiting was added.
Previously, waiting connections were counted as the difference between
active connections and the sum of reading and writing connections.
That made it impossible to count more than one request in one connection
as reading or writing (as is the case for SPDY).
Also, we no longer count connections in handshake state as waiting.
Valentin Bartenev
9 years ago
969 | 969 | |
970 | 970 | if (c->reusable) { |
971 | 971 | ngx_queue_remove(&c->queue); |
972 | ||
973 | #if (NGX_STAT_STUB) | |
974 | (void) ngx_atomic_fetch_add(ngx_stat_waiting, -1); | |
975 | #endif | |
972 | 976 | } |
973 | 977 | |
974 | 978 | c->reusable = reusable; |
978 | 982 | |
979 | 983 | ngx_queue_insert_head( |
980 | 984 | (ngx_queue_t *) &ngx_cycle->reusable_connections_queue, &c->queue); |
985 | ||
986 | #if (NGX_STAT_STUB) | |
987 | (void) ngx_atomic_fetch_add(ngx_stat_waiting, 1); | |
988 | #endif | |
981 | 989 | } |
982 | 990 | } |
983 | 991 |
72 | 72 | ngx_atomic_t *ngx_stat_reading = &ngx_stat_reading0; |
73 | 73 | ngx_atomic_t ngx_stat_writing0; |
74 | 74 | ngx_atomic_t *ngx_stat_writing = &ngx_stat_writing0; |
75 | ngx_atomic_t ngx_stat_waiting0; | |
76 | ngx_atomic_t *ngx_stat_waiting = &ngx_stat_waiting0; | |
75 | 77 | |
76 | 78 | #endif |
77 | 79 | |
510 | 512 | + cl /* ngx_stat_requests */ |
511 | 513 | + cl /* ngx_stat_active */ |
512 | 514 | + cl /* ngx_stat_reading */ |
513 | + cl; /* ngx_stat_writing */ | |
515 | + cl /* ngx_stat_writing */ | |
516 | + cl; /* ngx_stat_waiting */ | |
514 | 517 | |
515 | 518 | #endif |
516 | 519 | |
557 | 560 | ngx_stat_active = (ngx_atomic_t *) (shared + 6 * cl); |
558 | 561 | ngx_stat_reading = (ngx_atomic_t *) (shared + 7 * cl); |
559 | 562 | ngx_stat_writing = (ngx_atomic_t *) (shared + 8 * cl); |
563 | ngx_stat_waiting = (ngx_atomic_t *) (shared + 9 * cl); | |
560 | 564 | |
561 | 565 | #endif |
562 | 566 |
510 | 510 | extern ngx_atomic_t *ngx_stat_active; |
511 | 511 | extern ngx_atomic_t *ngx_stat_reading; |
512 | 512 | extern ngx_atomic_t *ngx_stat_writing; |
513 | extern ngx_atomic_t *ngx_stat_waiting; | |
513 | 514 | |
514 | 515 | #endif |
515 | 516 |
72 | 72 | { ngx_string("connections_writing"), NULL, ngx_http_stub_status_variable, |
73 | 73 | 2, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
74 | 74 | |
75 | { ngx_string("connections_waiting"), NULL, ngx_http_stub_status_variable, | |
76 | 3, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
77 | ||
75 | 78 | { ngx_null_string, NULL, NULL, 0, 0, 0 } |
76 | 79 | }; |
77 | 80 | |
82 | 85 | ngx_int_t rc; |
83 | 86 | ngx_buf_t *b; |
84 | 87 | ngx_chain_t out; |
85 | ngx_atomic_int_t ap, hn, ac, rq, rd, wr; | |
88 | ngx_atomic_int_t ap, hn, ac, rq, rd, wr, wa; | |
86 | 89 | |
87 | 90 | if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) { |
88 | 91 | return NGX_HTTP_NOT_ALLOWED; |
125 | 128 | rq = *ngx_stat_requests; |
126 | 129 | rd = *ngx_stat_reading; |
127 | 130 | wr = *ngx_stat_writing; |
131 | wa = *ngx_stat_waiting; | |
128 | 132 | |
129 | 133 | b->last = ngx_sprintf(b->last, "Active connections: %uA \n", ac); |
130 | 134 | |
134 | 138 | b->last = ngx_sprintf(b->last, " %uA %uA %uA \n", ap, hn, rq); |
135 | 139 | |
136 | 140 | b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n", |
137 | rd, wr, ac - (rd + wr)); | |
141 | rd, wr, wa); | |
138 | 142 | |
139 | 143 | r->headers_out.status = NGX_HTTP_OK; |
140 | 144 | r->headers_out.content_length_n = b->last - b->pos; |
174 | 178 | |
175 | 179 | case 2: |
176 | 180 | value = *ngx_stat_writing; |
181 | break; | |
182 | ||
183 | case 3: | |
184 | value = *ngx_stat_waiting; | |
177 | 185 | break; |
178 | 186 | |
179 | 187 | /* suppress warning */ |