~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/chunk_writer.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-15 21:27:39 UTC
  • mto: This revision was merged to the branch mainline in revision 3791.
  • Revision ID: john@arbash-meinel.com-20081015212739-ap2uunpg6rjkypc1
Add ChunkWriter.optimize(for_size=True)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    #    In testing, some values for bzr.dev::
48
48
    #        repack  time  MB   max   full
49
49
    #         1       7.5  4.6  1140  0
50
 
    #         2       8.4  4.2  1036  1          6.8
 
50
    #         2       8.4  4.2  1036  1
51
51
    #         3       9.8  4.1  1012  278
52
52
    #         4      10.8  4.1  728   945
53
53
    #        20      11.1  4.1  0     1012
54
54
    #        repack = 0
55
 
    #        zsync   time  MB    repack  max_z   time w/ add_node
56
 
    #         0       6.7  24.7  0       6270    5.0
57
 
    #         1       6.5  13.2  0       3342    4.3
58
 
    #         2       6.6   9.6  0       2414    4.9
59
 
    #         5       6.5   6.2  0       1549    4.8
60
 
    #         6       6.5   5.8  1       1435    4.8
61
 
    #         7       6.6   5.5  19      1337    4.8
62
 
    #         8       6.7   5.3  81      1220    4.4
63
 
    #        10       6.8   5.0  260     967     5.3
64
 
    #        11       6.8   4.9  366     839     5.3
65
 
    #        12       6.9   4.8  454     731     5.1
66
 
    #        15       7.2   4.7  704     450     5.8
67
 
    #        20       7.7   4.6  1133    7       5.8
 
55
    #        zsync   time  MB    repack  stop_for_z
 
56
    #         0       5.0  24.7  0       6270
 
57
    #         1       4.3  13.2  0       3342
 
58
    #         2       4.9   9.6  0       2414
 
59
    #         5       4.8   6.2  0       1549
 
60
    #         6       4.8   5.8  1       1435
 
61
    #         7       4.8   5.5  19      1337
 
62
    #         8       4.4   5.3  81      1220
 
63
    #        10       5.3   5.0  260     967
 
64
    #        11       5.3   4.9  366     839
 
65
    #        12       5.1   4.8  454     731
 
66
    #        15       5.8   4.7  704     450
 
67
    #        20       5.8   4.6  1133    7
68
68
 
69
69
    #    In testing, some values for mysql-unpacked::
70
70
    #                next_bytes estim
71
 
    #        repack  time  MB    hit_max full
72
 
    #         1      51.7  15.4  3913  0
73
 
    #         2      54.4  13.7  3467  0         35.4
74
 
    #        20      67.0  13.4  0     3380      46.7
 
71
    #        repack  time  MB    full    stop_for_repack
 
72
    #         1            15.4  0       3913
 
73
    #         2      35.4  13.7  0       346
 
74
    #        20      46.7  13.4  3380    0
75
75
    #        repack=0
76
 
    #        zsync                               time w/ add_node
77
 
    #         0      47.7 116.5  0       29782   29.5
78
 
    #         1      48.5  60.2  0       15356   27.8
79
 
    #         2      48.1  42.4  0       10822   27.8
80
 
    #         5      48.3  25.5  0       6491    26.8
81
 
    #         6      48.0  23.2  13      5896    27.3
82
 
    #         7      48.1  21.6  29      5451    27.5
83
 
    #         8      48.1  20.3  52      5108    27.1
84
 
    #        10      46.9  18.6  195     4526    29.4
85
 
    #        11      48.8  18.0  421     4143    29.2
86
 
    #        12      47.4  17.5  702     3738    28.0
87
 
    #        15      49.6  16.5  1223    2969    28.9
88
 
    #        20      48.9  15.7  2182    1810    29.6
89
 
    #        30            15.4  3891    23      31.4
 
76
    #        zsync                       stop_for_z
 
77
    #         0      29.5 116.5  0       29782
 
78
    #         1      27.8  60.2  0       15356
 
79
    #         2      27.8  42.4  0       10822
 
80
    #         5      26.8  25.5  0       6491
 
81
    #         6      27.3  23.2  13      5896
 
82
    #         7      27.5  21.6  29      5451
 
83
    #         8      27.1  20.3  52      5108
 
84
    #        10      29.4  18.6  195     4526
 
85
    #        11      29.2  18.0  421     4143
 
86
    #        12      28.0  17.5  702     3738
 
87
    #        15      28.9  16.5  1223    2969
 
88
    #        20      29.6  15.7  2182    1810
 
89
    #        30      31.4  15.4  3891    23
90
90
 
91
 
    _max_repack = 0
92
 
    _max_zsync = 8
 
91
    # Tuple of (num_repack_attempts, num_zsync_attempts)
 
92
    # num_zsync_attempts only has meaning if num_repack_attempts is 0.
 
93
    _repack_opts_for_speed = (0, 8)
 
94
    _repack_opts_for_size = (20, 0)
93
95
 
94
96
    def __init__(self, chunk_size, reserved=0):
95
97
        """Create a ChunkWriter to write chunk_size chunks.
110
112
        self.num_zsync = 0
111
113
        self.unused_bytes = None
112
114
        self.reserved_size = reserved
 
115
        # Default is to make building fast rather than compact
 
116
        self._max_repack, self._max_zsync = ChunkWriter._repack_opts_for_speed
 
117
 
 
118
    def optimize(self, for_size=True):
 
119
        """Change how we optimize our writes.
 
120
 
 
121
        :param for_size: If True, optimize for minimum space usage, otherwise
 
122
            optimize for fastest writing speed.
 
123
        :return: None
 
124
        """
 
125
        if for_size:
 
126
            opts = ChunkWriter._repack_opts_for_size
 
127
        else:
 
128
            opts = ChunkWriter._repack_opts_for_speed
 
129
        self._max_repack, self._max_zsync = opts
113
130
 
114
131
    def finish(self):
115
132
        """Finish the chunk.