Skip to content
Snippets Groups Projects
  1. Mar 25, 2021
  2. Mar 23, 2021
  3. May 25, 2021
  4. Apr 04, 2021
    • Georges Racinet's avatar
      message: wrapper class for easy logging · 10be0d6a
      Georges Racinet authored
      With gRPC, the `repr` of messages, notably Gitaly Requests
      is made of multiple lines.
      This is very bad for logging: a log should always be made of
      a single line for:
      
      - meaningful grepping
      - detangling when several processes log to the same file
      
      We want in particular service method to be able to log
      easily their incoming requests and/or more messages, but
      we want the formatting to be done only if the log is
      actually to be emitted (important to avoid debug logs to
      make production servers choke). This is usually achieved with
      the following pattern, because logging evaluation is inherently
      lazy.
      
      ```python
      logging.debug('the interesting object is %r', obj)
      ```
      
      We could use extras, as `hg-loggingmod` does for the repository,
      but that is evaluated in the final formatting of the entire log
      line, and requires to register a specific format, then a specific
      handler to use it.
      
      The provided solution (wrapping in a class), is not zero-cost,
      but is expected to be cheap enough for the time being.
      10be0d6a
  5. May 18, 2021
  6. Apr 25, 2021
  7. Apr 22, 2021
  8. Apr 11, 2021
  9. Apr 21, 2021
    • Georges Racinet's avatar
      Blob service: streaming in chunks of WRITE_BUFFER_SIZE · 92c2deb0
      Georges Racinet authored
      The reason why Gitaly does not respect `WRITE_BUFFER_SIZE`
      even though the Blob serving method go through its
      `streamio.SendWriter` object which enforces it is now
      roughly understood: the `SendWriter` object is called for
      the smaller chunks generated by `io.CopyN`.
      
      Since this does not look to be the actual intent in Gitaly
      and may be corrected later, we make HGitaly abide to
      `WRITE_BUFFER_SIZE` right away. This makes our code
      more consistent.
      
      Also, this makes the default chunk size go up from 16kB to
      128kB. It wouldn't be very surprising if the penalty for
      chunks that are too small (number of requests multiplied by 8)
      would be bigger in a Python program than in a Go program, because
      we may have a higher overhead per request.
      92c2deb0
    • Georges Racinet's avatar
      Gitaly Comparison tests: Gitaly Blob chunking can vary · 9e62dfcb
      Georges Racinet authored
      This fixes a flakiness in the comparison tests for `get_blob` and
      `get_blobs`: Gitaly's chunking is not constant, seems to depend
      on the (circumstantial) size of some inner buffers or similar.
      Hence a direct comparison of Gitaly and HGitaly responses is
      flay.
      
      Instead, we are focusing on what matters: repetition of metadata
      like oid and size (or not) and of course that the whole content
      is correct.
      9e62dfcb
  10. Apr 22, 2021
  11. Apr 15, 2021
    • Georges Racinet's avatar
      New dev cycle · 4d4be16d
      Georges Racinet authored
      4d4be16d
    • Georges Racinet's avatar
      e87cb7e1
    • Georges Racinet's avatar
    • Georges Racinet's avatar
      Merged stable branch into default · fb6208ac
      Georges Racinet authored
      fb6208ac
    • Georges Racinet's avatar
      New stable dev cycle · 065e782d
      Georges Racinet authored
      065e782d
    • Georges Racinet's avatar
      8a8b7f11
    • Georges Racinet's avatar
    • Georges Racinet's avatar
      server: mono-process mode · bdd1f208
      Georges Racinet authored
      The forking that the `hgitaly-serve` command is doing by
      default is harmful when we want to debug with pdb: request
      handling always end in an error. The new `--mono-process`
      option solves that by serving directly from the main process.
      This is probably a matter of forwarding all the
      right file descriptors for the tty, but it's not worth
      the investigation time when there is such a simple solution.
      
      Could have done it in the command itself, but this is probably
      easier to maintain in the `server` module and certainly easier
      to test.
      
      No strong assertions that it doesn't fork in the test, but
      coverage proves that the early return got executed; that should
      be enough.
      bdd1f208
    • Georges Racinet's avatar
      load_repo: fix the class leak for sharedrepo source as well · 58e290c6
      Georges Racinet authored
      Previous fixes have been developed and measured in a Python 3.9
      virtualenv (HDK). Replaying the measurements in a Python 3.8 HDK
      (the only supported Python version in all current Heptapod branches)
      immediately showed that this wasn't enough.
      
      After reconstruction of the virtualenv with Python 3.8, it became
      obvious that repository instances (and classes) where doubled, and
      the reason was the systematic instantiation of a sharedrepo source.
      Applying the same treatment for the latter got us back to the
      improvement previously obtained.
      
      It seems frankly dubious that the Python version is really
      implicated, but it could happen: we're after all dealing with stuff
      that the GC didn't clear by itself. Still, it could simply have been
      a matter of library version (not Mercurial, it's the same one).
      58e290c6
    • Georges Racinet's avatar
      load_repo: forcing garbage collection every 1000 calls. · 56bcfbb5
      Georges Racinet authored
      For something similar with hgweb, look at changeset ff2370a70fe8
      in Mercurial.
      
      Surprisingly, this does not change the memory footprint in our
      current investigations (which is just using examples/client.py
      with more calls). This means that the regular garbage collector
      was able to reap benefits of the parent changeset (calling
      `gc.collect()` is supposed to be more aggressive on the oldest
      generation).
      
      Still, keeping this as a safety net because our example certainly
      wouldn't cover all possible situations
      
      With rates of 100 and 500, the new log lines show us the GC
      working, with more to collect at 500 than at 100. But at 1000,
      we get back to the same amounts of collected objects and time
      spent than with 100. This suggests that this is close to the
      natural rate, hence we aren't really harming performance.
      
      In any case, this is a constant, and we could make it more
      configurable if needed.
      56bcfbb5
    • Georges Racinet's avatar
      load_repo: main cure for memory leak · 73abd75e
      Georges Racinet authored
      This brings down the leaking over 1000 requests from
      55MB to about 5MB. We are not yet forcing garbage collection
      (as `hgwebdir` does).
      
      The `_filteredrepotypes` keeps a correspondence between
      unfiltered repository classes and the filtered version.
      
      The problem is that each new repository is an instance of
      the single-usage class generated in `hgext3rd.topic.reposetup`,
      so these accumulate in `_filteredrepotypes`.
      
      Ironically the mapping seems to be there to avoid some other
      case of leaking:
      
      ```
      # Python <3.4 easily leaks types via __mro__. See
      # https://bugs.python.org/issue17950. We cache dynamically created types
      # so they won't be leaked on every invocation of repo.filtered().
      _filteredrepotypes = weakref.WeakKeyDictionary()
      ```
      
      One could imagine that garbage collection of the repo would also just
      clear its reference from the `WeakKeyDictionary`, but it doesn't
      happen.
      
      A final suprise is that this unlocks the collection of `ui` instances.
      According to investigation made with `guppy3` the class objects were
      actually the ones eating the most memory, but getting rid of `ui`
      instances is also good news.
      73abd75e
    • Georges Racinet's avatar
      load_repo: avoid useless ui object copy · e15ae399
      Georges Racinet authored
      Found out while investigating heptapod#466 that actually
      the machinery behind `hg.repository` actually performs a
      copy on its own. Our copy was adding pressure on the
      Python memory system. This does not cure the memory leak,
      but it saves about 2MB of leak over 1000 requests, even though
      it doesn't change the fact that none of these ui instances
      are actually collected (seen through instrumentation not
      part of this changeset).
      
      From `localrepo.py` in Mercurial 5.6.1:
      
      ```
      def makelocalrepository(baseui, path, intents=None):
          """Long docstring not cited here."""
          ui = baseui.copy()
          # Prevent copying repo configuration.
          ui.copy = baseui.copy
          (...)
      ```
      
      Note that this last line actually prevents `baseui` (
      would be the copy we were creating) to be freed immediately.
      
      makelocalrepository in turn is called via this backtrace:
      
      ```
        venv/lib64/python3.9/site-packages/mercurial/hg.py(221)repository()
      -> peer = _peerorrepo(
        venv/lib64/python3.9/site-packages/mercurial/hg.py(188)_peerorrepo()
      -> obj = _peerlookup(path).instance(
        venv/lib64/python3.9/site-packages/mercurial/localrepo.py(3214)instance()
      -> return makelocalrepository(ui, localpath, intents=intents)
      > venv/lib64/python3.9/site-packages/mercurial/localrepo.py(517)makelocalrepository()
      -> ui = baseui.copy()
      
      ```
      e15ae399
    • Georges Racinet's avatar
      load_repo: using a local variable before returning · 09d6901c
      Georges Racinet authored
      This will make instrumentation for memory investigation
      easier.
      09d6901c
    • Georges Racinet's avatar
      Merge branch 'topic/default/blob-tree' into 'branch/default' · e509cf7b
      Georges Racinet authored
      Blob and Tree related service methods
      
      Closes #16, #43, and #44
      
      See merge request !57
      e509cf7b
Loading