Rev 1: Create a simple plugin that allows me to time content extraction. in http://bzr.arbash-meinel.com/plugins/dummy_request
John Arbash Meinel
john at arbash-meinel.com
Sat Dec 12 20:43:40 GMT 2009
At http://bzr.arbash-meinel.com/plugins/dummy_request
------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20091212204332-00g8lyfngbi4cnru
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dummy_request
timestamp: Sat 2009-12-12 14:43:32 -0600
message:
Create a simple plugin that allows me to time content extraction.
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py 1970-01-01 00:00:00 +0000
+++ b/__init__.py 2009-12-12 20:43:32 +0000
@@ -0,0 +1,110 @@
+# Copyright (C) 2009 Canonical 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Make a stream request against a smart server and throw away the content.
+
+This is mostly about measuring throughput, etc.
+"""
+
+import cStringIO
+import os
+import time
+
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
+import tempfile
+
+from bzrlib import (
+ branch,
+ graph,
+ remote,
+ transport,
+ )
+from bzrlib.repofmt import (
+ groupcompress_repo,
+ )
+from bzrlib.smart import (
+ client as _mod_client,
+ medium as _mod_medium,
+ )
+""")
+from bzrlib import (
+ commands,
+ errors,
+ option,
+ )
+
+
+def make_server(in_file, out_file, transport):
+ return _mod_medium.SmartServerPipeStreamMedium(in_file, out_file, transport)
+
+
+# TODO: Create a file where we can monitor throughput rather than just total
+# time
+
+
+class cmd_test_stream(commands.Command):
+ """Make a stream request.
+
+ """
+
+ takes_options = [option.Option('keep', help='keep the output files')]
+
+ def run(self, keep=False):
+ b = branch.Branch.open('.')
+ req_fn, req_name = tempfile.mkstemp(prefix='bzr-request-')
+ resp_fn, resp_name = tempfile.mkstemp(prefix='bzr-response-')
+ self.outf.write('Request file: %s\n' % req_name)
+ self.outf.write('Response file: %s\n' % resp_name)
+ req_f = os.fdopen(req_fn, 'wb+')
+ # TODO: Make the resp_f a wrapper that tracks throughput,
+ # alternatively, we could also wrap it around a simple list
+ # structure, so that we avoid any sort of disk I/O limitations
+ resp_f = os.fdopen(resp_fn, 'wb+')
+ # We don't have the client ever read the response, we just place the
+ # request into the temp file
+ t = b.repository.bzrdir.root_transport
+ medium = _mod_medium.SmartSimplePipesClientMedium(None, req_f,
+ base=t.base)
+ client = _mod_client._SmartClient(medium)
+ server = _mod_medium.SmartServerPipeStreamMedium(req_f, resp_f, t)
+ # Now, place the request
+ search_parts = ['ancestry-of', b.last_revision()]
+ search_bytes = '\n'.join(search_parts)
+ fmt = groupcompress_repo.RepositoryFormat2a()
+ args = ('', fmt.network_name())
+ body = search_bytes
+ client._send_request(3, 'Repository.get_stream_1.19', args,
+ search_bytes)
+ # The request should have been put into the request file
+ req_f.seek(0)
+ # This should trigger a single request, and then stop, putting the
+ # output int othe response file
+ start_time = time.clock()
+ server.serve()
+ delta_time = time.clock() - start_time
+ bytes_written = resp_f.tell()
+ mb_written = bytes_written / 1024. / 1024
+ self.outf.write('Wrote %d bytes (%.1f MiB) in %.3fs, %.3fMiB/s\n'
+ % (bytes_written, mb_written, delta_time,
+ mb_written / delta_time))
+ req_f.close()
+ resp_f.close()
+ if not keep:
+ os.remove(req_name)
+ os.remove(resp_name)
+
+commands.register_command(cmd_test_stream)
More information about the bazaar-commits
mailing list