Skip to content

Commit

Permalink
mpm_event,mod_http2,mod_status: Follow up to r1918257: CONN_STATE_ASY…
Browse files Browse the repository at this point in the history
…NC_WAITIO.

Per discussion on PR #449, have a separate state for returning the connection
to the MPM to wait for an IO (namely CONN_STATE_ASYNC_WAITIO), rather than
(ab)using CONN_STATE_PROCESSING.

This removes the need for AGAIN added in r1918257 (for now), and AP_MPMQ_CAN_AGAIN
is renamed to AP_MPMQ_CAN_WAITIO.

This is also the state that mod_status accounts for, so rename ->processing
to ->wait_io in process_score (shows as "wait-io" in mod_status and mod_lua).



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1918482 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ylavic authored and pull[bot] committed Jul 20, 2024
1 parent 83f1fda commit 1910649
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 76 deletions.
7 changes: 4 additions & 3 deletions include/ap_mmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,10 @@
* 20211221.17 (2.5.1-dev) Add ap_proxy_worker_get_name()
* 20211221.18 (2.5.1-dev) Add ap_regexec_ex()
* 20211221.19 (2.5.1-dev) Add AP_REG_NOTEMPTY_ATSTART
* 20211221.20 (2.5.1-dev) Add CONN_STATE_KEEPALIVE and CONN_STATE_PROCESSING
* 20211221.21 (2.5.1-dev) Add processing field struct process_score
* 20211221.22 (2.5.1-dev) Add AGAIN, AP_MPMQ_CAN_AGAIN.
* 20211221.20 (2.5.1-dev) Add CONN_STATE_ASYNC_WAITIO, CONN_STATE_KEEPALIVE
* and CONN_STATE_PROCESSING
* 20211221.21 (2.5.1-dev) Add wait_io field to struct process_score
* 20211221.22 (2.5.1-dev) Add AP_MPMQ_CAN_WAITIO
*/

#define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
Expand Down
4 changes: 2 additions & 2 deletions include/ap_mpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
#define AP_MPMQ_CAN_SUSPEND 17
/** MPM supports additional pollfds */
#define AP_MPMQ_CAN_POLL 18
/** MPM reacts to AGAIN response */
#define AP_MPMQ_CAN_AGAIN 19
/** MPM supports CONN_STATE_ASYNC_WAITIO */
#define AP_MPMQ_CAN_WAITIO 19
/** @} */

/**
Expand Down
14 changes: 6 additions & 8 deletions include/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,6 @@ AP_DECLARE(const char *) ap_get_server_built(void);
*/
#define SUSPENDED -3 /**< Module will handle the remainder of the request.
* The core will never invoke the request again */
#define AGAIN -4 /**< Module wants to be called again when more
* data is available.
*/

