Skip to content

Commit

Permalink
New connections_above_limit() heuristic?
Browse files Browse the repository at this point in the history
  • Loading branch information
ylavic committed Feb 9, 2022
1 parent fc977a4 commit 1112038
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions server/mpm/event/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,26 +660,31 @@ static int enable_listensocks(void)
return 1;
}

static APR_INLINE apr_uint32_t listeners_disabled(void)
static APR_INLINE int listeners_disabled(void)
{
return apr_atomic_read32(&listensocks_disabled);
return apr_atomic_read32(&listensocks_disabled) != 0;
}

static APR_INLINE int connections_above_limit(int *busy)
static APR_INLINE apr_uint32_t u32_min(apr_uint32_t u1, apr_uint32_t u2)
{
apr_uint32_t i_count = ap_queue_info_num_idlers(worker_queue_info);
if (i_count > 0) {
apr_uint32_t c_count = apr_atomic_read32(&connection_count);
apr_uint32_t l_count = apr_atomic_read32(&lingering_count);
if (c_count <= l_count
/* Off by 'listeners_disabled()' to avoid flip flop */
|| c_count - l_count < (apr_uint32_t)threads_per_child +
(i_count - listeners_disabled()) *
async_factor) {
return (u1 < u2) ? u1 : u2;
}

static int connections_above_limit(int *busy)
{
#ifndef LISTEN_OFF_RATE
#define LISTEN_OFF_RATE 4u
#endif
apr_uint32_t t_p_c = (apr_uint32_t)threads_per_child;
apr_uint32_t i_num = ap_queue_info_num_idlers(worker_queue_info);
apr_uint32_t i_min = listeners_disabled() ? t_p_c / LISTEN_OFF_RATE : 0;
if (i_num > i_min) { /* amortize disable=>enable_listensocks() switch */
apr_uint32_t t_num = t_p_c + i_num * async_factor;
if (apr_atomic_read32(pending_q->total) <= t_num) {
return 0;
}
}
else if (busy) {
else if (busy && !i_num) {
*busy = 1;
}
return 1;
Expand Down

0 comments on commit 1112038

Please sign in to comment.