[pve-devel] r5679 - in pve-cluster/trunk/data: . perl

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Mar 10 13:35:03 CET 2011


Author: dietmar
Date: 2011-03-10 13:35:03 +0100 (Thu, 10 Mar 2011)
New Revision: 5679

Modified:
   pve-cluster/trunk/data/ChangeLog
   pve-cluster/trunk/data/perl/Cluster.pm
Log:
 cache RRD data for one second (avoid
	to many reads from API server)


Modified: pve-cluster/trunk/data/ChangeLog
===================================================================
--- pve-cluster/trunk/data/ChangeLog	2011-03-10 11:53:46 UTC (rev 5678)
+++ pve-cluster/trunk/data/ChangeLog	2011-03-10 12:35:03 UTC (rev 5679)
@@ -1,5 +1,8 @@
 2011-03-10  Proxmox Support Team  <support at proxmox.com>
 
+	* perl/Cluster.pm (rrd_dump): cache RRD data for one second (avoid
+	to many reads from API server)
+
 	* src/status.c (update_rrd_data): add RRD definition for VMs 
 	(update_rrd_data): use thread safe API, connect to rrdcached
 

Modified: pve-cluster/trunk/data/perl/Cluster.pm
===================================================================
--- pve-cluster/trunk/data/perl/Cluster.pm	2011-03-10 11:53:46 UTC (rev 5678)
+++ pve-cluster/trunk/data/perl/Cluster.pm	2011-03-10 12:35:03 UTC (rev 5679)
@@ -408,14 +408,29 @@
     warn $err if $err;
 }
 
+my $last_rrd_dump = 0;
+my $last_rrd_data = "";
+
 sub rrd_dump {
+
+    my $ctime = time();
+
+    if (($ctime - $last_rrd_dump) < 1) {
+	return $last_rrd_data;
+    }
+
     my $res;
     eval {
 	$res = &$ipcc_send_rec(10);
     };
     my $err = $@;
 
-    warn $err if $err;
+    if ($err) {
+	warn $err;
+    } else {
+	$last_rrd_dump = $ctime;
+	$last_rrd_data = $res;
+    }
 
     return $res;
 }



More information about the pve-devel mailing list