-
Notifications
You must be signed in to change notification settings - Fork 191
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
memory leaks: don't pass process stack via context #4699
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a216b19
memory leaks: don't pass process stack via context
ltalirz a27aa94
add test against memory leaks in engine.run
ltalirz 69aa6b9
add pympler dependency also on CI
ltalirz 20d43c9
refactor test to get rid of local variables
ltalirz cda8e5c
try freeing results dict
ltalirz 99bb97c
try adding more empty contexts...
ltalirz 9842fc5
add memory leak test in test suite
ltalirz e27e802
Merge branch 'develop' into issue_4698_context_var
ltalirz df7af0f
fix memory leak in test suite
ltalirz b9ce496
try fixing daemon tests
ltalirz 05750be
move test to .ci
ltalirz fdd6b24
Merge branch 'develop' into issue_4698_context_var
ltalirz a1cf65e
fix mypy
ltalirz 4d90829
Merge branch 'develop' into issue_4698_context_var
ltalirz 3e51b56
Merge branch 'develop' into issue_4698_context_var
ltalirz 04d19d2
Merge branch 'develop' into issue_4698_context_var
chrisjsewell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Utilities for testing memory leakage.""" | ||
from tests.utils import processes as test_processes # pylint: disable=no-name-in-module,import-error | ||
from tests.utils.memory import get_instances # pylint: disable=no-name-in-module,import-error | ||
from aiida.engine import processes, run | ||
from aiida.plugins import CalculationFactory | ||
from aiida import orm | ||
|
||
ArithmeticAddCalculation = CalculationFactory('arithmetic.add') | ||
|
||
|
||
def test_leak_run_process(): | ||
"""Test whether running a dummy process leaks memory.""" | ||
inputs = {'a': orm.Int(2), 'b': orm.Str('test')} | ||
run(test_processes.DummyProcess, **inputs) | ||
|
||
# check that no reference to the process is left in memory | ||
# some delay is necessary in order to allow for all callbacks to finish | ||
process_instances = get_instances(processes.Process, delay=0.2) | ||
assert not process_instances, f'Memory leak: process instances remain in memory: {process_instances}' | ||
|
||
|
||
def test_leak_local_calcjob(aiida_local_code_factory): | ||
"""Test whether running a local CalcJob leaks memory.""" | ||
inputs = {'x': orm.Int(1), 'y': orm.Int(2), 'code': aiida_local_code_factory('arithmetic.add', '/usr/bin/diff')} | ||
run(ArithmeticAddCalculation, **inputs) | ||
|
||
# check that no reference to the process is left in memory | ||
# some delay is necessary in order to allow for all callbacks to finish | ||
process_instances = get_instances(processes.Process, delay=0.2) | ||
assert not process_instances, f'Memory leak: process instances remain in memory: {process_instances}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Utilities for testing memory leakage.""" | ||
import asyncio | ||
from pympler import muppy | ||
|
||
|
||
def get_instances(classes, delay=0.0): | ||
"""Return all instances of provided classes that are in memory. | ||
|
||
Useful for investigating memory leaks. | ||
|
||
:param classes: A class or tuple of classes to check (passed to `isinstance`). | ||
:param delay: How long to sleep (seconds) before collecting the memory dump. | ||
This is a convenience function for tests involving Processes. For example, :py:func:`~aiida.engine.run` returns | ||
before all futures are resolved/cleaned up. Dumping memory too early would catch those and the references they | ||
carry, although they may not actually be leaking memory. | ||
""" | ||
if delay > 0: | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(asyncio.sleep(delay)) | ||
|
||
all_objects = muppy.get_objects() # this also calls gc.collect() | ||
return [o for o in all_objects if hasattr(o, '__class__') and isinstance(o, classes)] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.