You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Dan Villiom Podlaski Christiansen <da...@gmail.com> on 2010/06/03 14:11:47 UTC

File descriptor leak of rep-cache.db in 1.6.x

Hi,

I'm experiencing a file descriptor leak in the Subversion 1.6.x branch. I'm hit by it in the 1.6.1 build included with Mac OS X 10.6, a 1.6.11 build from MacPorts and a build of the 1.6.x branch. The bug is not present in 1.5.7, nor in trunk.

The bug is somewhat subtle, and the circumstances causing it are fairly complex. In the cause of running a test suite, we open repositories repeatedly using the ‘file’ protocol, log their history and fetch the contents of all revisions. This will fail after about a hundred tests, having exhausted file descriptors. Inspecting the output of ‘lsof’ on the process, there are 216 open references to ‘rep-cache.db’ files.

As mentioned, the circumstances causing the bug are fairly complex. I see this in hgsubversion,[1] a Mercurial plugin for Subversion interoperability. Both Mercurial and hgsubversion are written in Python, and historically, hgsubversion has used the SWIG bindings for Subversion. Unfortunately, we have found the SWIG bindings to leak like a sieve; it is not uncommon that converting large repositories uses several gigabytes of memory or even exhaust address space in a 32-bit environment. As an effort to fix this, I've been writing a Subvertpy backend for hgsubversion. Subvertpy[2] is a set of alternate Python bindings for Subversion, that expose a much less complicated API, and — most importantly — deals with memory allocation internally, rather than exposing it to the Python environment.

