Skip to content

Commit 1112038

Browse files
committed
New connections_above_limit() heuristic?
1 parent fc977a4 commit 1112038

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

server/mpm/event/event.c

+18-13
Original file line numberDiff line numberDiff line change
@@ -660,26 +660,31 @@ static int enable_listensocks(void)
660660
return 1;
661661
}
662662

663-
static APR_INLINE apr_uint32_t listeners_disabled(void)
663+
static APR_INLINE int listeners_disabled(void)
664664
{
665-
return apr_atomic_read32(&listensocks_disabled);
665+
return apr_atomic_read32(&listensocks_disabled) != 0;
666666
}
667667

668-
static APR_INLINE int connections_above_limit(int *busy)
668+
static APR_INLINE apr_uint32_t u32_min(apr_uint32_t u1, apr_uint32_t u2)
669669
{
670-
apr_uint32_t i_count = ap_queue_info_num_idlers(worker_queue_info);
671-
if (i_count > 0) {
672-
apr_uint32_t c_count = apr_atomic_read32(&connection_count);
673-
apr_uint32_t l_count = apr_atomic_read32(&lingering_count);
674-
if (c_count <= l_count
675-
/* Off by 'listeners_disabled()' to avoid flip flop */
676-
|| c_count - l_count < (apr_uint32_t)threads_per_child +
677-
(i_count - listeners_disabled()) *
678-
async_factor) {
670+
return (u1 < u2) ? u1 : u2;
671+
}
672+
673+
static int connections_above_limit(int *busy)
674+
{
675+
#ifndef LISTEN_OFF_RATE
676+
#define LISTEN_OFF_RATE 4u
677+
#endif
678+
apr_uint32_t t_p_c = (apr_uint32_t)threads_per_child;
679+
apr_uint32_t i_num = ap_queue_info_num_idlers(worker_queue_info);
680+
apr_uint32_t i_min = listeners_disabled() ? t_p_c / LISTEN_OFF_RATE : 0;
681+
if (i_num > i_min) { /* amortize disable=>enable_listensocks() switch */
682+
apr_uint32_t t_num = t_p_c + i_num * async_factor;
683+
if (apr_atomic_read32(pending_q->total) <= t_num) {
679684
return 0;
680685
}
681686
}
682-
else if (busy) {
687+
else if (busy && !i_num) {
683688
*busy = 1;
684689
}
685690
return 1;

0 commit comments

Comments
 (0)