Skip to content

memory ram usage in ts.samples() #1916

Closed

Description

@mufernando

ts.samples() is using too much ram when the keyword arguments are specified.

The subsetting by population or time is done on the Python side and it involves copying the tables (twice if pop and time are specified!). See the code here.

For a 3Gb tree sequence this is the ram usage I was getting:

image

** updated the figure

Activity

  1. jeromekelleher commented on Nov 16, 2021

    @jeromekelleher
    Member

    Thanks @mufernando this is very useful. Can you do this again with just a single population please (as in, don't call it in a loop, just call .samples() once each time)? It's not clear how many populations there are, and therefore what size the sample_sets dictionary is (and how big a multiplier this will be).

    The operation recap_tsu.samples() should take roughly 4 bytes * num_samples - if not, we have a leak.

  2. mufernando commented on Nov 16, 2021

    @mufernando
    MemberAuthor

    I updated the figure!

  3. added
    Performance
    Python API
    bug
    on Nov 16, 2021
  4. added this to the Python 0.4.0 milestone on Nov 16, 2021
  5. removed
    bug
    on Nov 17, 2021
  6. removed this from the Python 0.4.0 milestone on Nov 17, 2021
  7. jeromekelleher commented on Nov 17, 2021

    @jeromekelleher
    Member

    I've done some profiling here @mufernando and I don't think we're leaking memory in any major way, so I've removed the "bug" label. The main no parameters code path is definitely returning the right thing, and has the right size and the array.nbytes is the correct value. We can definitely streamline the other code paths, but there's nothing immediate we can do about them (but I've opened #1917 to give a way we can make them a lot better).

    I think the "memit" (and memoryprofile stats in general) need to be taken with a pinch of salt. When you see the first example, it looks like calling .samples uses 17MiB which sounds like too much (we have 3.6M samples, so the samples array should use 13.7 MiB). But, this isn't measuring the size of the things in the cell directly, it's measuring the difference in the size of the process overall from the OS's perspective. Numpy asked to malloc 13 MiB, and the OS decided to increase the size of the processes memory space by 17 MiB instead - this is totally normal and exactly what you'd expect.

  8. mufernando commented on Nov 17, 2021

    @mufernando
    MemberAuthor

    ah, great, thanks @jeromekelleher! also, I'm not sure if this is a Jupyter thing or not, but if you see the image I had before I edited (with for loops), %%memit said the peak was proportional to the number of loops. Do you think this could indicate Python's garbage collection is screwing us over or is this just a bug of memit? I know something similar was happening when I ran my Python script because of the amount of ram overall it needed to run in our cluster.

  9. jeromekelleher commented on Nov 17, 2021

    @jeromekelleher
    Member

    No sure @mufernando, I don't remember the details. I'd like to sort out #1917 and then run your benchark again ideally.

  10. added 4 commits that reference this issue on Jul 21, 2022
    c106abe
    d655c44
    4e863d8
    01ef912
  11. added a commit that references this issue on Mar 22, 2024
    ada9596
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerformancePython API

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions