Mercurial > hg
view tests/dumbhttp.py @ 23225:bdf7b1ea1dae stable
changegroup: don't store unused value on fnodes (issue4443)
The contents of fnodes are only accessed once per key. It is wasteful to
cache the value since nobody will use it.
Before this patch, the caching of unused data in fnodes was effectively
causing a memory leak during the file streaming part of bundle creation.
On mozilla-central (which has ~190,000 entries in fnodes), this patch
has a significant impact on RSS at the end of generate():
before: 516,124 KB
after: 364,356 KB
delta: -151,768 KB
The origin of this code can be traced back to 627cd7842e5d and has been
with us since the 2.7 release.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 06 Nov 2014 22:33:48 -0800 |
parents | 10116463b0b1 |
children | 6eab50a34fed |
line wrap: on
line source
#!/usr/bin/env python """ Small and dumb HTTP server for use in tests. """ from optparse import OptionParser import BaseHTTPServer, SimpleHTTPServer, os, signal, subprocess, sys def run(server_class=BaseHTTPServer.HTTPServer, handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler, server_address=('localhost', 8000)): httpd = server_class(server_address, handler_class) httpd.serve_forever() if __name__ == '__main__': parser = OptionParser() parser.add_option('-p', '--port', dest='port', type='int', default=8000, help='TCP port to listen on', metavar='PORT') parser.add_option('-H', '--host', dest='host', default='localhost', help='hostname or IP to listen on', metavar='HOST') parser.add_option('--pid', dest='pid', help='file name where the PID of the server is stored') parser.add_option('-f', '--foreground', dest='foreground', action='store_true', help='do not start the HTTP server in the background') (options, args) = parser.parse_args() signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0)) if options.foreground and options.pid: parser.error("options --pid and --foreground are mutually exclusive") if options.foreground: run(server_address=(options.host, options.port)) else: # This doesn't attempt to cleanly detach the process, as it's not # meant to be a long-lived, independent process. As a consequence, # it's still part of the same process group, and keeps any file # descriptors it might have inherited besided stdin/stdout/stderr. # Trying to do things cleanly is more complicated, requires # OS-dependent code, and is not worth the effort. proc = subprocess.Popen([sys.executable, __file__, '-f', '-H', options.host, '-p', str(options.port)], stdin=open(os.devnull, 'r'), stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) if options.pid: fp = file(options.pid, 'wb') fp.write(str(proc.pid) + '\n') fp.close()