annotate mercurial/node.py @ 26623:5a95fe44121d

clonebundles: support for seeding clones from pre-generated bundles Cloning can be an expensive operation for servers because the server generates a bundle from existing repository data at request time. For a large repository like mozilla-central, this consumes 4+ minutes of CPU time on the server. It also results in significant network utilization. Multiplied by hundreds or even thousands of clients and the ensuing load can result in difficulties scaling the Mercurial server. Despite generation of bundles being deterministic until the next changeset is added, the generation of bundles to service a clone request is not cached. Each clone thus performs redundant work. This is wasteful. This patch introduces the "clonebundles" extension and related client-side functionality to help alleviate this deficiency. The client-side feature is behind an experimental flag and is not enabled by default. It works as follows: 1) Server operator generates a bundle and makes it available on a server (likely HTTP). 2) Server operator defines the URL of a bundle file in a .hg/clonebundles.manifest file. 3) Client `hg clone`ing sees the server is advertising bundle URLs. 4) Client fetches and applies the advertised bundle. 5) Client performs equivalent of `hg pull` to fetch changes made since the bundle was created. Essentially, the server performs the expensive work of generating a bundle once and all subsequent clones fetch a static file from somewhere. Scaling static file serving is a much more manageable problem than scaling a Python application like Mercurial. Assuming your repository grows less than 1% per day, the end result is 99+% of CPU and network load from clones is eliminated, allowing Mercurial servers to scale more easily. Serving static files also means data can be transferred to clients as fast as they can consume it, rather than as fast as servers can generate it. This makes clones faster. Mozilla has implemented similar functionality of this patch on hg.mozilla.org using a custom extension. We are hosting bundle files in Amazon S3 and CloudFront (a CDN) and have successfully offloaded >1 TB/day in data transfer from hg.mozilla.org, freeing up significant bandwidth and CPU resources. The positive impact has been stellar and I believe it has proved its value to be included in Mercurial core. I feel it is important for the client-side support to be enabled in core by default because it means that clients will get faster, more reliable clones and will enable server operators to reduce load without requiring any client-side configuration changes (assuming clients are up to date, of course). The scope of this feature is narrowly and specifically tailored to cloning, despite "serve pulls from pre-generated bundles" being a valid and useful feature. I would eventually like for Mercurial servers to support transferring *all* repository data via statically hosted files. You could imagine a server that siphons all pushed data to bundle files and instructs clients to apply a stream of bundles to reconstruct all repository data. This feature, while useful and powerful, is significantly more work to implement because it requires the server component have awareness of discovery and a mapping of which changesets are in which files. Full, clone bundles, by contrast, are much simpler. The wire protocol command is named "clonebundles" instead of something more generic like "staticbundles" to leave the door open for a new, more powerful and more generic server-side component with minimal backwards compatibility implications. The name "bundleclone" is used by Mozilla's extension and would cause problems since there are subtle differences in Mozilla's extension. Mozilla's experience with this idea has taught us that some form of "content negotiation" is required. Not all clients will support all bundle formats or even URLs (advanced TLS requirements, etc). To ensure the highest uptake possible, a server needs to advertise multiple versions of bundles and clients need to be able to choose the most appropriate from that list one. The "attributes" in each server-advertised entry facilitate this filtering and sorting. Their use will become apparent in subsequent patches. Initial inspiration and credit for the idea of cloning from static files belongs to Augie Fackler and his "lookaside clone" extension proof of concept.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 09 Oct 2015 11:22:01 -0700
parents 738314da6c75
children 18f50b8cbf1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8226
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
1 # node.py - basic nodeid manipulation for mercurial
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
2 #
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
4 #
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8226
diff changeset
6 # GNU General Public License version 2 or any later version.
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
7
25962
738314da6c75 node: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25737
diff changeset
8 from __future__ import absolute_import
738314da6c75 node: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25737
diff changeset
9
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3578
diff changeset
10 import binascii
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
11
3578
3b4e00cba57a Define and use nullrev (revision of nullid) instead of -1.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2859
diff changeset
12 nullrev = -1
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
13 nullid = "\0" * 20
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
14
25737
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
15 # pseudo identifiers for working directory
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
16 # (they are experimental, so don't add too many dependencies on them)
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
17 wdirrev = 0x7fffffff
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
18 wdirid = "\xff" * 20
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
19
4995
e45fc5d03798 manifest: speed up creation of the manifestdict
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
20 # This ugly style has a noticeable effect in manifest parsing
e45fc5d03798 manifest: speed up creation of the manifestdict
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
21 hex = binascii.hexlify
e45fc5d03798 manifest: speed up creation of the manifestdict
Matt Mackall <mpm@selenic.com>
parents: 3877
diff changeset
22 bin = binascii.unhexlify
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
23
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
24 def short(node):
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
25 return hex(node[:6])