You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm pretty sure sim_mutations is accumulating some garbage same as pyslim (see #pyslim211). Note how sim_mutations also calls ts.tables.
I don't have the bandwidth right now to make a proper test... But it seems this won't matter after the changes to tskit's memory usage goes in, right @benjeffery?
There shouldn't be any interaction between ts.tables and garbage collection @mufernando --- it's just making a copy now where we want it to return a view.
I ran the same example (with a msprime tree sequence) and didn't run into issues.
Then I ran a minimal example with three sim_mutation calls to one of my tree sequences (from SLiM, so with a ton of metadata everywhere). You can see the memory usage only grows over time.
Lastly, I added some manual garbage collection in between sim_mutation calls and that seems to help quite a bit.
With some number of objects being accumulated in between calls:
Before: collected 0 objects.
After first call: collected 84 objects.
After second call: collected 84 objects.
After third call: collected 84 objects.
After changing my script to what is shown below, I got an absolutely massive log of stuff. The log is also large if I skip the mutation step. However, the difference between the 2 is lots of variables called ll_table, many copies of various mutation, individual, etc., tables. When I modified the script to gc.collect() right after load and then run:
mprof run mutatification.py |grep -c MutationTable
Thanks, this is very helpful. I'll dig in when I get a chance. Identifying if we have a refcount cycle will be very helpful and motivating in the read-only tables work: tskit-dev/tskit#2057
Activity
jeromekelleher commentedon Dec 10, 2021
There shouldn't be any interaction between
ts.tablesand garbage collection @mufernando --- it's just making a copy now where we want it to return a view.jeromekelleher commentedon Dec 10, 2021
Here's an example:
Then,
gives
Looks pretty solid to me?
benjeffery commentedon Dec 10, 2021
Are you getting the same result @mufernando? Would be interesting of your system is accumulating for this example.
mufernando commentedon Dec 10, 2021
I ran the same example (with a msprime tree sequence) and didn't run into issues.
Then I ran a minimal example with three
sim_mutationcalls to one of my tree sequences (from SLiM, so with a ton of metadata everywhere). You can see the memory usage only grows over time.Lastly, I added some manual garbage collection in between
sim_mutationcalls and that seems to help quite a bit.With some number of objects being accumulated in between calls:
This was my script:
and I can share the tree sequence, but it's 250M.
petrelharp commentedon Dec 10, 2021
ping @molpopgen?
molpopgen commentedon Dec 10, 2021
Well, let me try to break a tie and see if I make a plot that looks more like @jeromekelleher or more like @mufernando.
jeromekelleher commentedon Dec 10, 2021
Very nice, thanks @mufernando
molpopgen commentedon Dec 10, 2021
Tie goes to @mufernando, I think? Did this with a file I'm working with at the moment.
molpopgen commentedon Dec 10, 2021
For completeness, I repeated my example w/
gc.collect()after each bout of mutating.andrewkern commentedon Dec 10, 2021
is this call in
sim_mutationsthe issue?msprime/msprime/mutations.py
Line 1369 in c034a5d
molpopgen commentedon Dec 11, 2021
The main difference between @jeromekelleher's example and the others seems to be the presence of metadata in the latter, which must be a clue?
jeromekelleher commentedon Dec 11, 2021
Just looking at your plot again @mufernando - is that really 20s to load a 250mb file? Damn that's slow!
jeromekelleher commentedon Dec 11, 2021
I agree with Kevin, it's certainly pointing towards the presence of metadata. I guess making a smaller reproducible example is the next step.
molpopgen commentedon Dec 11, 2021
Hmm. Yeah. In mine, it is 14 sec for 1.5 gigs.
jeromekelleher commentedon Dec 11, 2021
Well, adding some top-level metadata doesn't do anything. This example has a flat memory profile:
molpopgen commentedon Dec 11, 2021
These experiments also gave a flat profile:
molpopgen commentedon Dec 11, 2021
Note to self to try and use the methods outlined here to try to find reference cycles in the examples leading to growing memory use.
molpopgen commentedon Dec 13, 2021
After changing my script to what is shown below, I got an absolutely massive log of stuff. The log is also large if I skip the mutation step. However, the difference between the 2 is lots of variables called
ll_table, many copies of various mutation, individual, etc., tables. When I modified the script togc.collect()right after load and then run:mprof run mutatification.py |grep -c MutationTableI got a count of 30. That seems way too many?
The script:
molpopgen commentedon Dec 13, 2021
This version gives a count of 6 mutation tables:
jeromekelleher commentedon Dec 14, 2021
Hmmmmm....
molpopgen commentedon Dec 14, 2021
Yeah, my intuition is no good on this. I think this is with tskit 0.3.7 installed, FWIW.
jeromekelleher commentedon Dec 14, 2021
Thanks, this is very helpful. I'll dig in when I get a chance. Identifying if we have a refcount cycle will be very helpful and motivating in the read-only tables work: tskit-dev/tskit#2057
molpopgen commentedon Dec 14, 2021
I haven't had luck finding a runtime analysis tool that'll print out reference cycles. Do you know of one?
jeromekelleher commentedon Dec 14, 2021
No but I figure if gc finds things in simple cases like this that's evidence they exist?
molpopgen commentedon Dec 14, 2021
I believe that's correct. But I want a back trace analog here. I want to see where they're coming from. But I'd also like a unicorn I guess.
jeromekelleher commentedon Jul 17, 2024
I think this was resolved upstream in tskit