Optimize status.cgi
Jonathan Kamens
jkamens at Advent.COM
Wed Dec 23 03:26:00 CET 2009
With nagios 3.2.0 at my site, it took over a minute from when I entered
a host name in the Web UI's "Quick Search:" box and hit Enter, until
when the status details for the host were actually displayed.
The attached patch reduces the time to do exactly the same work to under
five seconds.
It adds the following optimizations to the code base:
1. When iterating through the lines in the status.dat file, use a
persistent buffer to read lines rather than freeing and
reallocating a new buffer for every line. This reduces
fragmentation of the malloc pool and reduces the amount of time
spent in malloc() and free(). This is implemented by adding a new
function, mmap_fgets_buf(), which is like mmap_fgets() except it
takes an optional buffer to reuse if possible. I added this to
both cgiutils.c and utils.c so that it can be used elsewhere in
the code.
2. When parsing the status.dat file, reduce the number of unnecessary
calls to strcmp() by keeping track of when we know we're in a
block and not checking for block-start sequences unnecessarily.
3. Defer the sorting of the comment and scheduled downtime linked
lists until they've all been read from status.dat. This makes a
*/huge/* difference in performance -- it dwarfs by orders of
magnitude the optimizations listed above. The way this is
implemented is invisible to programs aside from status.cgi that
call add_comment() or add_downtime(), but those programs can
easily be modified to take advantage of the new functionality if
they need to be sped up.
I sincerely hope that the maintainers of Nagios will make an effort to
include these changes in the next release. They represent a dramatic
improvement in the performance and usability of the Web UI.
Thanks,
Jonathan Kamens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20091222/b3980dd6/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nagios-3.2.0-status-cgi-speed.patch
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20091222/b3980dd6/attachment.ksh>
-------------- next part --------------
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel
More information about the Developers
mailing list