Cap the number of open files in the WindowCache
commit5116478788608eceaba668eb57b5bf2e7e61651f
authorShawn O. Pearce <spearce@spearce.org>
Wed, 18 Mar 2009 01:36:16 +0000 (17 18:36 -0700)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 19 Mar 2009 20:05:11 +0000 (19 21:05 +0100)
tree0b263ec026afe33edbda74b1c9541df5626a5feb
parentc5a2b6352405cfdc3fcf8e46817b4f771ac0579b
Cap the number of open files in the WindowCache

The default WindowCache configuration is:

  packedGitLimit:      10 MB
  packedGitWindowSize:  8 KB

10 MB / 8 KB allows up to 1280 windows permitted in the WindowCache
at any given time.  If every window came from a unique pack file, we
need 1280 file descriptors just for the resources in the WindowCache.
For most applications this is way beyond the hard limit configured
for the host JVM, causing java.io.IOException("Too many open files")
from possibly any part of JGit or the host application.

Specifically, I ran into this problem in Gerrit Code Review, where we
commonly see hundreds of very small pack files spread over hundreds
of Git repositories, all accessed from a persistent JVM that is also
hosting an SSH daemon and a web server.  The aggressive caching of
windows in the WindowCache and of Repository objects in Gerrit's
own RepositoryCache caused us to retain far too many tiny pack files.

We now set the limit at 128 open files, assuming this is a reasonable
limit for most applications using the library.  Git repositories tend
to be in the handful of packs/repository (e.g. <10 packs/repository)
and applications using JGit tend to access only a handful of Git
repositories at a time (e.g. <10 repositories/JVM).

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java
org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java