Nginx load balancing for multiple processes (judged by thread pool)

Source: Internet
Author: User
Tags nginx load balancing

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.