-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle SIGQUIT on out of memory from NumPy better (#48)
* Add memory test script Make rbg more robust... output whatever info has been collected * Set limit in rbg of 35000 vertices. This is arbitrary, but allows reasonable execution time without using too much virtual memory in my configuration Update bibliography references (not tied to this branch...)
- Loading branch information
Showing
3 changed files
with
120 additions
and
20 deletions.
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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
| Date encountered | Author | Title | | ||
|------------------|--------|-------| | ||
| 4/6/2020 | Stephan Dolan | Fun with Semirings | | ||
| 4/2/2020 | Stéfan van der Walt, Gael Varoquaux | The NumPy Array: A Structure for Efficient Numerical Computation | | ||
| 4/2/2020 | Travis Oliphant | [Guide to NumPy](https://web.mit.edu/dvp/Public/numpybook.pdf) | | ||
| 4/2/2020 | Stéfan van der Walt, Gael Varoquaux | [The NumPy Array: A Structure for Efficient Numerical Computation](https://arxiv.org/abs/1102.1523) | | ||
| 4/6/2020 | Stephan Dolan | [Fun with Semirings](http://stedolan.net/research/semirings.pdf) | | ||
| 4/12/2020 | Alan Cannaday | [Solving Cycling Pedigress or "Loops" by Analyzing Birth Ranges and Parent-Child Relationships](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.368.9730&rep=rep1&type=pdf) | ||
| 4/14/2020 | Leskovec, Rajaraman, Ullman | [Mining of Massive Datasets](http://infolab.stanford.edu/~ullman/mmds/book0n.pdf) | | ||
| 4/14/2020 | Balabit | [Scalable SParse Matrix Multiplication in Apache Spark](https://medium.com/balabit-unsupervised/scalable-sparse-matrix-multiplication-in-apache-spark-c79e9ffc0703) | | ||
|
||
|
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,78 @@ | ||
import numpy as np | ||
import os | ||
import psutil | ||
import sys | ||
import traceback | ||
|
||
PROCESS = psutil.Process(os.getpid()) | ||
MEGA = 1024 * 1024 | ||
|
||
|
||
def main(): | ||
try: | ||
print_memory_usage() | ||
# alloc_max_str() | ||
alloc_max_array() | ||
except MemoryError as error: | ||
# Output expected MemoryErrors. | ||
log_exception(error) | ||
except Exception as exception: | ||
# Output unexpected Exceptions. | ||
log_exception(exception, False) | ||
|
||
|
||
def alloc_max_array(): | ||
"""Allocates memory for maximum array. | ||
See: https://stackoverflow.com/a/15495136 | ||
:return: None | ||
""" | ||
base = 13 * 10000 | ||
i = 0 | ||
nbytes = 0 | ||
while True: | ||
try: | ||
size = base + i * 1000 | ||
collection = np.ones((size,size), dtype=np.int32) | ||
nbytes = collection.nbytes | ||
i += 1 | ||
if i % 1 == 0: | ||
print(f"loop: {i}; size: {size:,}; allocated: {nbytes/(1024*1024*1024):,.2f} GB") | ||
except MemoryError as error: | ||
# Output expected MemoryErrors. | ||
log_exception(error) | ||
break | ||
except Exception as exception: | ||
# Output unexpected Exceptions. | ||
log_exception(exception, False) | ||
break | ||
print(f'Maximum array size: {nbytes:,}') | ||
print_memory_usage() | ||
|
||
|
||
def log_exception(exception: BaseException, expected: bool = True): | ||
"""Prints the passed BaseException to the console, including traceback. | ||
:param exception: The BaseException to output. | ||
:param expected: Determines if BaseException was expected. | ||
""" | ||
output = "[{}] {}: {}".format('EXPECTED' if expected else 'UNEXPECTED', type(exception).__name__, exception) | ||
print(output) | ||
exc_type, exc_value, exc_traceback = sys.exc_info() | ||
traceback.print_tb(exc_traceback) | ||
|
||
|
||
def print_memory_usage(): | ||
"""Prints current memory usage stats. | ||
See: https://stackoverflow.com/a/15495136 | ||
:return: None | ||
""" | ||
total, available, percent, used, free, active, inactive, wired = psutil.virtual_memory() | ||
total, available, used, free = total / MEGA, available / MEGA, used / MEGA, free / MEGA | ||
proc = PROCESS.memory_info()[1] / MEGA | ||
print(f'process = {proc:,.2f} total = {total:,.2f} available = {available:,.2f} used = {used:,.2f} free = {free:,.2f} percent = {percent}') | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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