Mercurial > public > mercurial-scm > hg
comparison mercurial/wireproto.py @ 28436:8d38eab2777a
peer: add an iterbatcher interface
This is very much like ordinary batch(), but it will let me add a mode
for batch where we have pathologically large requests which are then
handled streamily. This will be a significant improvement for things
like remotefilelog, which may want to request thousands of entities at
once.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 01 Mar 2016 18:39:25 -0500 |
parents | 176736afa886 |
children | 48fd02dac1d4 |
comparison
equal
deleted
inserted
replaced
28435:176736afa886 | 28436:8d38eab2777a |
---|---|
112 for encres, r in zip(encresults, rsp): | 112 for encres, r in zip(encresults, rsp): |
113 batchable, encresref, resref = r | 113 batchable, encresref, resref = r |
114 encresref.set(encres) | 114 encresref.set(encres) |
115 resref.set(batchable.next()) | 115 resref.set(batchable.next()) |
116 | 116 |
117 class remoteiterbatcher(peer.iterbatcher): | |
118 def __init__(self, remote): | |
119 super(remoteiterbatcher, self).__init__() | |
120 self._remote = remote | |
121 | |
122 def submit(self): | |
123 """Break the batch request into many patch calls and pipeline them. | |
124 | |
125 This is mostly valuable over http where request sizes can be | |
126 limited, but can be used in other places as well. | |
127 """ | |
128 rb = self._remote.batch() | |
129 rb.calls = self.calls | |
130 rb.submit() | |
131 | |
132 def results(self): | |
133 for name, args, opts, resref in self.calls: | |
134 yield resref.value | |
135 | |
117 # Forward a couple of names from peer to make wireproto interactions | 136 # Forward a couple of names from peer to make wireproto interactions |
118 # slightly more sensible. | 137 # slightly more sensible. |
119 batchable = peer.batchable | 138 batchable = peer.batchable |
120 future = peer.future | 139 future = peer.future |
121 | 140 |
190 cmds.append('%s %s' % (op, args)) | 209 cmds.append('%s %s' % (op, args)) |
191 rsp = self._call("batch", cmds=';'.join(cmds)) | 210 rsp = self._call("batch", cmds=';'.join(cmds)) |
192 return [unescapearg(r) for r in rsp.split(';')] | 211 return [unescapearg(r) for r in rsp.split(';')] |
193 def _submitone(self, op, args): | 212 def _submitone(self, op, args): |
194 return self._call(op, **args) | 213 return self._call(op, **args) |
214 | |
215 def iterbatch(self): | |
216 return remoteiterbatcher(self) | |
195 | 217 |
196 @batchable | 218 @batchable |
197 def lookup(self, key): | 219 def lookup(self, key): |
198 self.requirecap('lookup', _('look up remote revision')) | 220 self.requirecap('lookup', _('look up remote revision')) |
199 f = future() | 221 f = future() |