/** Returned by the bottom-most filter if no data was written.
* @see ap_pass_brigade(). */
Expand Down Expand Up @@ -1322,18 +1319,19 @@ struct conn_slave_rec {
*/
typedef enum {
CONN_STATE_KEEPALIVE, /* Kept alive in the MPM (using KeepAliveTimeout) */
CONN_STATE_PROCESSING, /* Processed by process_connection() hooks, returning
* AGAIN to the MPM in this state will make it wait for
* the connection to be readable or writable according to
* CONN_SENSE_WANT_READ or CONN_SENSE_WANT_WRITE respectively,
* where Timeout applies */
CONN_STATE_PROCESSING, /* Processed by process_connection hooks */
CONN_STATE_HANDLER, /* Processed by the modules handlers */
CONN_STATE_WRITE_COMPLETION, /* Flushed by the MPM before entering CONN_STATE_KEEPALIVE */
CONN_STATE_SUSPENDED, /* Suspended in the MPM until ap_run_resume_suspended() */
CONN_STATE_LINGER, /* MPM flushes then closes the connection with lingering */
CONN_STATE_LINGER_NORMAL, /* MPM has started lingering close with normal timeout */
CONN_STATE_LINGER_SHORT, /* MPM has started lingering close with short timeout */

CONN_STATE_ASYNC_WAITIO, /* Returning this state to the MPM will make it wait for
* the connection to be readable or writable according to
* c->cs->sense (resp. CONN_SENSE_WANT_READ or _WRITE),
* using the configured Timeout */

CONN_STATE_NUM, /* Number of states (keep here before aliases) */

/* Aliases (legacy) */
Expand Down
3 changes: 1 addition & 2 deletions include/scoreboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ struct process_score {
apr_uint32_t lingering_close; /* async connections in lingering close */
apr_uint32_t keep_alive; /* async connections in keep alive */
apr_uint32_t suspended; /* connections suspended by some module */
apr_uint32_t processing; /* async connections in processing (returned
to the MPM for POLLIN/POLLOUT) */
apr_uint32_t wait_io; /* async connections waiting an IO in the MPM */
};

/* Scoreboard is now in 'local' memory, since it isn't updated once created,
Expand Down
14 changes: 7 additions & 7 deletions modules/generators/mod_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ static int status_handler(request_rec *r)
ap_rputs("</dl>", r);

if (is_async) {
int processing = 0, write_completion = 0, lingering_close = 0, keep_alive = 0,
int wait_io = 0, write_completion = 0, lingering_close = 0, keep_alive = 0,
connections = 0, stopping = 0, procs = 0;
if (!short_report)
ap_rputs("\n\n<table rules=\"all\" cellpadding=\"1%\">\n"
Expand All @@ -576,13 +576,13 @@ static int status_handler(request_rec *r)
"<th colspan=\"3\">Async connections</th></tr>\n"
"<tr><th>total</th><th>accepting</th>"
"<th>busy</th><th>graceful</th><th>idle</th>"
"<th>processing</th><th>writing</th><th>keep-alive</th>"
"<th>wait-io</th><th>writing</th><th>keep-alive</th>"
"<th>closing</th></tr>\n", r);
for (i = 0; i < server_limit; ++i) {
ps_record = ap_get_scoreboard_process(i);
if (ps_record->pid) {
connections += ps_record->connections;
processing += ps_record->processing;
wait_io += ps_record->wait_io;
write_completion += ps_record->write_completion;
keep_alive += ps_record->keep_alive;
lingering_close += ps_record->lingering_close;
Expand Down Expand Up @@ -611,7 +611,7 @@ static int status_handler(request_rec *r)
thread_busy_buffer[i],
thread_graceful_buffer[i],
thread_idle_buffer[i],
ps_record->processing,
ps_record->wait_io,
ps_record->write_completion,
ps_record->keep_alive,
ps_record->lingering_close);
Expand All @@ -628,20 +628,20 @@ static int status_handler(request_rec *r)
procs, stopping,
connections,
busy, graceful, idle,
processing, write_completion, keep_alive,
wait_io, write_completion, keep_alive,
lingering_close);
}
else {
ap_rprintf(r, "Processes: %d\n"
"Stopping: %d\n"
"ConnsTotal: %d\n"
"ConnsAsyncProcessing: %d\n"
"ConnsAsyncWaitIO: %d\n"
"ConnsAsyncWriting: %d\n"
"ConnsAsyncKeepAlive: %d\n"
"ConnsAsyncClosing: %d\n",
procs, stopping,
connections,
processing, write_completion, keep_alive,
wait_io, write_completion, keep_alive,
lingering_close);
}
}
Expand Down
18 changes: 8 additions & 10 deletions modules/http2/h2_c1.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

static struct h2_workers *workers;

static int async_mpm, mpm_can_again;
static int async_mpm, mpm_can_waitio;

APR_OPTIONAL_FN_TYPE(ap_logio_add_bytes_in) *h2_c_logio_add_bytes_in;
APR_OPTIONAL_FN_TYPE(ap_logio_add_bytes_out) *h2_c_logio_add_bytes_out;
Expand All @@ -61,9 +61,9 @@ apr_status_t h2_c1_child_init(apr_pool_t *pool, server_rec *s)
/* some MPMs do not implemnent this */
async_mpm = 0;
}
#ifdef AP_MPMQ_CAN_AGAIN
if (!async_mpm || ap_mpm_query(AP_MPMQ_CAN_AGAIN, &mpm_can_again)) {
mpm_can_again = 0;
#ifdef AP_MPMQ_CAN_WAITIO
if (!async_mpm || ap_mpm_query(AP_MPMQ_CAN_WAITIO, &mpm_can_waitio)) {
mpm_can_waitio = 0;
}
#endif

Expand Down Expand Up @@ -117,7 +117,6 @@ apr_status_t h2_c1_setup(conn_rec *c, request_rec *r, server_rec *s)

int h2_c1_run(conn_rec *c)
{
int rc = OK;
apr_status_t status;
int mpm_state = 0, keepalive = 0;
h2_conn_ctx_t *conn_ctx = h2_conn_ctx_get(c);
Expand Down Expand Up @@ -165,15 +164,14 @@ int h2_c1_run(conn_rec *c)
* See PR 63534.
*/
c->cs->sense = CONN_SENSE_WANT_READ;
#ifdef AP_MPMQ_CAN_AGAIN
if (mpm_can_again) {
#ifdef AP_MPMQ_CAN_WAITIO
if (mpm_can_waitio) {
/* This tells the MPM to wait for the connection to be
* readable (CONN_SENSE_WANT_READ) within the configured
* Timeout and then come back to the process_connection()
* hooks again when ready.
*/
c->cs->state = CONN_STATE_PROCESSING;
rc = AGAIN;
c->cs->state = CONN_STATE_ASYNC_WAITIO;
}
else
#endif
Expand All @@ -199,7 +197,7 @@ int h2_c1_run(conn_rec *c)
}
}

return rc;
return OK;
}

apr_status_t h2_c1_pre_close(struct h2_conn_ctx_t *ctx, conn_rec *c)
Expand Down
4 changes: 2 additions & 2 deletions modules/lua/lua_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,8 +1264,8 @@ static int lua_ap_scoreboard_process(lua_State *L)
lua_pushnumber(L, ps_record->suspended);
lua_settable(L, -3);

lua_pushstring(L, "processing");
lua_pushnumber(L, ps_record->processing);
lua_pushstring(L, "wait_io");
lua_pushnumber(L, ps_record->wait_io);
lua_settable(L, -3);

lua_pushstring(L, "write_completion");
Expand Down
Loading

0 comments on commit 1910649

Please sign in to comment.