Calculates the current load in the thread pool, making a decision whether to run its own process and continue to rob the task
Let's focus on Ngx_trylock_accept_mutex, the function in which
ngx_int_t
Ngx_trylock_accept_mutex (ngx_cycle_t *cycle)
{
Add code here, if the thread pool is busy and does not allow continuation of the accept, return directly
if (Ngx_shmtx_trylock (&ngx_accept_mutex)) {
if (ngx_enable_accept_events (cycle) = = Ngx_error){//here If the lock succeeds, then call Ngx_enable_accept_events, will listen FD registered to their own epoll, so can grab the accept event, I modified here, if the process is very busy, then directly return (that is, will not grab accept, and will not block the program flow)
Ngx_shmtx_unlock (&ngx_accept_mutex);
return ngx_error;
}
Ngx_accept_mutex_held = 1;
return NGX_OK;
}
if (Ngx_accept_mutex_held) {
if (ngx_disable_accept_events (cycle) = = Ngx_error) {
return ngx_error;
}
Ngx_accept_mutex_held = 0;
}
return NGX_OK;
}
Nginx load balancing for multiple processes (judged by thread pool)