[Nagios-devel] hashing optimizations
Posted: Wed Jun 15, 2005 4:17 am
This is a multi-part message in MIME format.
--------------060808030409060001060404
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ahoy.
The attached patch provides proper hashing for Nagios and the cgi's.
The various functions are implemented in include/hash.h (so they can be
properly inlined in the functions that use them).
Some minor changes were necessary to other files as well. Notably, I've
hoisted the initialization of the hashtables to a function of its own to
save a lot of conditionals (the add_*_to_hashlist are always called from
an inner loop with tons of iterations).
I've also resized the hash-tables somewhat. Let me know if this turns
into a memory hog.
Note that I haven't tested this patch yet (except buildtests ofcourse).
I thought it would be prudent to have a few people compile this on
different platforms first to find the easy-to-fix showstoppers with odd
archs/platforms/compilers/whatever.
Heads up for performance tests in a bit. I'll run all tests with Nagios'
default optimization levels and no arch-specific gcc options, as I
suppose that's how the vast majority of people running nagios will use it.
--
Andreas Ericsson [email protected]
OP5 AB www.op5.se
Lead Developer
--------------060808030409060001060404
Content-Type: text/plain;
name="nagios-proper-hash.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios-proper-hash.diff"
diff -urN ../nagios.orig/base/nagios.c ./base/nagios.c
--- ../nagios.orig/base/nagios.c 2005-05-26 14:12:45.000000000 +0200
+++ ./base/nagios.c 2005-06-15 13:32:06.000000000 +0200
@@ -479,6 +479,7 @@
/* reset program variables */
reset_variables();
+ initialize_hash_data();
/* get program (re)start time and save as macro */
program_start=time(NULL);
diff -urN ../nagios.orig/base/utils.c ./base/utils.c
--- ../nagios.orig/base/utils.c 2005-06-13 14:41:57.000000000 +0200
+++ ./base/utils.c 2005-06-15 13:24:04.000000000 +0200
@@ -4244,69 +4244,6 @@
return encoded_url_string;
}
-
-
-/******************************************************************/
-/************************* HASH FUNCTIONS *************************/
-/******************************************************************/
-
-/* single hash function */
-int hashfunc1(const char *name1,int hashslots){
- unsigned int i,result;
-
- result=0;
-
- if(name1)
- for(i=0;i0)
- return 1;
- else if(result<0)
- return -1;
- else
- return strcmp(val1b,val2b);
- }
-
-
-
/******************************************************************/
/************************* FILE FUNCTIONS *************************/
/******************************************************************/
@@ -5094,6 +5031,9 @@
/* free memory allocated to comments */
free_comment_data();
+ /* free memory allocated to hash-tables */
+ free_hash_data();
+
/* free memory for the high priority event list */
this_event=event_list_high;
while(this_event!=NULL){
diff -urN ../nagios.orig/cgi/cgiutils.c ./cgi/cgiutils.c
--- ../nagios.orig/cgi/cgiutils.c 2004-11-15 09:28:06.000000000 +0100
+++ ./cgi/cgiutils.c 2005-06-15 13:37:31.000000000 +0200
@@ -199,6 +199,15 @@
my_strtok_buffer=NULL;
original_my_strtok_buffer=NULL;
+ /*
+ * This might not be the best place for this c
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
--------------060808030409060001060404
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ahoy.
The attached patch provides proper hashing for Nagios and the cgi's.
The various functions are implemented in include/hash.h (so they can be
properly inlined in the functions that use them).
Some minor changes were necessary to other files as well. Notably, I've
hoisted the initialization of the hashtables to a function of its own to
save a lot of conditionals (the add_*_to_hashlist are always called from
an inner loop with tons of iterations).
I've also resized the hash-tables somewhat. Let me know if this turns
into a memory hog.
Note that I haven't tested this patch yet (except buildtests ofcourse).
I thought it would be prudent to have a few people compile this on
different platforms first to find the easy-to-fix showstoppers with odd
archs/platforms/compilers/whatever.
Heads up for performance tests in a bit. I'll run all tests with Nagios'
default optimization levels and no arch-specific gcc options, as I
suppose that's how the vast majority of people running nagios will use it.
--
Andreas Ericsson [email protected]
OP5 AB www.op5.se
Lead Developer
--------------060808030409060001060404
Content-Type: text/plain;
name="nagios-proper-hash.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios-proper-hash.diff"
diff -urN ../nagios.orig/base/nagios.c ./base/nagios.c
--- ../nagios.orig/base/nagios.c 2005-05-26 14:12:45.000000000 +0200
+++ ./base/nagios.c 2005-06-15 13:32:06.000000000 +0200
@@ -479,6 +479,7 @@
/* reset program variables */
reset_variables();
+ initialize_hash_data();
/* get program (re)start time and save as macro */
program_start=time(NULL);
diff -urN ../nagios.orig/base/utils.c ./base/utils.c
--- ../nagios.orig/base/utils.c 2005-06-13 14:41:57.000000000 +0200
+++ ./base/utils.c 2005-06-15 13:24:04.000000000 +0200
@@ -4244,69 +4244,6 @@
return encoded_url_string;
}
-
-
-/******************************************************************/
-/************************* HASH FUNCTIONS *************************/
-/******************************************************************/
-
-/* single hash function */
-int hashfunc1(const char *name1,int hashslots){
- unsigned int i,result;
-
- result=0;
-
- if(name1)
- for(i=0;i0)
- return 1;
- else if(result<0)
- return -1;
- else
- return strcmp(val1b,val2b);
- }
-
-
-
/******************************************************************/
/************************* FILE FUNCTIONS *************************/
/******************************************************************/
@@ -5094,6 +5031,9 @@
/* free memory allocated to comments */
free_comment_data();
+ /* free memory allocated to hash-tables */
+ free_hash_data();
+
/* free memory for the high priority event list */
this_event=event_list_high;
while(this_event!=NULL){
diff -urN ../nagios.orig/cgi/cgiutils.c ./cgi/cgiutils.c
--- ../nagios.orig/cgi/cgiutils.c 2004-11-15 09:28:06.000000000 +0100
+++ ./cgi/cgiutils.c 2005-06-15 13:37:31.000000000 +0200
@@ -199,6 +199,15 @@
my_strtok_buffer=NULL;
original_my_strtok_buffer=NULL;
+ /*
+ * This might not be the best place for this c
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]