# How nginx define a free worker?

**URL:** <https://www.ruby-forum.com/t/how-nginx-define-a-free-worker/224682>\
**Category:** NGINX\
**Created:** [November 21, 2012, 5:53pm UTC](https://www.ruby-forum.com/t/how-nginx-define-a-free-worker/224682 "2012-11-21T17:53:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 21, 2012, 5:53pm UTC](https://www.ruby-forum.com/t/how-nginx-define-a-free-worker/224682/1 "2012-11-21T17:53:10Z")

</div>

Hi,  
If I have n cores and I am running n nginx worker process how nginx  
will  
decide free worker for next connection?

1. Will it be doing round robin?

If it is not using round robin what method it use? Is there a way I can  
force it to use round robin method?  
regards  
Vivek G.

---

<div class="post-metadata">

**Author:** ![vivek112020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/8c91f0/32.png) [@vivek112020](https://www.ruby-forum.com/u/vivek112020)\
**Post date:** [November 21, 2012, 6:36pm UTC](https://www.ruby-forum.com/t/how-nginx-define-a-free-worker/224682/2 "2012-11-21T18:36:59Z")

</div>

On 11/21/12 20:51, Vivek G. wrote:

> If I have n cores and I am running n nginx worker process how nginx will decide  
> free worker for next connection?
> 
> 1. Will it be doing round robin?
> 
> If it is not using round robin what method it use? Is there a way I can force it  
> to use round robin method?  
> regards

Load distribution between worker processes affected by accept\_mutex

> **[Core functionality](http://nginx.org/en/docs/ngx_core_module.html#accept_mutex)**
>
> If accept\_mutex is enabled, worker processes will accept new connections by turn. Otherwise, all worker processes will be notified about new connections, and if volume of new connections is low, some of the worker processes may just waste system...

Default is to use accept mutex and if load is low, most request will be  
handled  
by one worker.

On heavy loaded server load destribution between worker processes will  
be more  
uniform.

You can switch off accept\_mutex and load will be more uniform even with  
low  
load, but all worker processes will be waken up on each new connection  
and only  
one worker can accept given connection:

> **[Thundering herd problem](https://en.wikipedia.org/wiki/Thundering_herd_problem)**
>
> The thundering herd problem is a performance-degrading phenomenon in computer science and computer networking that occurs when a large number of processes or threads are simultaneously awakened, typically in response to a specific event or the availability of a resource. However, only one process is able to respond to the event or access the new resource, causing most other processes to fail and go back to sleep. This unnecessary awakening consumes CPU and other system resources, potentially redu...

In case of nginx number of processes is usually low, and negative impact  
of  
accept\_mutex off should be low.

–  
Anton Y.

---

<div class="post-metadata">

**Author:** ![vivek112020](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/8c91f0/32.png) [@vivek112020](https://www.ruby-forum.com/u/vivek112020)\
**Post date:** [November 22, 2012, 3:49am UTC](https://www.ruby-forum.com/t/how-nginx-define-a-free-worker/224682/3 "2012-11-22T03:49:15Z")

</div>

I am running nginx with high number of worker. So I think disable  
accept\_mutex will cause high load on the system.  
Is there any other method I can choose in nginx like simple round robin  
b/w  
workers?

Posted at Nginx Forum:

> **[Re: How nginx define a free worker?](https://forum.nginx.org/read.php?2,233093,233111#msg-233111)**
>
> Hi, If I have n cores and I am running n nginx worker process how nginx will decide free worker for next connection? 1. Will it be doing round robin? If it is not using round robin what method it use? Is there a way I can force it to use round r
