[Nagios-devel] Optimisation fix

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] Optimisation fix

Post by Guest »

This is a multi-part message in MIME format.
--------------050209010500070809010108
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello,

My company has deployed for a French company a nagios system for
supervising over 600 computers. It was definetely too slow for an
acceptable use (~5 minutes for displaying cgis).

I have profiled the c code of nagios using gprof and find the guilty =
:
xdata/xodtemplate.c : xodtemplate_service *xodtemplate_find_service(char
*name) {...}

I have corrected the guilty and found a factor 5 in speed of nagios
cgis' (ie : 5 times faster for about 5 lines changed in the code).
Please feel free to use the patch, test it and correct it to your
convenience. You can see the profiling before and after the patch in the
attached files. It was originally made against nagios 1.2, but I have
ported it against your cvs version of this day.

I use a ghashmap of the "glib", but any other well-implemented
hashmap can be convenient. In order to test it easily and see the speed
improvements, you have to modify the Makefile in xdata subdirectory,
after the ./configure execution.
Add `pkg-config --cflags glib-2.0` to $CFLAGS and `pkg-config --libs
glib-2.0` to $LDFLAGS. You'll need to install the glib-devel package too.

After that, try to display any of the cgis... it 's amazing !



--=20
Loiseleur Michel - TM2L (08000LINUX)
Open Source Software Assurance
LINAGORA
27, rue de Berri
1er =E9tage
75008 PARIS
T=E9l : 01 58 18 68 28
Fax : 01 58 18 68 29
"Si hoc legere scis nimium eruditionis habes"


--------------050209010500070809010108
Content-Type: text/x-patch;
name="nagios-2.4-optimization.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios-2.4-optimization.patch"

--- xdata/xodtemplate.c 2006-06-23 18:10:16.000000000 +0200
+++ xdata/xodtemplate.c 2006-06-23 18:13:11.000000000 +0200
@@ -67,6 +67,10 @@
#include "xodtemplate.h"


+/* needed for fast cgis */
++#include
+
+
#ifdef NSCORE
extern int use_regexp_matches;
extern int use_true_regexp_matching;
@@ -8150,18 +8154,23 @@
/* finds a specific service object */
xodtemplate_service *xodtemplate_find_service(char *name){
xodtemplate_service *temp_service=NULL;
-
- for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
- if(temp_service->name==NULL)
- continue;
- if(!strcmp(temp_service->name,name))
- break;
- }
-
- return temp_service;
+ static GHashTable* hashtable_services = 0;
+
+ /* init 1 time */
+ if (hashtable_services == 0) {
+ xodtemplate_service *temp_service;
+ hashtable_services = g_hash_table_new (&g_str_hash, &g_str_equal);
+ for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next)
+ if(temp_service->name != NULL)
+ g_hash_table_insert (hashtable_services, temp_service->name, temp_service);
+ }
+
+ /* process each time */
+ return g_hash_table_lookup (hashtable_services, name);
}


+
/* finds a specific service object by its REAL name, not its TEMPLATE name */
xodtemplate_service *xodtemplate_find_real_service(char *host_name, char *service_description){
xodtemplate_service *temp_service=NULL;

--------------050209010500070809010108
Content-Type: text/x-log;
name="gprof_after.log"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="gprof_after.log"

Flat profile:

Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ns/call ns/call name
9.21 0.11 0.11 xodtemplate_strip (xodtemplate.c:519 @ 8057b1d)
7.89 0.20 0.09 xodtemplate_process_config_file (xodtemplate.c:336 @ 80575b1)
4.39 0.25 0.05 xodtemplate_add_object_property (xodtemplate.c:1248 @ 8058e0f)
4.39 0.30 0.05 xodtemplate_add_object_property (xodtemplate.c:1263 @ 8058eb0)
4.39 0.35 0.05 xodtemplate_strip (xodtemplate.c:502 @ 8057a82)
4.39

...[email truncated]...


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