Page 1 of 1

[Nagios-devel] CGI speedup (patch against 1.1)

Posted: Sun Aug 03, 2003 7:10 pm
by Guest
--f2QGlHpHGjS2mn6Y
Content-Type: multipart/mixed; boundary="pWyiEgJYm5f9v55/"
Content-Disposition: inline


--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I'm currently running a nagios instance which is monitoring almost 7000
services, 95% of which are passive. I'd found that the load on the single
server is generally quite high. The patch that Michael posted earlier made
a huge difference to the general load on the system, but the CGI scripts
(status.cgi) still takes around 13-14 seconds per view.=20

Profiling the CGI revealed that roughly 90% of the cpu time is spent in
find_service, because it does a linear walk along the linked list of all
the services, and it does it sometimes 4 times per service because of the
amount of processing required to display a nice pretty sorted list.

My quick fix (not a perfect solution) was to build a hash of the service &
host names and use that to very quickly find the record in RAM. I've used
glib because it has very simple hashing routines, but any hashing code
would probably do fine.

After applying the patch, the CGI takes around 4 seconds per view, which is
a huge improvement.

However, using the nagios core compiled with this code appears to run a lot
hotter, and makes the load skyrocket to around 60 or so... So I just use
this patch with the CGI.

Patch against release 1.1 is attached...

--=20
Regards,
David Parrish
0410 586 121

--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nagios-1.1-glib.patch"
Content-Transfer-Encoding: quoted-printable

diff -u -b -B -r1.1.1.1 Makefile.in
--- base/Makefile.in 23 Jun 2003 01:56:10 -0000 1.1.1.1
+++ base/Makefile.in 30 Jul 2003 01:22:20 -0000
@@ -10,9 +10,9 @@
SRC_XDATA=3D../xdata
=20
CC=3D@CC@
-CFLAGS=3D@CFLAGS@ @DEFS@ -DNSCORE
+CFLAGS=3D@CFLAGS@ @DEFS@ -DNSCORE `glib-config --cflags`
#CFLAGS=3D-O3 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wst=
rict-prototypes -Wmissing-prototypes -Wnested-externs -DHAVE_CONFIG_H -DNSC=
ORE
-LDFLAGS=3D@LDFLAGS@ @LIBS@
+LDFLAGS=3D@LDFLAGS@ @LIBS@ `glib-config --libs`
=20
prefix=3D@prefix@
exec_prefix=3D@exec_prefix@
diff -u -b -B -r1.1.1.1 Makefile.in
--- cgi/Makefile.in 23 Jun 2003 01:56:10 -0000 1.1.1.1
+++ cgi/Makefile.in 30 Jul 2003 01:22:20 -0000
@@ -25,9 +25,9 @@
=20
CP=3D@CP@
CC=3D@CC@
-CFLAGS=3D@CFLAGS@ @DEFS@ -DNSCGI
+CFLAGS=3D@CFLAGS@ @DEFS@ -DNSCGI `glib-config --cflags`
#CFLAGS=3D-O3 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wst=
rict-prototypes -Wmissing-prototypes -Wnested-externs -DHAVE_CONFIG_H -DNSC=
GI
-LDFLAGS=3D@LDFLAGS@ @LIBS@
+LDFLAGS=3D@LDFLAGS@ @LIBS@ `glib-config --libs`
=20
CGIS=3Davail.cgi cmd.cgi config.cgi extinfo.cgi history.cgi notifications.=
cgi outages.cgi showlog.cgi status.cgi statuswml.cgi summary.cgi tac.cgi $(=
CGIEXTRAS)
=20
diff -u -b -B -r1.1.1.2 common.h
--- common/common.h 23 Jun 2003 01:57:24 -0000 1.1.1.2
+++ common/common.h 30 Jul 2003 01:22:20 -0000
@@ -208,8 +208,12 @@
#define OK 0
#define ERROR -2 /* value was changed from -1 so as to not interfere wi=
th STATUS_UNKNOWN plugin result */
=20
+#ifndef TRUE
#define TRUE 1
+#endif
+#ifndef FALSE
#define FALSE 0
+#endif
=20
=20
/****************** HOST CONFIG FILE READING OPTIONS ********************/
diff -u -b -B -r1.1.1.1 config.h.in
--- common/config.h.in 23 Jun 2003 01:56:10 -0000 1.1.1.1
+++ common/config.h.in 30 Jul 2003 01:22:20 -0000
@@ -214,3 +214,7 @@
#include
#endif
=20
+#define HAVE_GLIB_H 1
+#ifdef HAVE_GLIB_H
+#include
+#endif
diff -u -b -B -r1.1.1.1 objects.c
--- common/objects.c 23 Jun 2003 01:56:10 -0000 1.1.1.1
+++ common/objects.c 30 Jul 2003 01:22:20 -0000
@@ -59,6 +59,8 @@
servicedependency *servicedependency_list=3DNULL;
hostdependency *hostdependency_list=3DNULL;
hostescalation *hostescalation_list=3DNULL;
+GHashTable *service_hash =3D NULL;
+GHashTable *host_hash =3D NULL;
=20
=20
=20
@@ -747,6 +749,16 @@
printf("\tNotification Interval: %d\n",new_host->n

...[email truncated]...


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