xsawyerx / xs-fun

XS is fun: a simple and easy tutorial on writing Perl XS
144 stars 35 forks source link

chapter_08 #23

Open augensalat opened 9 years ago

augensalat commented 9 years ago

First of all: Many thanks for this great tutorial.

Unfortunately the last chapter is not complete. Moreover the example code is broken.

t/leak-pointer.t .. 
1..2
ok 1 - use Audio::Chromaprint;
not ok 2 - Does not grow in memory

#   Failed test 'Does not grow in memory'
#   at t/leak-pointer.t line 11.
# Lost 344064 bytes of memory over 10000 calls, average of 34.41 per call
# Looks like you failed 1 test of 2.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests 
paultcochrane commented 9 years ago

Thanks for the bug report. Unfortunately, I can't reproduce the problem. What platform are you on? If you're on Linux, which distribution (and version thereof) are you using? Which version of perl are you using (the output of perl --version should be sufficient)? Is it a perlbrewed Perl version or the system perl? Sorry for the many questions! Nevertheless, I'd like to get to the bottom of this issue.

As far as the chapter text is concerned, if I recall correctly, @xsawyerx made the comment at a conference recently that he's thinking of reworking this chapter, and I have a feeling that it's a known issue that the chapter isn't yet complete.

augensalat commented 9 years ago

Hi Paul,

it is Linux 64bit and perlbrew and it fails on each Perl dist (each 64bit) so far, which was 5.14.0 w/ threads, 5.14.1 w/o threads, 5.16.2 w/o threads and 5.22.0 w/o threads.

I found the setting 100/100 for Test::MemoryGrowth suspicious, and indeed it worked for that number, but not when I run with a more reasonable setting like the default 10/10000.

Did you also run you test with Test::MemoryGrowth default?

paultcochrane commented 9 years ago

No, I simply ran the test suite. However, after I changed the number of calls to 10000 and the burn in setting to 10 (or even 100), I'm able to reproduce your results. Thanks for pointing out this issue we'll need to look into it a bit more.

@xsawyerx: was there a reason you chose calls => 100, burn_in => 100 for the leak-pointer test?

augensalat commented 9 years ago

Afaik Perl reserves system memory in bigger chunks. With just 100 calls the leaked memory seems to stay below the threshold before Perl must reserve the next chunk.

xsawyerx commented 8 years ago

No reason it was exactly 100. I just wanted something that didn't take very long. Let's raise and try to fix any problem we see.

xsawyerx commented 5 years ago

I tested with 1,000 for both burn_in and calls and then I can reproduce the failure:

$ perl -Mblib -Ilib t/leak-pointer.t
1..2
ok 1 - use Audio::Chromaprint;
not ok 2 - Does not grow in memory
#   Failed test 'Does not grow in memory'
#   at t/leak-pointer.t line 11.
# Lost 118784 bytes of memory over 1000 calls, average of 118.78 per call
# Looks like you failed 1 test of 2.

I'm going to review the chapter now and clean up the code first. Then we'll see if the code still leaks and try to address that.

Thanks again for opening the ticket. :)

xsawyerx commented 5 years ago

This doesn't seem to happen every time I run the test. I'm not sure why it's sporadic.