Merge lp:~jameinel/launchpad/loggerhead-clear-cache into lp:launchpad

Proposed by John A Meinel
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 15819
Proposed branch: lp:~jameinel/launchpad/loggerhead-clear-cache
Merge into: lp:launchpad
Diff against target: 16 lines (+6/-0)
1 file modified
lib/launchpad_loggerhead/app.py (+6/-0)
To merge this branch: bzr merge lp:~jameinel/launchpad/loggerhead-clear-cache
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+119793@code.launchpad.net

Commit message

When loggerhead finished with a branch, have it clear its caches, rather than waiting for the GC to do so.

Description of the change

This is a small tweak for the Launchpad Loggerhead app that drive bazaar.launchpad.net.

Specifically, every request to loggerhead gets a new bzrlib.branch.Branch object created. Which then loads data for all the indexes, etc. A lot of this gets cached on the assumption that the object will get re-used. However, these objects are *not* shared between Loggerhead requests. It is a known issue that they also don't go away by simple ref-count (they require the garbage collector to run to remove circular references).

So this is just helping things along. Once we've finished an HTTP request, directly request that caches at least get cleared out.

In doing a test of just spidering of the launchpad codebase using bazaar.launchpad.dev on my local machine. This dropped the peak memory of 'start-loggerhead.py' down from 500+MB down to around 130-200MB.

A different option would be to look into changing how branches are opened, and possibly caching them. It would theoretically help performance a lot, we wouldn't be re-reading all the same content over and over. However at this point, I'd rather drop a cache than add a new one.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/launchpad_loggerhead/app.py'
2--- lib/launchpad_loggerhead/app.py 2012-06-29 08:40:05 +0000
3+++ lib/launchpad_loggerhead/app.py 2012-08-15 21:05:07 +0000
4@@ -286,6 +286,12 @@
5 served_url=None, private=private)
6 return view.app(environ, start_response)
7 finally:
8+ bzr_branch.repository.revisions.clear_cache()
9+ bzr_branch.repository.signatures.clear_cache()
10+ bzr_branch.repository.inventories.clear_cache()
11+ if bzr_branch.repository.chk_bytes is not None:
12+ bzr_branch.repository.chk_bytes.clear_cache()
13+ bzr_branch.repository.texts.clear_cache()
14 bzr_branch.unlock()
15 finally:
16 lp_server.stop_server()