Patchwork [4,of,4,V2] chgserver: start background preloading thread

login
register
mail settings
Submitter Jun Wu
Date Feb. 23, 2017, 2:16 a.m.
Message ID <5c44925eab9a42436996.1487816171@localhost.localdomain>
Download mbox | patch
Permalink /patch/18725/
State Changes Requested
Headers show

Comments

Jun Wu - Feb. 23, 2017, 2:16 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1487814470 28800
#      Wed Feb 22 17:47:50 2017 -0800
# Node ID 5c44925eab9a424369967e852b05f42443eac3a6
# Parent  28571825744fb4f4b424385f55afa9484532ef43
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5c44925eab9a
chgserver: start background preloading thread

A new boolean option chgserver.stateful is added. If set to True, chg master
will start the background repo preloading thread and becomes stateful.
Yuya Nishihara - Feb. 27, 2017, 4:08 p.m.
On Wed, 22 Feb 2017 18:16:11 -0800, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1487814470 28800
> #      Wed Feb 22 17:47:50 2017 -0800
> # Node ID 5c44925eab9a424369967e852b05f42443eac3a6
> # Parent  28571825744fb4f4b424385f55afa9484532ef43
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5c44925eab9a
> chgserver: start background preloading thread
> 
> A new boolean option chgserver.stateful is added. If set to True, chg master
> will start the background repo preloading thread and becomes stateful.
> 
> diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
> --- a/mercurial/chgserver.py
> +++ b/mercurial/chgserver.py
> @@ -37,4 +37,7 @@ Config
>    # whether to skip config or env change checks
>    skiphash = False
> +
> +  # whether to be stateful, and preload repo state in background
> +  stateful = False
>  """

Let's keep it undocumented for now.

> @@ -582,4 +585,26 @@ class chgunixservicehandler(object):
>                              self._hashstate, self._baseaddress)
>  
> +class chgunixforkingservice(commandserver.unixforkingservice):
> +    """like unixforkingservice with an optional chgcache.preloader"""
> +
> +    def __init__(self, ui, repo, opts, handler=None):
> +        super(chgunixforkingservice, self).__init__(ui, repo, opts, handler)
> +        if self.ui.configbool('chgserver', 'stateful'):
> +            self._preloader = chgcache.preloader()
> +        else:
> +            self._preloader = None
> +
> +    def init(self):
> +        super(chgunixforkingservice, self).init()
> +        if self._preloader is not None:
> +            self.ui.debug('starting background preloader\n')
> +            self._preloader.start()
> +
> +    def _cleanup(self):
> +        super(chgunixforkingservice, self)._cleanup()
> +        if self._preloader is not None:
> +            self.ui.debug('stopping background preloader\n')
> +            self._preloader.stop()

Can you add a couple of hooks to chgunixservicehandler to isolate chg stuff
from the service class?

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -37,4 +37,7 @@  Config
   # whether to skip config or env change checks
   skiphash = False
+
+  # whether to be stateful, and preload repo state in background
+  stateful = False
 """
 
@@ -582,4 +585,26 @@  class chgunixservicehandler(object):
                             self._hashstate, self._baseaddress)
 
+class chgunixforkingservice(commandserver.unixforkingservice):
+    """like unixforkingservice with an optional chgcache.preloader"""
+
+    def __init__(self, ui, repo, opts, handler=None):
+        super(chgunixforkingservice, self).__init__(ui, repo, opts, handler)
+        if self.ui.configbool('chgserver', 'stateful'):
+            self._preloader = chgcache.preloader()
+        else:
+            self._preloader = None
+
+    def init(self):
+        super(chgunixforkingservice, self).init()
+        if self._preloader is not None:
+            self.ui.debug('starting background preloader\n')
+            self._preloader.start()
+
+    def _cleanup(self):
+        super(chgunixforkingservice, self)._cleanup()
+        if self._preloader is not None:
+            self.ui.debug('stopping background preloader\n')
+            self._preloader.stop()
+
 def chgunixservice(ui, repo, opts):
     # CHGINTERNALMARK is temporarily set by chg client to detect if chg will
@@ -592,3 +617,3 @@  def chgunixservice(ui, repo, opts):
         ui.setconfig('bundle', 'mainreporoot', '', 'repo')
     h = chgunixservicehandler(ui)
-    return commandserver.unixforkingservice(ui, repo=None, opts=opts, handler=h)
+    return chgunixforkingservice(ui, repo=None, opts=opts, handler=h)