[rrd-developers] [PATCH 2/2] Introduce "-m" argument to reduce calls to realloc().
kevin brintnall
kbrint at rufus.net
Sat Oct 31 19:46:19 CET 2009
---
doc/rrdcached.pod | 9 +++++++++
src/rrd_daemon.c | 23 ++++++++++++++++++++---
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/doc/rrdcached.pod b/doc/rrdcached.pod
index 043e020..5e8728f 100644
--- a/doc/rrdcached.pod
+++ b/doc/rrdcached.pod
@@ -18,6 +18,7 @@ B<rrdcached>
[-F]
[-g]
[B<-b>E<nbsp>I<base_dir>E<nbsp>[B<-B>]]
+[B<-m>E<nbsp>I<alloc_size>]
=head1 DESCRIPTION
@@ -197,6 +198,14 @@ Only permit writes into the base directory specified in B<-b> (and any
sub-directories). This does B<NOT> detect symbolic links. Paths
containing C<../> will also be blocked.
+=item B<-m> I<alloc_size>
+
+Allocate value pointers in chunks of I<alloc_size>. This may improve CPU
+utilization on machines with slow C<realloc()> implementations, in
+exchange for slightly higher memory utilization. The default isE<nbsp>1.
+Do not set this more than the B<-w> value divided by your average RRD step
+size.
+
=back
=head1 AFFECTED RRDTOOL COMMANDS
diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c
index 4c84f19..79ea17b 100644
--- a/src/rrd_daemon.c
+++ b/src/rrd_daemon.c
@@ -174,7 +174,8 @@ struct cache_item_s
{
char *file;
char **values;
- size_t values_num;
+ size_t values_num; /* number of valid pointers */
+ size_t values_alloc; /* number of allocated pointers */
time_t last_flush_time;
time_t last_update_stamp;
#define CI_FLAGS_IN_TREE (1<<0)
@@ -251,6 +252,7 @@ static char *config_pid_file = NULL;
static char *config_base_dir = NULL;
static size_t _config_base_dir_len = 0;
static int config_write_base_only = 0;
+static size_t config_alloc_chunk = 1;
static listen_socket_t **config_listen_address_list = NULL;
static size_t config_listen_address_list_len = 0;
@@ -638,6 +640,7 @@ static void wipe_ci_values(cache_item_t *ci, time_t when)
{
ci->values = NULL;
ci->values_num = 0;
+ ci->values_alloc = 0;
ci->last_flush_time = when;
if (config_write_jitter > 0)
@@ -1434,7 +1437,8 @@ static int handle_request_update (HANDLER_PROTO) /* {{{ */
else
ci->last_update_stamp = stamp;
- if (!rrd_add_strdup(&ci->values, &ci->values_num, value))
+ if (!rrd_add_strdup_chunk(&ci->values, &ci->values_num, value,
+ &ci->values_alloc, config_alloc_chunk))
{
RRDD_LOG (LOG_ERR, "handle_request_update: rrd_add_strdup failed.");
continue;
@@ -2746,7 +2750,7 @@ static int read_options (int argc, char **argv) /* {{{ */
char **permissions = NULL;
size_t permissions_len = 0;
- while ((option = getopt(argc, argv, "gl:P:f:w:z:t:Bb:p:Fj:h?")) != -1)
+ while ((option = getopt(argc, argv, "gl:P:f:w:z:t:Bb:p:Fj:m:h?")) != -1)
{
switch (option)
{
@@ -3003,6 +3007,19 @@ static int read_options (int argc, char **argv) /* {{{ */
}
break;
+ case 'm':
+ {
+ int temp = atoi(optarg);
+ if (temp > 0)
+ config_alloc_chunk = temp;
+ else
+ {
+ fprintf(stderr, "Invalid allocation size: %s\n", optarg);
+ status = 10;
+ }
+ }
+ break;
+
case 'h':
case '?':
printf ("RRDCacheD %s\n"
--
1.6.4
More information about the rrd-developers
mailing list