<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>I have been working on a simple change to the xsddefault.c file which seems to be a good optimization for large installations. Our installation has 43,500 services and 4,200 hosts. The CGI’s tend to take a while to go through the status.dat file as a result. The way that the routine is written to read in the status.dat file has some design drawbacks that make it interpret the lines more slowly than it could.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>If the status.dat file is uncorrupted (which if it is corrupted, there are more problems than reading that file in), then the order of testing for different types of data on the line consumes more time than it should. If you are already inside a definition of a service, host, or whatever, there is no reason to test whether you are going to run into another object definition start line until after you have ended the definition that you are currently in. The optimization that I have made just takes that into account, and it no longer has to do 10 strcmp() calls for every line it reads. When an object definition starts (e.g. “hoststatus {“), just set a flag, then clear it when you get to the end (“}”). Then when you look at a line, don’t look for the possible definition lines, just check the flag and look for variable/value pair (var=value).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>In our case, the speed increase is not dramatic, but it is significant. The average time to execute for one of the CGI’s was reduced by .7 seconds. While this is only about 10%, this reduces the load on the web server significantly when there are many requests for these pages. In some cases (when the server is busy) it reduces the execution time by as much as 3 seconds, which is more like 40%.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’m submitting this modification for evaluation and comment. Hopefully it can make it into the Nagios code base.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Cary Petterborg<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>---------------------<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Below is the output of a diff of xsddefault.c from the version of 3.2.1 that we are currently using (*most* of the differences are just the indentation of the section that is now enclosed within an if statement):<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Index: xsddefault.c<o:p></o:p></p><p class=MsoNormal>===================================================================<o:p></o:p></p><p class=MsoNormal>--- xsddefault.c (revision 1955)<o:p></o:p></p><p class=MsoNormal>+++ xsddefault.c              (working copy)<o:p></o:p></p><p class=MsoNormal>@@ -766,6 +766,7 @@<o:p></o:p></p><p class=MsoNormal>                unsigned long triggered_by=0;<o:p></o:p></p><p class=MsoNormal>                unsigned long duration=0L;<o:p></o:p></p><p class=MsoNormal>                int x=0;<o:p></o:p></p><p class=MsoNormal>+             int in_block = FALSE;<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>                /* initialize some vars */<o:p></o:p></p><p class=MsoNormal>@@ -815,47 +816,66 @@<o:p></o:p></p><p class=MsoNormal>                                if(input[0]=='#' || input[0]=='\x0')<o:p></o:p></p><p class=MsoNormal>                                                continue;<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"info {"))<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_INFO_DATA;<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"programstatus {"))<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_PROGRAMSTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"hoststatus {")){<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_HOSTSTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>-                                              temp_hoststatus=(hoststatus *)malloc(sizeof(hoststatus));<o:p></o:p></p><p class=MsoNormal>-                                              if(temp_hoststatus){<o:p></o:p></p><p class=MsoNormal>-                                                              temp_hoststatus->host_name=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_hoststatus->plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_hoststatus->long_plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_hoststatus->perf_data=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_hoststatus->check_options=0;<o:p></o:p></p><p class=MsoNormal>-                                                      }<o:p></o:p></p><p class=MsoNormal>-                                      }<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"servicestatus {")){<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_SERVICESTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>-                                              temp_servicestatus=(servicestatus *)malloc(sizeof(servicestatus));<o:p></o:p></p><p class=MsoNormal>-                                              if(temp_servicestatus){<o:p></o:p></p><p class=MsoNormal>-                                                              temp_servicestatus->host_name=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_servicestatus->description=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_servicestatus->plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_servicestatus->long_plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_servicestatus->perf_data=NULL;<o:p></o:p></p><p class=MsoNormal>-                                                              temp_servicestatus->check_options=0;<o:p></o:p></p><p class=MsoNormal>-                                                      }<o:p></o:p></p><p class=MsoNormal>-                                      }<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"contactstatus {")){<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_CONTACTSTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>-                                              /* unimplemented */<o:p></o:p></p><p class=MsoNormal>-                                      }<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"hostcomment {"))<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_HOSTCOMMENT_DATA;<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"servicecomment {"))<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_SERVICECOMMENT_DATA;<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"hostdowntime {"))<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_HOSTDOWNTIME_DATA;<o:p></o:p></p><p class=MsoNormal>-                              else if(!strcmp(input,"servicedowntime {"))<o:p></o:p></p><p class=MsoNormal>-                                              data_type=XSDDEFAULT_SERVICEDOWNTIME_DATA;<o:p></o:p></p><p class=MsoNormal>+                             if (!in_block ) {<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>+                                             if(!strcmp(input,"info {")) {<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_INFO_DATA;<o:p></o:p></p><p class=MsoNormal>+                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"programstatus {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_PROGRAMSTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>+                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"hoststatus {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_HOSTSTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>+                                                             temp_hoststatus=(hoststatus *)malloc(sizeof(hoststatus));<o:p></o:p></p><p class=MsoNormal>+                                                             if(temp_hoststatus){<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_hoststatus->host_name=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_hoststatus->plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_hoststatus->long_plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_hoststatus->perf_data=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_hoststatus->check_options=0;<o:p></o:p></p><p class=MsoNormal>+                                                                                             }<o:p></o:p></p><p class=MsoNormal>+                                                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"servicestatus {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_SERVICESTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>+                                                             temp_servicestatus=(servicestatus *)malloc(sizeof(servicestatus));<o:p></o:p></p><p class=MsoNormal>+                                                             if(temp_servicestatus){<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_servicestatus->host_name=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_servicestatus->description=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_servicestatus->plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_servicestatus->long_plugin_output=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_servicestatus->perf_data=NULL;<o:p></o:p></p><p class=MsoNormal>+                                                                             temp_servicestatus->check_options=0;<o:p></o:p></p><p class=MsoNormal>+                                                                                             }<o:p></o:p></p><p class=MsoNormal>+                                                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"contactstatus {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_CONTACTSTATUS_DATA;<o:p></o:p></p><p class=MsoNormal>+                                                             /* unimplemented */<o:p></o:p></p><p class=MsoNormal>+                                                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"hostcomment {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_HOSTCOMMENT_DATA;<o:p></o:p></p><p class=MsoNormal>+                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"servicecomment {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_SERVICECOMMENT_DATA;<o:p></o:p></p><p class=MsoNormal>+                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"hostdowntime {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_HOSTDOWNTIME_DATA;<o:p></o:p></p><p class=MsoNormal>+                                             }<o:p></o:p></p><p class=MsoNormal>+                                             else if(!strcmp(input,"servicedowntime {")){<o:p></o:p></p><p class=MsoNormal>+                                                             in_block = TRUE;<o:p></o:p></p><p class=MsoNormal>+                                                             data_type=XSDDEFAULT_SERVICEDOWNTIME_DATA;<o:p></o:p></p><p class=MsoNormal>+                                             }<o:p></o:p></p><p class=MsoNormal>+                             }<o:p></o:p></p><p class=MsoNormal>+<o:p></o:p></p><p class=MsoNormal>                                else if(!strcmp(input,"}")){<o:p></o:p></p><p class=MsoNormal>+                                             in_block = FALSE;<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>                                                switch(data_type){<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p></div>
<DIV>
<p class=MsoNormal><span style='font-size:7.0pt';font-family:'"Helvetica","Tahoma","Arial","sans-serif"'><font color="#666666"><br><br> NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.</span><o:p></o:p></span></p><BR>
</DIV></body></html>