So far, the results are good; converting a test repository (cvs2svn) using the HTTP or svn protocols is slower, but with significantly lower memory use. (Some of that overhead just might be the cost of deallocating more; you never know…) The file protocol, however, appears to leak somewhat, using 27% less memory than when using the SWIG bindings, but use twice as much CPU time. (Please note that I haven't tested this with anything other than 1.6.) The file protocol is the main protocol used by the hgsubversion test suite. Whereas leaking one file descriptor per repository is insignificant during common use, our test suite opens hundreds of repositories in a single process.

Considering the many packages involved, it's not easy to determine which one might be buggy. A few observations:

* While hgsubversion leaks using the SWIG bindings, it doesn't leak file descriptors. This suggests that it isn't the cause of *this* leak.
* It is quite possible that the source of the leak is in Subvertpy. In order to get hgsubversion working using it, I had to add a few missing wrapper APIs. However…
* Neither hgsubversion nor Subvertpy contain any logic related to the various repository access methods. It seems likely that if either were the cause of the bug, it should affect all access methods and not just one.
* From a brief inspection of the Subversion source code, it appears that the ‘rep-cache.db’ is an implementation detail deep in Subversion. It's odd that this file remains open throughout the lifetime of the process. If the source of the leak were higher up in the chain, wouldn't other files in the repository remain open as well?
* Finally, there's the point that the leak isn't present when using Subversion 1.5.7 or 1.7.x. Subvertpy uses slightly different code paths for 1.5.7, but for 1.7.x, the code used is exactly the same. hgsubversion requires Subversion 1.5, and uses the same paths regardless of the underlying version of Subversion.

I haven't been able to reproduce this outside our test suite. Opening a repository directly doesn't cause ‘rep-cache.db’ to opened, nor does obtaining a log of all revisions. hgsubversion has two modes for fetching revisions; replay and diff-based. Hacking the tests to use one instead only affects how many repositories are processed before exhausting descriptors. For reference, I've attached the output of ‘lsof’ on a process running our test suite; both unfiltered and filtered for readability.

So, what to do now? I've discussed this with the Subvertpy author, Jelmer Vernooij, and he's at a loss as to what might cause this other than a bug in Subversion. I'd like to be able to diagnose this further, but so far, I haven't been able to get Subversion to open ‘rep-cache.db’ file. So I ask you guys: Do you think this is a bug in Subversion, or somewhere else? Do you have any hints on what I can do to diagnose this further? If it is a bug in Subversion, could it be fixed in the 1.6.x branch?

(I've Cc'ed this mail to Augie Fackler and Jelmer Vernooij, the maintainers of hgsubversion and Subvertpy, respectively.)

[1] http://code.google.com/p/hgsubversion/
[2] http://samba.org/~jelmer/subvertpy/

--

Dan Villiom Podlaski Christiansen
danchr@gmail.com


Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by Greg Stein <gs...@gmail.com>.
On my phone, so sorry for a short reply.

A few weeks ago, a change was made to an FS test to clear a pool, to close
file descriptors. I was suspicious that it only fixed a symptom rather than
a real bug, and that seems correct.

I'd start investigation there.

On Jun 3, 2010 10:12 AM, "Dan Villiom Podlaski Christiansen" <
danchr@gmail.com> wrote:

Hi,

I'm experiencing a file descriptor leak in the Subversion 1.6.x branch. I'm
hit by it in the 1.6.1 build included with Mac OS X 10.6, a 1.6.11 build
from MacPorts and a build of the 1.6.x branch. The bug is not present in
1.5.7, nor in trunk.

The bug is somewhat subtle, and the circumstances causing it are fairly
complex. In the cause of running a test suite, we open repositories
repeatedly using the ‘file’ protocol, log their history and fetch the
contents of all revisions. This will fail after about a hundred tests,
having exhausted file descriptors. Inspecting the output of ‘lsof’ on the
process, there are 216 open references to ‘rep-cache.db’ files.

As mentioned, the circumstances causing the bug are fairly complex. I see
this in hgsubversion,[1] a Mercurial plugin for Subversion interoperability.
Both Mercurial and hgsubversion are written in Python, and historically,
hgsubversion has used the SWIG bindings for Subversion. Unfortunately, we
have found the SWIG bindings to leak like a sieve; it is not uncommon that
converting large repositories uses several gigabytes of memory or even
exhaust address space in a 32-bit environment. As an effort to fix this,
I've been writing a Subvertpy backend for hgsubversion. Subvertpy[2] is a
set of alternate Python bindings for Subversion, that expose a much less
complicated API, and — most importantly — deals with memory allocation
internally, rather than exposing it to the Python environment.

So far, the results are good; converting a test repository (cvs2svn) using
the HTTP or svn protocols is slower, but with significantly lower memory
use. (Some of that overhead just might be the cost of deallocating more; you
never know…) The file protocol, however, appears to leak somewhat, using 27%
less memory than when using the SWIG bindings, but use twice as much CPU
time. (Please note that I haven't tested this with anything other than 1.6.)
The file protocol is the main protocol used by the hgsubversion test suite.
Whereas leaking one file descriptor per repository is insignificant during
common use, our test suite opens hundreds of repositories in a single
process.

Considering the many packages involved, it's not easy to determine which one
might be buggy. A few observations:

* While hgsubversion leaks using the SWIG bindings, it doesn't leak file
descriptors. This suggests that it isn't the cause of *this* leak.
* It is quite possible that the source of the leak is in Subvertpy. In order
to get hgsubversion working using it, I had to add a few missing wrapper
APIs. However…
* Neither hgsubversion nor Subvertpy contain any logic related to the
various repository access methods. It seems likely that if either were the
cause of the bug, it should affect all access methods and not just one.
* From a brief inspection of the Subversion source code, it appears that the
‘rep-cache.db’ is an implementation detail deep in Subversion. It's odd that
this file remains open throughout the lifetime of the process. If the source
of the leak were higher up in the chain, wouldn't other files in the
repository remain open as well?
* Finally, there's the point that the leak isn't present when using
Subversion 1.5.7 or 1.7.x. Subvertpy uses slightly different code paths for
1.5.7, but for 1.7.x, the code used is exactly the same. hgsubversion
requires Subversion 1.5, and uses the same paths regardless of the
underlying version of Subversion.

I haven't been able to reproduce this outside our test suite. Opening a
repository directly doesn't cause ‘rep-cache.db’ to opened, nor does
obtaining a log of all revisions. hgsubversion has two modes for fetching
revisions; replay and diff-based. Hacking the tests to use one instead only
affects how many repositories are processed before exhausting descriptors.
For reference, I've attached the output of ‘lsof’ on a process running our
test suite; both unfiltered and filtered for readability.

So, what to do now? I've discussed this with the Subvertpy author, Jelmer
Vernooij, and he's at a loss as to what might cause this other than a bug in
Subversion. I'd like to be able to diagnose this further, but so far, I
haven't been able to get Subversion to open ‘rep-cache.db’ file. So I ask
you guys: Do you think this is a bug in Subversion, or somewhere else? Do
you have any hints on what I can do to diagnose this further? If it is a bug
in Subversion, could it be fixed in the 1.6.x branch?

(I've Cc'ed this mail to Augie Fackler and Jelmer Vernooij, the maintainers
of hgsubversion and Subvertpy, respectively.)

[1] http://code.google.com/p/hgsubversion/
[2] http://samba.org/~jelmer/subvertpy/

--

Dan Villiom Podlaski Christiansen
danchr@gmail.com

Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by Dan Villiom Podlaski Christiansen <da...@gmail.com>.
On 3 Jun 2010, at 19:27, Dan Villiom Podlaski Christiansen wrote:

> Some statistics:

…which were wrong. Jelmer was a bit surprised that Subvertpy should be 2x slower than the SWIG bindings, and he was right: I had some debugging code left over which called ‘gc.collect()’ regularly.

BDB repository w. Subvertpy:
Virtual private memory: 46 MB
CPU time: 2m47s

FSFS repository w. Subvertpy:
Virtual private memory: 415 MB
CPU time: 2m48s

BDB repository w. SWIG:
Virtual private memory: 408 MB
CPU time: 3m10s

FSFS repository w. SWIG:
Virtual private memory: 410 MB
CPU time: 3m07s

> Based on this I would say that BDB repositories appear to not leak much when using Subvertpy. Everything else leaks quite a lot. Granted, there is a significant CPU overhead in Subvertpy, but I believe its much cleaner API and better memory handling compensate for that. Besides, many people using hgsubversion will have their conversions I/O bound rather CPU bound.

More accurately: There appear to be no downsides to using Subvertpy.

--

Dan Villiom Podlaski Christiansen
danchr@gmail.com


Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by Dan Villiom Podlaski Christiansen <da...@gmail.com>.
On 3 Jun 2010, at 18:39, Hyrum K. Wright wrote:

> On Thu, Jun 3, 2010 at 11:26 AM, Dan Villiom Podlaski Christiansen <da...@gmail.com> wrote:
> I just switched my checkout to that branch, compiled and ran the tests. And it worked! Great!
> 
> Is there any particular reason why it hasn't been merged into the 1.6.x branch yet?
> 
> It just needs one more vote, as per STATUS:
> http://svn.apache.org/repos/asf/subversion/branches/1.6.x/STATUS
> 
> Lobbying here or on IRC for that vote will improve it's chances of being cast.  (But I suspect that it will happen before we get to 1.6.12.)

Having this fix in 1.6.12 would be great. How far off is 1.6.12?

> > If converting a repository is a bit like "svnadmin dump" then it may
> > not be SWIG, you might be seeing issue 3593:
> >
> > http://subversion.tigris.org/issues/show_bug.cgi?id=3593
> 
> That's interesting. I'm currently doing a dump-and-load of the cvs2svn repository. (For some reason, this is obnoxiously slow…) I'll give it a try once it completes and report back.

FWIW this BDB slowness appeared exclusive to my Mac; the dump-and-load went much faster on my FreeBSD VPS.

> For what it's worth, we also get massive leaks with the SWIG bindings when cloning/converting over the network. I'm sure this isn't the only cause of those leaks :)
> 
> :(  For which flavor of the swig bindings are you seeing problems?

We're using the Python SWIG bindings. Some statistics:

BDB repository w. Subvertpy:
Memory: 37.7 MB virtual private
Running time: 6m38s CPU

FSFS repository w. Subvertpy:
Memory: 417.6 MB virtual private
Running time: 6m36s CPU

BDB repository w. SWIG:
Memory: 413.3 MB virtual private
Running time: 3m03s CPU

FSFS repository w. SWIG:
Memory: 408.9 MB virtual private
Running time: 3m04s CPU

Based on this I would say that BDB repositories appear to not leak much when using Subvertpy. Everything else leaks quite a lot. Granted, there is a significant CPU overhead in Subvertpy, but I believe its much cleaner API and better memory handling compensate for that. Besides, many people using hgsubversion will have their conversions I/O bound rather CPU bound.

--

Dan Villiom Podlaski Christiansen
danchr@gmail.com


Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by Dan Villiom Podlaski Christiansen <da...@gmail.com>.
On 3 Jun 2010, at 18:39, Hyrum K. Wright wrote:

> On Thu, Jun 3, 2010 at 11:26 AM, Dan Villiom Podlaski Christiansen <da...@gmail.com> wrote:
> I just switched my checkout to that branch, compiled and ran the tests. And it worked! Great!
> 
> Is there any particular reason why it hasn't been merged into the 1.6.x branch yet?
> 
> It just needs one more vote, as per STATUS:
> http://svn.apache.org/repos/asf/subversion/branches/1.6.x/STATUS
> 
> Lobbying here or on IRC for that vote will improve it's chances of being cast.  (But I suspect that it will happen before we get to 1.6.12.)

Having this fix in 1.6.12 would be great. How far off is 1.6.12?

> > If converting a repository is a bit like "svnadmin dump" then it may
> > not be SWIG, you might be seeing issue 3593:
> >
> > http://subversion.tigris.org/issues/show_bug.cgi?id=3593
> 
> That's interesting. I'm currently doing a dump-and-load of the cvs2svn repository. (For some reason, this is obnoxiously slow…) I'll give it a try once it completes and report back.

FWIW this BDB slowness appeared exclusive to my Mac; the dump-and-load went much faster on my FreeBSD VPS.

> For what it's worth, we also get massive leaks with the SWIG bindings when cloning/converting over the network. I'm sure this isn't the only cause of those leaks :)
> 
> :(  For which flavor of the swig bindings are you seeing problems?

We're using the Python SWIG bindings. Some statistics:

BDB repository w. Subvertpy:
Memory: 37.7 MB virtual private
Running time: 6m38s CPU

FSFS repository w. Subvertpy:
Memory: 417.6 MB virtual private
Running time: 6m36s CPU

BDB repository w. SWIG:
Memory: 413.3 MB virtual private
Running time: 3m03s CPU

FSFS repository w. SWIG:
Memory: 408.9 MB virtual private
Running time: 3m04s CPU

Based on this I would say that BDB repositories appear to not leak much when using Subvertpy. Everything else leaks quite a lot. Granted, there is a significant CPU overhead in Subvertpy, but I believe its much cleaner API and better memory handling compensate for that. Besides, many people using hgsubversion will have their conversions I/O bound rather CPU bound.

--

Dan Villiom Podlaski Christiansen
danchr@gmail.com


Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by "Hyrum K. Wright" <hy...@mail.utexas.edu>.
On Thu, Jun 3, 2010 at 11:26 AM, Dan Villiom Podlaski Christiansen <
danchr@gmail.com> wrote:

> On 3 Jun 2010, at 17:45, Philip Martin wrote:
>
> > Dan Villiom Podlaski Christiansen <da...@gmail.com> writes:
> >
> >> The bug is somewhat subtle, and the circumstances causing it are
> >> fairly complex. In the cause of running a test suite, we open
> >> repositories repeatedly using the ‘file’ protocol, log their history
> >> and fetch the contents of all revisions. This will fail after about
> >> a hundred tests, having exhausted file descriptors. Inspecting the
> >> output of ‘lsof’ on the process, there are 216 open references to
> >> ‘rep-cache.db’ files.
> >
> > Issue 3506 has changed the way the rep-cache is written:
> >
> > http://subversion.tigris.org/issues/show_bug.cgi?id=3506
> >
> > The changes are not in 1.6 yet:
> >
> > http://svn.apache.org/repos/asf/subversion/branches/1.6.x-issue3506/
>
> I just switched my checkout to that branch, compiled and ran the tests. And
> it worked! Great!
>
> Is there any particular reason why it hasn't been merged into the 1.6.x
> branch yet?
>

It just needs one more vote, as per STATUS:
http://svn.apache.org/repos/asf/subversion/branches/1.6.x/STATUS

Lobbying here or on IRC for that vote will improve it's chances of being
cast.  (But I suspect that it will happen before we get to 1.6.12.)


> > If converting a repository is a bit like "svnadmin dump" then it may
> > not be SWIG, you might be seeing issue 3593:
> >
> > http://subversion.tigris.org/issues/show_bug.cgi?id=3593
>
> That's interesting. I'm currently doing a dump-and-load of the cvs2svn
> repository. (For some reason, this is obnoxiously slow…) I'll give it a try
> once it completes and report back.
>
> For what it's worth, we also get massive leaks with the SWIG bindings when
> cloning/converting over the network. I'm sure this isn't the only cause of
> those leaks :)
>

:(  For which flavor of the swig bindings are you seeing problems?

-Hyrum

Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by Philip Martin <ph...@wandisco.com>.
Dan Villiom Podlaski Christiansen <da...@gmail.com> writes:

>> http://svn.apache.org/repos/asf/subversion/branches/1.6.x-issue3506/
>
> I just switched my checkout to that branch, compiled and ran the
> tests. And it worked! Great!
>
> Is there any particular reason why it hasn't been merged into the
> 1.6.x branch yet?

It's waiting for review, see

http://svn.apache.org/repos/asf/subversion/branches/1.6.x/STATUS

-- 
Philip

Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by Dan Villiom Podlaski Christiansen <da...@gmail.com>.
On 3 Jun 2010, at 17:45, Philip Martin wrote:

> Dan Villiom Podlaski Christiansen <da...@gmail.com> writes:
> 
>> The bug is somewhat subtle, and the circumstances causing it are
>> fairly complex. In the cause of running a test suite, we open
>> repositories repeatedly using the ‘file’ protocol, log their history
>> and fetch the contents of all revisions. This will fail after about
>> a hundred tests, having exhausted file descriptors. Inspecting the
>> output of ‘lsof’ on the process, there are 216 open references to
>> ‘rep-cache.db’ files.
> 
> Issue 3506 has changed the way the rep-cache is written:
> 
> http://subversion.tigris.org/issues/show_bug.cgi?id=3506
> 
> The changes are not in 1.6 yet:
> 
> http://svn.apache.org/repos/asf/subversion/branches/1.6.x-issue3506/

I just switched my checkout to that branch, compiled and ran the tests. And it worked! Great!

Is there any particular reason why it hasn't been merged into the 1.6.x branch yet?

> If converting a repository is a bit like "svnadmin dump" then it may
> not be SWIG, you might be seeing issue 3593:
> 
> http://subversion.tigris.org/issues/show_bug.cgi?id=3593

That's interesting. I'm currently doing a dump-and-load of the cvs2svn repository. (For some reason, this is obnoxiously slow…) I'll give it a try once it completes and report back.

For what it's worth, we also get massive leaks with the SWIG bindings when cloning/converting over the network. I'm sure this isn't the only cause of those leaks :)

--

Dan Villiom Podlaski Christiansen
danchr@gmail.com


Re: File descriptor leak of rep-cache.db in 1.6.x

Posted by Philip Martin <ph...@wandisco.com>.
Dan Villiom Podlaski Christiansen <da...@gmail.com> writes:

> The bug is somewhat subtle, and the circumstances causing it are
> fairly complex. In the cause of running a test suite, we open
> repositories repeatedly using the ‘file’ protocol, log their history
> and fetch the contents of all revisions. This will fail after about
> a hundred tests, having exhausted file descriptors. Inspecting the
> output of ‘lsof’ on the process, there are 216 open references to
> ‘rep-cache.db’ files.

Issue 3506 has changed the way the rep-cache is written:

http://subversion.tigris.org/issues/show_bug.cgi?id=3506

The changes are not in 1.6 yet:

http://svn.apache.org/repos/asf/subversion/branches/1.6.x-issue3506/

> As mentioned, the circumstances causing the bug are fairly
> complex. I see this in hgsubversion,[1] a Mercurial plugin for
> Subversion interoperability. Both Mercurial and hgsubversion are
> written in Python, and historically, hgsubversion has used the SWIG
> bindings for Subversion. Unfortunately, we have found the SWIG
> bindings to leak like a sieve; it is not uncommon that converting
> large repositories uses several gigabytes of memory or even exhaust
> address space in a 32-bit environment.

If converting a repository is a bit like "svnadmin dump" then it may
not be SWIG, you might be seeing issue 3593:

http://subversion.tigris.org/issues/show_bug.cgi?id=3593

-- 
Philip