Rev 2672: * New method ``bzrlib.transport.Transport.get_recommended_page_size``. in http://people.ubuntu.com/~robertc/baz2.0/transport

Robert Collins robertc at robertcollins.net
Sun Aug 5 02:47:48 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/transport

------------------------------------------------------------
revno: 2672
revision-id: robertc at robertcollins.net-20070805014730-qjx8zkquv3pagglo
parent: pqm at pqm.ubuntu.com-20070803043116-l7u1uypblmx1uxnr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: transport-get-file
timestamp: Sun 2007-08-05 11:47:30 +1000
message:
  * New method ``bzrlib.transport.Transport.get_recommended_page_size``.
    This provides a hint to users of transports as to the reasonable
    minimum data to read. In principle this can take latency and
    bandwidth into account on a per-connection basis, but for now it
    just has hard coded values based on the url. (e.g. http:// has a large
    page size, file:// has a small one.) (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/transport/decorator.py  decorator.py-20060402223305-e913a0f25319ab42
  bzrlib/transport/ftp.py        ftp.py-20051116161804-58dc9506548c2a53
  bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
  bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
=== modified file 'NEWS'
--- a/NEWS	2007-08-02 07:22:05 +0000
+++ b/NEWS	2007-08-05 01:47:30 +0000
@@ -195,6 +195,13 @@
     * ``bzrlib.pack.make_readv_reader`` allows readv based access to pack
       files that are stored on a transport. (Robert Collins)
 
+    * New method ``bzrlib.transport.Transport.get_recommended_page_size``.
+      This provides a hint to users of transports as to the reasonable
+      minimum data to read. In principle this can take latency and
+      bandwidth into account on a per-connection basis, but for now it
+      just has hard coded values based on the url. (e.g. http:// has a large
+      page size, file:// has a small one.) (Robert Collins)
+
   TESTING:
 
     * Remove selftest ``--clean-output``, ``--numbered-dirs`` and

=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py	2007-07-20 18:59:29 +0000
+++ b/bzrlib/tests/test_transport_implementations.py	2007-08-05 01:47:30 +0000
@@ -866,6 +866,11 @@
         # plain "listdir".
         # self.assertEqual([], os.listdir('.'))
 
+    def test_recommended_page_size(self):
+        """Transports recommend a page size for partial access to files."""
+        t = self.get_transport()
+        self.assertIsInstance(t.recommended_page_size(), int)
+
     def test_rmdir(self):
         t = self.get_transport()
         # Not much to do with a readonly transport

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2007-07-22 17:18:05 +0000
+++ b/bzrlib/transport/__init__.py	2007-08-05 01:47:30 +0000
@@ -460,6 +460,18 @@
             path = '/' + path
         return path
 
+    def recommended_page_size(self):
+        """Return the recommended page size for this transport.
+
+        This is potentially different for every path in a given namespace.
+        For example, local transports might use an operating system call to 
+        get the block size for a given path, which can vary due to mount
+        points.
+
+        :return: The page size in bytes.
+        """
+        return 4 * 1024
+
     def relpath(self, abspath):
         """Return the local path portion from a given absolute path.
 

=== modified file 'bzrlib/transport/decorator.py'
--- a/bzrlib/transport/decorator.py	2007-07-20 03:20:20 +0000
+++ b/bzrlib/transport/decorator.py	2007-08-05 01:47:30 +0000
@@ -130,6 +130,10 @@
         """See Transport.list_dir()."""
         return self._decorated.list_dir(relpath)
 
+    def recommended_page_size(self):
+        """See Transport.recommended_page_size()."""
+        return self._decorated.recommended_page_size()
+
     def rename(self, rel_from, rel_to):
         return self._decorated.rename(rel_from, rel_to)
     

=== modified file 'bzrlib/transport/ftp.py'
--- a/bzrlib/transport/ftp.py	2007-07-20 18:59:29 +0000
+++ b/bzrlib/transport/ftp.py	2007-08-05 01:47:30 +0000
@@ -323,6 +323,14 @@
             self._translate_perm_error(e, abspath,
                 unknown_exc=errors.FileExists)
 
+    def recommended_page_size(self):
+        """See Transport.recommended_page_size().
+
+        For FTP we suggest a large page size to reduce the overhead
+        introduced by latency.
+        """
+        return 64 * 1024
+
     def rmdir(self, rel_path):
         """Delete the directory at rel_path"""
         abspath = self._remote_path(rel_path)

=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py	2007-07-20 18:59:29 +0000
+++ b/bzrlib/transport/http/__init__.py	2007-08-05 01:47:30 +0000
@@ -294,6 +294,14 @@
             # After one or more tries, we get the data.
             yield start, data
 
+    def recommended_page_size(self):
+        """See Transport.recommended_page_size().
+
+        For HTTP we suggest a large page size to reduce the overhead
+        introduced by latency.
+        """
+        return 64 * 1024
+
     @staticmethod
     @deprecated_method(zero_seventeen)
     def offsets_to_ranges(offsets):

=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py	2007-07-20 18:59:29 +0000
+++ b/bzrlib/transport/sftp.py	2007-08-05 01:47:30 +0000
@@ -257,6 +257,14 @@
         except (IOError, paramiko.SSHException), e:
             self._translate_io_exception(e, path, ': error retrieving')
 
+    def recommended_page_size(self):
+        """See Transport.recommended_page_size().
+
+        For SFTP we suggest a large page size to reduce the overhead
+        introduced by latency.
+        """
+        return 64 * 1024
+
     def _sftp_readv(self, fp, offsets, relpath='<unknown>'):
         """Use the readv() member of fp to do async readv.
 



More information about the bazaar-commits mailing list