[Nagios-devel] Large installation CGI optimization patch

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] Large installation CGI optimization patch

Post by Guest »

--_000_D26A6FD0353F784CB75381CF3D2043E19B5C879DMBX02ldschurcho_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="ISO-8859-1"

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 re=
ad in the status.dat file has some design drawbacks that make it interpret =
the lines more slowly than it could.

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 dif=
ferent 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 n=
o reason to test whether you are going to run into another object definitio=
n start line until after you have ended the definition that you are current=
ly 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 o=
bject 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 variabl=
e/value pair (var=3Dvalue).

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. Wh=
ile this is only about 10%, this reduces the load on the web server signifi=
cantly when there are many requests for these pages. In some cases (when th=
e server is busy) it reduces the execution time by as much as 3 seconds, wh=
ich is more like 40%.

I'm submitting this modification for evaluation and comment. Hopefully it c=
an make it into the Nagios code base.

Cary Petterborg

---------------------

Below is the output of a diff of xsddefault.c from the version of 3.2.1 tha=
t we are currently using (*most* of the differences are just the indentatio=
n of the section that is now enclosed within an if statement):

Index: xsddefault.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- xsddefault.c (revision 1955)
+++ xsddefault.c (working copy)
@@ -766,6 +766,7 @@
unsigned long triggered_by=3D0;
unsigned long duration=3D0L;
int x=3D0;
+ int in_block =3D FALSE;

/* initialize some vars */
@@ -815,47 +816,66 @@
if(input[0]=3D=3D'#' || input[0]=3D=3D'\x0')
continue;
- else if(!strcmp(input,"info {"))
- data_type=3DXSDDEFAULT_INFO_=
DATA;
- else if(!strcmp(input,"programstatus {"))
- data_type=3DXSDDEFAULT_PROGR=
AMSTATUS_DATA;
- else if(!strcmp(input,"hoststatus {")){
- data_type=3DXSDDEFAULT_HOSTS=
TATUS_DATA;
- temp_hoststatus=3D(hoststatu=
s *)malloc(sizeof(hoststatus));
- if(temp_hoststatus){
- temp_hoststa=
tus->host_name=3DNULL;
- temp_hoststa=
tus->plugin_output=3DNULL;
- temp_hoststa=
tus->long_plugin_output=3DNULL;
- temp_hoststa=
tus->perf_data=3DNULL;
- temp_hoststa=
tus->check_options=3D0;
- }
- }
- else if(!strcmp(input,"services

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked