# POSIX semaphores patch

**URL:** <https://www.ruby-forum.com/t/posix-semaphores-patch/206541>\
**Category:** NGINX\
**Created:** [May 4, 2011, 1:08pm UTC](https://www.ruby-forum.com/t/posix-semaphores-patch/206541 "2011-05-04T13:08:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 4, 2011, 1:08pm UTC](https://www.ruby-forum.com/t/posix-semaphores-patch/206541/1 "2011-05-04T13:08:47Z")

</div>

The attache patch enables POSIX semaphores usage during shared memory  
access.  
It should decrease CPU usage on start-up or online upgrade of  
installations  
with large caches or large number of workers.

I tested the patch on FreeBSD 8.2. There is no sense to test it on  
FreeBSD prior to 7.2 version, since semaphores does not work on these  
systems.  
You can ensure that there are enough semaphores:  
sysctl p1003\_1b.sem\_nsems\_max  
By default there should be 32 semaphores. On 8.2+ you can increase them  
dynamically. You need one semaphores per shared zone.  
“sysctl p1003\_1b.nsems” shows current number of semaphores.

It would be intresting to test the patch on other platforms - Linux  
and Solaris. Please draw attention to alerts in error\_log.  
Note also that nginx does not destroy semaphores on exit. They should  
deleted by kernel automatically. Please check that there is no  
semaphore leakage while nginx work.
