[pve-devel] r5686 - in pve-cluster/trunk/data: perl src

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Mar 11 08:59:40 CET 2011


Author: dietmar
Date: 2011-03-11 08:59:40 +0100 (Fri, 11 Mar 2011)
New Revision: 5686

Modified:
   pve-cluster/trunk/data/perl/Cluster.pm
   pve-cluster/trunk/data/src/status.c
Log:
cache rrd dump


Modified: pve-cluster/trunk/data/perl/Cluster.pm
===================================================================
--- pve-cluster/trunk/data/perl/Cluster.pm	2011-03-11 07:23:23 UTC (rev 5685)
+++ pve-cluster/trunk/data/perl/Cluster.pm	2011-03-11 07:59:40 UTC (rev 5686)
@@ -415,7 +415,8 @@
 
     my $ctime = time();
 
-    if (($ctime - $last_rrd_dump) < 1) {
+    my $diff = $ctime - $last_rrd_dump;
+    if ($diff < 2) {
 	return $last_rrd_data;
     }
 

Modified: pve-cluster/trunk/data/src/status.c
===================================================================
--- pve-cluster/trunk/data/src/status.c	2011-03-11 07:23:23 UTC (rev 5685)
+++ pve-cluster/trunk/data/src/status.c	2011-03-11 07:59:40 UTC (rev 5686)
@@ -896,8 +896,6 @@
 	g_return_if_fail(len > 0);
 	g_return_if_fail(len < 4096);
 
-	// fixme: when do we remove old entries ?
-
 	static const char *rrdcsock = "unix:/var/run/rrdcached.sock";
 
 	int use_daemon = 1;
@@ -1026,14 +1024,20 @@
 	return (diff > expire) ? TRUE : FALSE;
 }
 
+static char *rrd_dump_buf = NULL;
+static time_t rrd_dump_last = 0;
+
 void
 cfs_rrd_dump(GString *str)
 {
-	// fixme: cache result ?
-
 	time_t ctime;
 	time(&ctime);
 
+	if (rrd_dump_buf && (ctime - rrd_dump_last) < 2) {
+		g_string_assign(str, rrd_dump_buf);
+		return;
+	}
+
 	/* remove old data */
 	g_hash_table_foreach_remove(cfs_status.rrdhash, rrd_entry_is_old,  
 				    GUINT_TO_POINTER(ctime));
@@ -1054,6 +1058,11 @@
 	}
 
 	g_string_append_c(str, 0); // never return undef
+
+	rrd_dump_last = ctime;
+	if (rrd_dump_buf)
+		g_free(rrd_dump_buf);
+	rrd_dump_buf = g_strdup(str->str);
 }
 
 static gboolean 




More information about the pve-devel mailing list