Rev 1: A simple plugin for timing connection to a smart server. in http://bzr.arbash-meinel.com/plugins/hello

John Arbash Meinel john at arbash-meinel.com
Fri Oct 26 17:23:44 BST 2007


At http://bzr.arbash-meinel.com/plugins/hello

------------------------------------------------------------
revno: 1
revision-id:john at arbash-meinel.com-20071026162342-q0kwteylii2zrkw5
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: hello
timestamp: Fri 2007-10-26 11:23:42 -0500
message:
  A simple plugin for timing connection to a smart server.
added:
  __init__.py                    __init__.py-20071026162324-fyzesbthcgxhqy4b-1
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py	1970-01-01 00:00:00 +0000
+++ b/__init__.py	2007-10-26 16:23:42 +0000
@@ -0,0 +1,70 @@
+# Copyright (C) 2007 Canonical Development Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Connect to a Bazaar smart server, and just say hello.
+"""
+
+import time
+
+from bzrlib import (
+    commands,
+    option,
+    transport,
+    )
+
+
+class cmd_hello(commands.Command):
+    """Say hello to a Bazaar smart server.
+
+    """
+
+    takes_args = ['location']
+    takes_options = [option.Option('ping',
+                        help='Test the round trip time to the server.'),
+                    ]
+
+    def run(self, location=None, ping=False):
+        from bzrlib.smart import client
+        start = time.time()
+        t = transport.get_transport(location)
+        t_time = time.time()
+        medium = t.get_shared_medium()
+        medium_time = time.time()
+        the_client = client._SmartClient(medium)
+        client_time = time.time()
+        hello_response = the_client.call('hello')
+        hello_time = time.time()
+        print 'response: %s' % (hello_response,)
+        print "get_transport: %.3fs" % (t_time - start,)
+        print "get_shared_medium: %.3fs" % (medium_time - t_time,)
+        print "client: %.3fs" % (client_time - medium_time,)
+        print "hello: %.3fs" % (hello_time - client_time,)
+
+        if ping:
+            total_time = 0.0
+            n_count = 20
+            for i in xrange(n_count):
+                base_time = time.time()
+                the_client.call('hello')
+                cur_time = time.time()
+                total_time += cur_time - base_time
+                print 'hello: %.3fs\r' % (cur_time - base_time,),
+            avg_time = total_time / n_count
+            print 'Average ping: %.3fms' % (avg_time * 1000.0)
+            hello_delta = hello_time - client_time
+            print 'Connect time: %.3fs' % (hello_delta - avg_time,)
+
+commands.register_command(cmd_hello)



More information about the bazaar-commits mailing list