[pve-devel] r5563 - pve-manager/pve2/bin/test

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Feb 18 07:41:45 CET 2011


Author: dietmar
Date: 2011-02-18 07:41:45 +0100 (Fri, 18 Feb 2011)
New Revision: 5563

Modified:
   pve-manager/pve2/bin/test/example1.pl
   pve-manager/pve2/bin/test/perftest1.pl
Log:
fix examples


Modified: pve-manager/pve2/bin/test/example1.pl
===================================================================
--- pve-manager/pve2/bin/test/example1.pl	2011-02-18 05:40:06 UTC (rev 5562)
+++ pve-manager/pve2/bin/test/example1.pl	2011-02-18 06:41:45 UTC (rev 5563)
@@ -3,20 +3,22 @@
 
 use strict;
 use PVE::API2Client;
-use PVE::Config;
+use PVE::AccessControl;
+use PVE::INotify;
 
 use Data::Dumper;
 
-my $ticket = "root::root::";
+my $hostname = PVE::INotify::read_file("hostname");
 
-my $hostname = PVE::Config::read_file ("hostname");
+# normally you use username/password,
+# but we can simply create a ticket if we are root
+my $ticket = PVE::AccessControl::assemble_ticket('root');
 
 my $conn = PVE::API2Client->new(
-    username => 'root',
-    password => 'admin',
-#    ticket => $ticket,
+#    username => 'root',
+#    password => 'yourpassword',
+    ticket => $ticket,
     host => $hostname,
-#   host => 'localhost',
     );
 
 my $res = $conn->get("api2/json/", {});

Modified: pve-manager/pve2/bin/test/perftest1.pl
===================================================================
--- pve-manager/pve2/bin/test/perftest1.pl	2011-02-18 05:40:06 UTC (rev 5562)
+++ pve-manager/pve2/bin/test/perftest1.pl	2011-02-18 06:41:45 UTC (rev 5563)
@@ -4,25 +4,27 @@
 use strict;
 use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
 use PVE::API2Client;
-use PVE::Config;
+use PVE::INotify;
+
 use Data::Dumper;
 
-# fixme: create correct ticket
-my $ticket = "root::root::";
+my $hostname = PVE::INotify::read_file("hostname");
 
+# normally you use username/password,
+# but we can simply create a ticket if we are root
+my $ticket = PVE::AccessControl::assemble_ticket('root');
+
 my $wcount = 4;
 my $qcount = 500;
 
-my $hostname = PVE::Config::read_file ("hostname");
-
 sub test_rpc {
+    my ($host) = @_;
 
     my $conn = PVE::API2Client->new(
-	username => 'root',
-	password => 'admin',
-	#    ticket => $ticket,
-	host => $hostname,
-	#host => 'localhost',
+	#username => 'root',
+	#password => 'yourpassword',
+	ticket => $ticket,
+	host => $host,
 	);
 
     for (my $i = 0; $i < $qcount; $i++) {
@@ -39,25 +41,35 @@
 	}
     }
 }
-my $workers;
 
-my $starttime = [gettimeofday];
+sub run_tests {
+    my ($host) = @_;
+    
+    my $workers;
 
-for (my $i = 0; $i < $wcount; $i++) {
-    if (my $pid = fork ()) {
-	$workers->{$pid} = 1;
-    } else {
-	test_rpc ();
-	exit (0);
+    my $starttime = [gettimeofday];
+
+    for (my $i = 0; $i < $wcount; $i++) {
+	if (my $pid = fork ()) {
+	    $workers->{$pid} = 1;
+	} else {
+	    test_rpc ($host);
+	    exit (0);
+	}
     }
-}
 
+    # wait for children
+    1 while (wait > 0);
 
-# wait for children
-1 while (wait > 0);
+    my $elapsed = int(tv_interval ($starttime) * 1000);
 
-my $elapsed = int(tv_interval ($starttime) * 1000);
+    my $tpq = $elapsed / ($wcount*$qcount);
 
-my $tpq = $elapsed / ($wcount*$qcount);
+    print "$host: $tpq ms per query\n";
+}
 
-print "DONE: $tpq ms per query\n";
+# TODO: Apache is much slower, why? 
+
+run_tests("localhost"); # test 'pvedaemon'
+
+run_tests($hostname); # test 'apache'



More information about the pve-devel mailing list