A memory profiler for data batch processing applications.
The Fil memory profiler for Python
Your code reads some data, processes it, and uses too much memory. In order to reduce memory usage, you need to learn what code is responsible, and specifically what code is responsible for peak memory usage.
And that's exactly what Fil will help you find. Fil an open source memory profiler designed for data processing applications written in Python, and includes native support for Jupyter.
At the moment it only runs on Linux and macOS.
For more information, including an example of the output, see https://pythonspeed.com/products/filmemoryprofiler/
- Using Fil
- Reducing memory usage in your code
- What Fil tracks
Assuming you're on macOS or Linux, and are using Python 3.6 or later, you can use either Conda or pip (or any tool that is pip-compatible and can install
To install on Conda:
$ conda install -c conda-forge filprofiler
To install the latest version of Fil you'll need Pip 19 or newer. You can check like this:
$ pip --version pip 19.3.0
If you're using something older than v19, you can upgrade by doing:
$ pip install --upgrade pip
If that doesn't work, try running that in a virtualenv.
Assuming you have a new enough version of pip:
$ pip install filprofiler
To measure memory usage of some code in Jupyter you need to do three things:
- Use an alternative kernel, "Python 3 with Fil". You can choose this kernel when you create a new notebook, or you can switch an existing notebook in the Kernel menu; there should be a "Change Kernel" option in there in both Jupyter Notebook and JupyterLab.
- Load the extension by doing
- Add the
%%filprofilemagic to the top of the cell with the code you wish to profile.
Instead of doing:
$ python yourscript.py --input-file=yourfile
$ fil-profile run yourscript.py --input-file=yourfile
And it will generate a report.
free to figure out how much memory is available—in this case about 6.3GB—and then set a corresponding limit on virtual memory with
$ free -h total used free shared buff/cache available Mem: 7.7Gi 1.1Gi 6.3Gi 50Mi 334Mi 6.3Gi Swap: 3.9Gi 3.0Gi 871Mi $ ulimit -Sv 6300000
Then, run your program under Fil, and it will generate a SVG at the point in time when memory runs out:
$ fil-profile run oom.py ... =fil-profile= Wrote memory usage flamegraph to fil-result/2020-06-15T12:37:13.033/out-of-memory.svg
You've found where memory usage is coming from—now what?
If you're using data processing or scientific computing libraries, I have written a relevant guide to reducing memory usage.
What Fil tracks
Fil will track memory allocated by:
- Normal Python code.
- C code using
- C++ code using
- Fortran 90 explicitly allocated memory (tested with gcc's
Still not supported, but planned:
mmap(). The usage here is inconsistent since the OS can swap it in or out, so probably supporting this will involve a different kind of resource usage.
- Other forms of shared memory, need to investigate if any of them allow sufficient allocation.
mmap()s created via
/dev/zero(not common, since it's not cross-platform, e.g. macOS doesn't support this).
Copyright 2020 Hyphenated Enterprises LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size filprofiler-0.10.0-cp36-cp36m-macosx_10_14_x86_64.whl (271.7 kB)||File type Wheel||Python version cp36||Upload date||Hashes View|
|Filename, size filprofiler-0.10.0-cp36-cp36m-manylinux2010_x86_64.whl (1.8 MB)||File type Wheel||Python version cp36||Upload date||Hashes View|
|Filename, size filprofiler-0.10.0-cp37-cp37m-macosx_10_14_x86_64.whl (271.7 kB)||File type Wheel||Python version cp37||Upload date||Hashes View|
|Filename, size filprofiler-0.10.0-cp37-cp37m-manylinux2010_x86_64.whl (1.8 MB)||File type Wheel||Python version cp37||Upload date||Hashes View|
|Filename, size filprofiler-0.10.0-cp38-cp38-macosx_10_14_x86_64.whl (271.7 kB)||File type Wheel||Python version cp38||Upload date||Hashes View|
|Filename, size filprofiler-0.10.0-cp38-cp38-manylinux2010_x86_64.whl (1.8 MB)||File type Wheel||Python version cp38||Upload date||Hashes View|
Hashes for filprofiler-0.10.0-cp36-cp36m-macosx_10_14_x86_64.whl
Hashes for filprofiler-0.10.0-cp36-cp36m-manylinux2010_x86_64.whl
Hashes for filprofiler-0.10.0-cp37-cp37m-macosx_10_14_x86_64.whl
Hashes for filprofiler-0.10.0-cp37-cp37m-manylinux2010_x86_64.whl
Hashes for filprofiler-0.10.0-cp38-cp38-macosx_10_14_x86_64.whl
Hashes for filprofiler-0.10.0-cp38-cp38-manylinux2010_x86_64.whl