[core] reset connection counters per connection
reset connection counters per connection, not per request adjust mod_accesslog and mod_rrdtool usage continue to count mod_rrdtool per request rather than per connection so that data is updated after each request, rather than aggregated to the end of a potentially long-lived connection with many keep-alives.personal/stbuehler/tests-path
parent
8eea3bd014
commit
afc2025d8e
|
@ -228,6 +228,8 @@ static void connection_fdwaitqueue_append(connection *con) {
|
|||
connection_list_append(&con->srv->fdwaitqueue, con);
|
||||
}
|
||||
|
||||
static void request_reset (request_st * const r);
|
||||
|
||||
static void connection_handle_response_end_state(request_st * const r, connection * const con) {
|
||||
/* call request_done hook if http_status set (e.g. to log request) */
|
||||
/* (even if error, connection dropped, as long as http_status is set) */
|
||||
|
@ -242,7 +244,11 @@ static void connection_handle_response_end_state(request_st * const r, connectio
|
|||
}
|
||||
|
||||
if (r->keep_alive) {
|
||||
connection_reset(con);
|
||||
request_reset(r);
|
||||
con->is_readable = 1; /* potentially trigger optimistic read */
|
||||
/*(accounting used by mod_accesslog for HTTP/1.0 and HTTP/1.1)*/
|
||||
r->bytes_read_ckpt = con->bytes_read;
|
||||
r->bytes_written_ckpt = con->bytes_written;
|
||||
#if 0
|
||||
r->start_ts = con->read_idle_ts = log_epoch_secs;
|
||||
#endif
|
||||
|
@ -764,6 +770,8 @@ request_reset (request_st * const r) {
|
|||
static void connection_reset(connection *con) {
|
||||
request_st * const r = &con->request;
|
||||
request_reset(r);
|
||||
r->bytes_read_ckpt = 0;
|
||||
r->bytes_written_ckpt = 0;
|
||||
con->is_readable = 1;
|
||||
|
||||
con->bytes_written = 0;
|
||||
|
@ -875,7 +883,7 @@ static int connection_handle_read_state(connection * const con) {
|
|||
int pipelined_request_start = 0;
|
||||
unsigned short hoff[8192]; /* max num header lines + 3; 16k on stack */
|
||||
|
||||
if (con->request_count > 1 && 0 == con->bytes_read) {
|
||||
if (con->request_count > 1 && con->bytes_read == r->bytes_read_ckpt) {
|
||||
keepalive_request_start = 1;
|
||||
if (NULL != c) { /* !chunkqueue_is_empty(cq)) */
|
||||
pipelined_request_start = 1;
|
||||
|
@ -931,7 +939,7 @@ static int connection_handle_read_state(connection * const con) {
|
|||
} while ((c = connection_read_header_more(con, cq, c, clen)));
|
||||
|
||||
if (keepalive_request_start) {
|
||||
if (0 != con->bytes_read) {
|
||||
if (con->bytes_read > r->bytes_read_ckpt) {
|
||||
/* update r->start_ts timestamp when first byte of
|
||||
* next request is received on a keep-alive connection */
|
||||
r->start_ts = log_epoch_secs;
|
||||
|
|
|
@ -981,13 +981,16 @@ static int log_access_record (const request_st * const r, buffer * const b, form
|
|||
break;
|
||||
|
||||
case FORMAT_BYTES_OUT_NO_HEADER:
|
||||
if (con->bytes_written > 0) {
|
||||
off_t bytes = con->bytes_written - (off_t)r->resp_header_len;
|
||||
{
|
||||
off_t bytes = con->bytes_written - r->bytes_written_ckpt;
|
||||
if (bytes > 0) {
|
||||
bytes -= (off_t)r->resp_header_len;
|
||||
buffer_append_int(b, bytes > 0 ? bytes : 0);
|
||||
} else {
|
||||
buffer_append_string_len(b, CONST_STR_LEN("-"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FORMAT_HEADER:
|
||||
if (NULL != (vb = http_header_request_get(r, HTTP_HEADER_UNSPECIFIED, CONST_BUF_LEN(&f->string)))) {
|
||||
accesslog_append_escaped(b, vb);
|
||||
|
@ -1018,19 +1021,25 @@ static int log_access_record (const request_st * const r, buffer * const b, form
|
|||
}
|
||||
break;
|
||||
case FORMAT_BYTES_OUT:
|
||||
if (con->bytes_written > 0) {
|
||||
buffer_append_int(b, con->bytes_written);
|
||||
{
|
||||
off_t bytes = con->bytes_written - r->bytes_written_ckpt;
|
||||
if (bytes > 0) {
|
||||
buffer_append_int(b, bytes);
|
||||
} else {
|
||||
buffer_append_string_len(b, CONST_STR_LEN("-"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FORMAT_BYTES_IN:
|
||||
if (con->bytes_read > 0) {
|
||||
buffer_append_int(b, con->bytes_read);
|
||||
{
|
||||
off_t bytes = con->bytes_read - r->bytes_read_ckpt;
|
||||
if (bytes > 0) {
|
||||
buffer_append_int(b, bytes);
|
||||
} else {
|
||||
buffer_append_string_len(b, CONST_STR_LEN("-"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FORMAT_SERVER_NAME:
|
||||
if (!buffer_string_is_empty(r->server_name)) {
|
||||
buffer_append_string_buffer(b, r->server_name);
|
||||
|
|
|
@ -424,8 +424,8 @@ REQUESTDONE_FUNC(mod_rrd_account) {
|
|||
rrd_config * const rrd = p->conf.rrd;
|
||||
if (NULL == rrd) return HANDLER_GO_ON;
|
||||
++rrd->requests;
|
||||
rrd->bytes_written += r->con->bytes_written;
|
||||
rrd->bytes_read += r->con->bytes_read;
|
||||
rrd->bytes_written += (r->con->bytes_written - r->bytes_written_ckpt);
|
||||
rrd->bytes_read += (r->con->bytes_read - r->bytes_read_ckpt);
|
||||
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
|
|
|
@ -178,6 +178,8 @@ struct request_st {
|
|||
buffer *tmp_buf; /* shared; same as srv->tmp_buf */
|
||||
response_dechunk *gw_dechunk;
|
||||
|
||||
off_t bytes_written_ckpt; /* used by mod_accesslog */
|
||||
off_t bytes_read_ckpt; /* used by mod_accesslog */
|
||||
struct timespec start_hp;
|
||||
time_t start_ts;
|
||||
|
||||
|
|
Loading…
Reference in New Issue