Bug 64066

Summary: httpd slow on startup/reload when many vhosts are configured
Product: Apache httpd-2 Reporter: Giovanni Bechis <giovanni>
Component: CoreAssignee: Apache HTTPD Bugs Mailing List <bugs>
Severity: normal    
Priority: P2    
Version: 2.4.41   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Configuration load speed improvement

Description Giovanni Bechis 2020-01-09 15:01:10 UTC
Created attachment 36959 [details]
Configuration load speed improvement

The httpd(8) startup and "graceful restart" time can be very long (~45s) with a large amount of vhosts (5k), defeating the purpose of "graceful restart" by causing client timeouts.
This appears to be the result of many calls to ap_find_command() which searches for a command by walking a simple array of command_rec structures and doing a string comparison between the name element of the structure and the desired command name. 

To reproduce the issue a configuration with at least 5k vhosts is needed;
with a similar config startup is slow and, after sending USR1 signal httpd(8)
becomes unresponsive for many seconds and this can cause client timeouts.

Httpd already has a hash of directives that is builds internally.
As this was most of the startup time we can avoid the manual array search.
For configurations with many directives this reduces the startup time by at least an order of magnitude.

Bug analysis and patch authored by cPanel.
Comment 1 Jim Jagielski 2020-01-14 17:12:39 UTC
Thank you for the patch. This looks very useful indeed. I will check and, if it passes all tests, apply to trunk w/ a back port to 2.4.x
Comment 2 Giovanni Bechis 2020-01-21 10:26:38 UTC
for the archives, committed in trunk in r1872786.
Comment 3 Giovanni Bechis 2020-02-07 17:19:46 UTC
Backported to 2.4 in commit r1872786.
Comment 4 Giovanni Bechis 2020-02-07 17:20:47 UTC
Backported in 2.4 in commit r1873738.