Runaway memory usage; surely my own bug! #1241
Replies: 14 comments 10 replies
-
I'm confused, because when I run the same experiment using the standard Oceandrift model and reader_ROMS_native reader, the constant increase in memory usage continues. Now, increasing memory usage might be expected as particles spread out throughout a run, but the increases continue well past what can be explained by having to load forcing data for the entire domain. I've tried running Oceandrift now with: and also with: In all cases, my memory usage continues to rise monotonically. For a current test run, 10,000 particles, after 3 months of simulation (using daily forcing files, and hourly calculation timestep, memory usage has risen from 3.5BG to 10GB |
Beta Was this translation helpful? Give feedback.
-
Hi, Yes, OpenDrift should not use much memory, as the history array is flushed to disk every 100 timesteps by default (export_buffer_length), and for readers, only previous and upcoming timesteps are kept/cached in memory. |
Beta Was this translation helpful? Give feedback.
-
I have run with a million particles on a laptop without problems, and have never bothered to monitor memory usage as it has never been an issue for me. |
Beta Was this translation helpful? Give feedback.
-
E.g. changing the number of particles in example_generic from 3000 to 1 million gives for me a memory usage of about 4GB. |
Beta Was this translation helpful? Give feedback.
-
Could you make one or two of these ROMS files available for testing? Also it could be useful to see your full script that leads to memory problems. |
Beta Was this translation helpful? Give feedback.
-
Hi Knut, Thanks for your continued help. Please let me know if the following link doesn't work: https://drive.google.com/drive/folders/1SFrCu0EgelI1FoKelTSyaOqxje6Rp0wQ?usp=drive_link It should take you to a Google Drive folder containing my script, a single ".p" (Pickle) file from which initial lon/lat coordinates of floats are read, and 10 netCDF forcing files from our circulation model. Otherwise, I can easily paste the script here, if that's best. Thank you, |
Beta Was this translation helpful? Give feedback.
-
Hi, were you able to look at those files? Everything should run if it's all in the same directory. I'm still unable to get a single seeding of 12000 floats to run for 90 days; see the picture of memory usage, before crashing: |
Beta Was this translation helpful? Give feedback.
-
The script (unchanged) worked well on my laptop, and spend about 2 minutes, producing an output file of 269MB. |
Beta Was this translation helpful? Give feedback.
-
I am not familiar with Slurm and do presently not have access to a cluster. After downloading all your forcing files and adding So yes, there seem to be a steady increase of memory usage. I am not sure what causes this, as history/data array is flushed to disk every 100 time steps. Maybe it is Xarray consuming more memory after opening more of the forcing files? |
Beta Was this translation helpful? Give feedback.
-
I did some more testing with Memray (https://github.com/bloomberg/memray) which was quite easy to install and use, however, I was not able to identify any source of memory leak. However, I found this page hinting that Xarray has a memory leak when using the default After installing |
Beta Was this translation helpful? Give feedback.
-
You solved the problem! Thank you so much!!!!!! Memory usage rises to 2GB and then remains stable - what a sight for sore eyes! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
As the netCDF files is written with time as the open/unlimited dimension, is it not strictly CF-compatible as is. This naturally consumes a lot of memory. For very long simulations with many elements, this may crash. But the output file is still usable, just not strictly CF-compliant. |
Beta Was this translation helpful? Give feedback.
-
Hi @knutfrode, thanks for explaining the memory spike at the end of Opendrift runs. That makes sense! It also gave me a chance to look into "CF compliance". (Sorry for delayed response; just back from "spring break") |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm experiencing runaway memory usage, which kills runs once they reach the maximum available memory on my system.
I've made some minor customizations in a model and reader, and I'm confident that I have not introduced any variables that will continuously grow in size throughout the run (ie there is no list appending happening, ,etc).
I'm plotting memory usage of my runs, and it's ever-increasing in a regular staircase pattern. I am using daily model output; if I run for 10 days, I see 10 steps in the plot of memory usage. So, there seems to be a connection between when a new model output file is loaded and when memory usage jumps. The jumps are all roughly the same size throughout the run.
I installed Opendrift about three months ago, following the instructions on the main webpage (https://opendrift.github.io/install.html). So I think my version of is somewhat up-to-date.
What could be causing this ever-increasing memory usage?
I'm looking into the "run" method, to see how the history object is modified. It seems like it's initialized as a fixed-size list, and then flushed when the number of model (or output?) timesteps equals <export_buffer_length>. I haven't yet found anything in the source code that would be continuing to grow throughout the run, but I continue to look.
I've also run with various configurations (adjusting <export_buffer_length>, running with default settings (ie only specifying an output file), adjusting model and output timesteps). The staircase pattern of memory usage does not change.
Please advise,
Thank you,
Bruce
Beta Was this translation helpful? Give feedback.
All reactions