Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_bigmem.test_from_2G_generator uses more memory than expected #49688

Closed
pitrou opened this issue Mar 8, 2009 · 22 comments
Closed

test_bigmem.test_from_2G_generator uses more memory than expected #49688

pitrou opened this issue Mar 8, 2009 · 22 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes performance Performance or resource usage tests Tests in the Lib/test dir

Comments

@pitrou
Copy link
Member

pitrou commented Mar 8, 2009

BPO 5438
Nosy @Yhg1s, @pitrou, @serhiy-storchaka, @zooba, @llllllllll, @miss-islington
PRs
  • bpo-5438: Update memory requirements and optimize test_bigmem.py. #11123
  • [3.7] bpo-5438: Update memory requirements and optimize test_bigmem.py. (GH-11123) #11259
  • Files
  • bigmem.patch
  • bigmem-update.patch
  • bigmem_usage_440G.png
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/Yhg1s'
    closed_at = <Date 2019-08-02.22:25:50.886>
    created_at = <Date 2009-03-08.01:25:13.696>
    labels = ['3.8', '3.7', 'tests', 'performance']
    title = 'test_bigmem.test_from_2G_generator uses more memory than expected'
    updated_at = <Date 2019-08-02.22:25:50.880>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2019-08-02.22:25:50.880>
    actor = 'steve.dower'
    assignee = 'twouters'
    closed = True
    closed_date = <Date 2019-08-02.22:25:50.886>
    closer = 'steve.dower'
    components = ['Tests']
    creation = <Date 2009-03-08.01:25:13.696>
    creator = 'pitrou'
    dependencies = []
    files = ['38945', '38952', '38996']
    hgrepos = []
    issue_num = 5438
    keywords = ['patch']
    message_count = 22.0
    messages = ['83295', '109768', '132074', '240713', '240728', '240842', '240848', '240870', '240884', '240887', '240913', '240922', '240936', '240944', '240953', '240960', '240968', '241147', '241939', '331660', '332191', '332194']
    nosy_count = 7.0
    nosy_names = ['twouters', 'pitrou', 'nadeem.vawda', 'serhiy.storchaka', 'steve.dower', 'llllllllll', 'miss-islington']
    pr_nums = ['11123', '11259']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue5438'
    versions = ['Python 3.7', 'Python 3.8']

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 8, 2009

    It seems test_from_2G_generator doesn't respect its announced memory
    consumption. I launched test_bigmem with "-M 12G" on a 16GB machine, and
    the interpreter process got killed by the OOM killer (Out Of Memory)
    while running this test case.

    @pitrou pitrou added tests Tests in the Lib/test dir performance Performance or resource usage labels Mar 8, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 9, 2010

    Is this problem repeatable? I haven't got a big enough box on which to try this out.

    @Yhg1s
    Copy link
    Member

    Yhg1s commented Mar 25, 2011

    I'm not surprised this test takes up more memory... It claims to take up 9 times the test size in memory, with a minimum useful test size of 1G. With a limit of 12G that would make the test size about 1.33G. However, it then proceeds to build a tuple of 159 million distinct integers and stuffs them into a tuple. Each integer is at least 24 bytes long, plus the 8 of the pointer in the tuple, making the total memory use over 32 times the test size. I'll fix the test.

    @Yhg1s Yhg1s self-assigned this Mar 25, 2011
    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 13, 2015

    I am now computing the size based on the system's int and pointer size.

    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 13, 2015

    I have updated the test to make another test that does not have a __len__.

    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 14, 2015

    Steve, we talked about the possibility of having you run some of these tests on a machine with a large amount of ram; I am adding you to the nosy list.

    @serhiy-storchaka
    Copy link
    Member

    How long time the test run (if there is enough memory)? May be we should decrease memory requirements by using shared values?

    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 14, 2015

    I am not sure yet; I don't have access to a machine that can run the test.

    @zooba
    Copy link
    Member

    zooba commented Apr 14, 2015

    I'll soon have Windows and Ubuntu machines with 448GB RAM each - anything special I should test here?

    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 14, 2015

    The tests need to be run with higher memory caps, this can be set with the -M flag, like "python -m test -M 64G test_bigmem". I am under the impression that these tests don't get run all the time so we might want to run that suite.

    @zooba
    Copy link
    Member

    zooba commented Apr 14, 2015

    It's running fine, but not really exercising the limit. I ran with -M 440G and we haven't gone past 38GB usage yet. I'll post a timeline plot when it finishes (on Windows - not sure how to collect the data but I'm also running on Ubuntu), but it looks like we may need to tweak the tests to go closer to the limit.

    @zooba
    Copy link
    Member

    zooba commented Apr 14, 2015

    I'm up to test_from_2G_generator. It says the peak will be 36GB. Memory grew in chunks up to about 40GB and has been stuck there for 10 minutes.

    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 14, 2015

    Has the test passed or is it still hung? Also, I guess this means that the tuple is over-allocating, maybe I need to revise the memory assumptions to account for the growth algorithm.

    @zooba
    Copy link
    Member

    zooba commented Apr 14, 2015

    It's passed. There was no memory usage increase from that point, but after about 20 minutes it completed successfully.

    All the tests passed on Ubuntu, but again, they didn't really fill up RAM - 50GB looks like the high point.

    @zooba
    Copy link
    Member

    zooba commented Apr 14, 2015

    Just for fun, I attached the memory usage graph from the Windows run. You can see the long pauses in the middle for the two changed tests, and the graph only goes up to 57GB despite the limit being set at 440GB.

    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 14, 2015

    I think that the idea is not to get as close to the limit as possible but just to hard cap the memory usage of the test suite so that it doesn't get oom-killed. twouters, does this sound correct? Also, I think that this means that the new decorator is reporting a proper size hint.

    @Yhg1s
    Copy link
    Member

    Yhg1s commented Apr 14, 2015

    Yes. The test doesn't run with more than the requested "units", but if you
    run it without -M it does run with a very small number, in order to make
    sure the tests don't bitrot.

    The mechanism could do with an overhaul though; I wrote it in 2006 or so,
    before we had test skipping and when memory limits were a lot lower (and we
    had fewer, less powerful friends :) I also wonder if we should change it to
    run each test in a separate process so we can more easily check the actual
    memory usage.
    On Apr 14, 2015 1:16 PM, "Joe Jevnik" <report@bugs.python.org> wrote:

    Joe Jevnik added the comment:

    I think that the idea is not to get as close to the limit as possible but
    just to hard cap the memory usage of the test suite so that it doesn't get
    oom-killed. twouters, does this sound correct? Also, I think that this
    means that the new decorator is reporting a proper size hint.

    ----------


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue5438\>


    @llllllllll
    Copy link
    Mannequin

    llllllllll mannequin commented Apr 15, 2015

    I can look into rewriting the framework to use multiprocessing; however, should we split this into a separate issue or block this one until that work is done.

    @Yhg1s
    Copy link
    Member

    Yhg1s commented Apr 24, 2015

    Rewriting the tests shouldn't block this specific issue, no. Also, don't use multiprocessing for it. I would just use subprocess to start a separate process (which might after all be OOM-killed,) check the exitcode, and record its stderr in case of failure. Given that Steve ran the bigmem tests with a high limit and they all passed means that it's not pressing, though -- while it would be *good* to make these tests easier, and the skips more obvious, it's a good sign that nothing broke :)

    @serhiy-storchaka
    Copy link
    Member

    tuple(range(size)) should consume approximately 90 GiB of memory and run for hours. I think this happens because it creates enormous number of integer objects, and this can lead to requesting additional memory for memory pools.

    If details of memory management for small objects is not the purpose of this test, I think we can replace it with tuple(iter([42]*size)). It executes the same code in tuple creation: allocates a tuple of known size (both range and list iterators have __length_hint__) and fills it with values produced by the iterator. This allows significantly reduce memory requirements (to 16 GiB) and execution time (to 20 seconds on my computer).

    The proposed PR implements this rewriting. It also fixes memory requirements for other tests, optimizes repr tests for tuples and lists (repr(False) is faster and longer than repr(0)), and expresses memory requirements in terms of character and pointer sizes.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life 3.8 only security fixes labels Dec 11, 2018
    @serhiy-storchaka
    Copy link
    Member

    New changeset b13a20f by Serhiy Storchaka in branch 'master':
    bpo-5438: Update memory requirements and optimize test_bigmem.py. (GH-11123)
    b13a20f

    @miss-islington
    Copy link
    Contributor

    New changeset a26201c by Miss Islington (bot) in branch '3.7':
    bpo-5438: Update memory requirements and optimize test_bigmem.py. (GH-11123)
    a26201c

    @zooba zooba closed this as completed Aug 2, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes performance Performance or resource usage tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants