rfc:zendsignals
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:zendsignals [2008/07/06 01:10] – fix typos lucas | rfc:zendsignals [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2008-07-05 | * Date: 2008-07-05 | ||
* Author: Lucas Nealan < | * Author: Lucas Nealan < | ||
- | * Status: | + | * Status: |
* First Proposed by: [[http:// | * First Proposed by: [[http:// | ||
+ | * Source code: [[http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This idea came about at Facebook while investigating ways to optimize Zend Engine calls to ap_block/ | + | This idea came about at Facebook while investigating ways to optimize Zend Engine calls to ap_block/ |
* Make HANDLE_BLOCK/ | * Make HANDLE_BLOCK/ | ||
+ | | ||
* Improve performance of PHP running under SAPI's that currently implement block/ | * Improve performance of PHP running under SAPI's that currently implement block/ | ||
+ | |||
+ | ===== Improved Stability ===== | ||
+ | |||
+ | The Zend Engine exposes an alarm blocking mechanism via macros however the specific implementation is left up to each SAPI, many of which do not provide the necessary functionality. In a standard PHP environment this is likely to be acceptable as the PHP engine only implements a single alarm based feature, the max_execution_time timeout. A survey of bundled SAPI's shows that almost all implement STANDARD_SAPI_MODULE_PROPERTIES in their sapi_module_struct, | ||
+ | |||
+ | As extensions such as APC are introduced the need for stable alarm handling increases. The likelihood of being within within a critical section increases as an extension may be maintaining a shared memory segment using a variety of locking mechanisms, some of which may in fact further increase these odds such as spinlocking. | ||
+ | |||
+ | Extensions will now be able implement the zend alarm blocking macros in their critical sections and be assured that these critical sections will be protected. | ||
===== Details ===== | ===== Details ===== | ||
Line 30: | Line 40: | ||
If execution is within a critical section, execution of the previous handler will be deferred until the HANDLE_UNBLOCK_INTERRUPTIONS macro is reached. During deferred execution if any additional signals are received they are queued. All queued signals handlers will be invoked when HANDLE_UNBLOCK_INTERRUPTIONS is reached. | If execution is within a critical section, execution of the previous handler will be deferred until the HANDLE_UNBLOCK_INTERRUPTIONS macro is reached. During deferred execution if any additional signals are received they are queued. All queued signals handlers will be invoked when HANDLE_UNBLOCK_INTERRUPTIONS is reached. | ||
- | === zend_signal() | + | === Zend Alarm Blocking Macros |
- | The // | + | For optimal performance |
- | === HANDLE_BLOCK/ | + | This accounting will not work in ZTS enabled mode thus support for deferred signal handling is automatically disabled when ZTS is enabled. |
- | For optimal performance the new blocking macros account for critical sections by incrementing and decrementing the // | + | === zend_signal() === |
- | This accounting will not work in ZTS enabled mode thus support for deferred signal handling is automatically disabled when ZTS is enabled. | + | The // |
===== Performance ===== | ===== Performance ===== | ||
- | Benchmarks in valgrind/ | + | === zend_alloc === |
- | ===== APC ===== | + | Using [[http:// |
- | With the newer locking mechanisms now available in the APC extension this type of internal handling is now extremely important. APC spinlocks, although in faster overall page generation, spend more user time towards accounting by the ITIMER_PROF interval timer than mutex locking. This may trigger an increased number of php execution timeouts. When this timeout occurs, APC is more likely than be in a spinlock. This implementation enables deferred signal protection for SIGPROF which solves this problem and adds a greater level of stability for APC users within all locking mechanisms. | + | ^ Average |
+ | |php-5.2.5 | 938.9716| | ||
+ | |php-5.2.5-patched | 915.8652| | ||
+ | |difference | ||
+ | |improvement | ||
- | ===== Patch ===== | + | Note: Although within the range of error these measurements seem consistent. The same script executed via ApacheBench showed no detectible request time improvement once transit cost was introduced. |
- | The patch against PHP_5_3 is [[http://sizzo.org/ | + | === callgrind === |
+ | |||
+ | Benchmarks using Valgrind/Callgrind show the following results on a heavyweight page with a total of almost 3 billion instructions. | ||
+ | |||
+ | ^ Callgrind | ||
+ | ^php-5.2.5 ^^ | ||
+ | |total instructions | ||
+ | |ap_block_alarms calls | ||
+ | |ap_unblock_alarms calls |4, | ||
+ | ^php-5.2.5-patched | ||
+ | |total instructions | ||
+ | |ap_block_alarms calls |0 | | ||
+ | |ap_unblock_alarms calls |0 | | ||
+ | |||
+ | - 9,997,702 less function calls | ||
+ | - 99,969,503 less instructions (3.6%) | ||
+ | |||
+ | Although some measure of improved performance is expected and measurable this functionality should at the very least improve stability at no cost. | ||
===== Considerations ===== | ===== Considerations ===== | ||
- | - Zend Signal Handling support has not been implemented for ZTS enabled php builds. | + | - Limited |
- | + | ||
- | - The proposal has only been implemented | + | |
- | + | ||
- For simplicity the // | - For simplicity the // | ||
+ | |||
+ | - A signal queue of ZEND_SIGNAL_QUEUE_SIZE is created to handle recieved signals within critical sections. It is initialized to support 32 signals. If more are received after this they are discarded. | ||
+ | |||
+ | ===== Discoveries ===== | ||
+ | === pcntl extension signals === | ||
+ | The pcntl extension allows signal handlers to be defined in PHP userspace via // | ||
+ | |||
+ | Note: Although --enable-pcntl states " | ||
+ | |||
+ | Update: pcntl has been modified to register signals via // | ||
+ | |||
+ | === PHP SIGCHLD signal handler === | ||
+ | To deal with zombied or defunct children SIGCHILD handling was added to PHP via --enable-sigchild. This is apparently very common during disconnect when using oracle libraries to connect via the BEQ interface. When enabled, a handler for SIGCHILD is installed during php_startup. This handler calls // | ||
+ | |||
+ | Since Zend Signals does not install a handler for SIGCHILD there is no explicit conflict. Also the simplicity of the handler should ensure that it does not adversely affect any critical zend sections. In future versions we may want to bring this functionality into Zend and enable by default on all platforms that support SIGCHLD ass well as implement via // | ||
+ | |||
+ | Note: When calling //wait()// or // | ||
===== Changelog ===== | ===== Changelog ===== | ||
- | - 2008-07-05 Lucas Nealan: Initial creation | + | - 2008-07-05 Lucas Nealan: Initial creation |
+ | - 2008-07-08 Lucas Nealan: Updated patch for php_request_shutdown order issue ([[http:// | ||
+ | - 2008-07-29 Lucas Nealan: Update patch to fix reentrance in handler, enable by default, stolen signal reporting ([[http:// | ||
+ | - 2008-08-01 Lucas Nealan: Update patch to fix tests, alloc/free on php startup/ | ||
+ | - 2008-08-03 Lucas Nealan: Incorporated ZTS support by Arnaud Le Blanc, moved ini def to zend.c, added HEAD patch ([[http:// | ||
+ | - 2008-08-05 Arnaud Le Blanc: Added zend_sigaction() and ported PCNTL to use it. ([[http:// | ||
+ | - 2008-08-12 Lucas Nealan: Update patches to latest CVS, minor TWS fixes etc. ([[http:// | ||
+ | - 2009-11-20 Brian Shire: Updated patches for latest CVS with some fixes for bugs caused by another fix to the handling of signals during user-space shutdown functions. ([[http:// |
rfc/zendsignals.1215306626.txt.gz · Last modified: 2017/09/22 13:28 (external edit)