Mercurial > hg
view tests/lockdelay.py @ 39561:d06834e0f48e
wireprotov2peer: stream decoded responses
Previously, wire protocol version 2 would buffer all response data.
Only once all data was received did we CBOR decode it and resolve
the future associated with the command. This was obviously not
desirable. In future commits that introduce large response payloads,
this caused significant memory bloat and slowed down client
operations due to waiting on the server.
This commit refactors the response handling code so that response
data can be streamed.
Command response objects now contain a buffered CBOR decoder. As
new data arrives, it is fed into the decoder. Decoded objects are
made available to the generator as they are decoded.
Because there is a separate thread processing incoming frames and
feeding data into the response object, there is the potential for
race conditions when mutating response objects. So a lock has been
added to guard access to critical state variables.
Because the generator emitting decoded objects needs to wait on
those objects to become available, we've added an Event for the
generator to wait on so it doesn't busy loop. This does mean
there is the potential for deadlocks. And I'm pretty sure they can
occur in some scenarios. We already have a handful of TODOs around
this. But I've added some more. Fixing this will likely require
moving the background thread receiving frames into clienthandler.
We likely would have done this anyway when implementing the client
bits for the SSH transport.
Test output changes because the initial CBOR map holding the overall
response state is now always handled internally by the response
object.
Differential Revision: https://phab.mercurial-scm.org/D4474
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 29 Aug 2018 15:17:11 -0700 |
parents | a76d5ba7ac43 |
children | 2372284d9457 |
line wrap: on
line source
# Dummy extension that adds a delay after acquiring a lock. # # This extension can be used to test race conditions between lock acquisition. from __future__ import absolute_import import os import time def reposetup(ui, repo): class delayedlockrepo(repo.__class__): def lock(self): delay = float(os.environ.get('HGPRELOCKDELAY', '0.0')) if delay: time.sleep(delay) res = super(delayedlockrepo, self).lock() delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0')) if delay: time.sleep(delay) return res repo.__class__ = delayedlockrepo