Last active
August 29, 2015 14:12
-
-
Save cpelley/892cfc9b91f76c3f6be6 to your computer and use it in GitHub Desktop.
netcdf memory_blow-up
This file contains hidden or 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
from netCDF4 import Dataset | |
import numpy as np | |
import os | |
def process_usage(): | |
fnme = os.path.join('/', 'proc', str(os.getpid()), 'status') | |
usage = {} | |
with open(fnme, 'r') as fh: | |
for line in fh: | |
key, value = line.split(':') | |
usage[key.strip()] = value.strip() | |
print ('Virtual memory usage {} (peak {})\n' | |
'Resident set size {} (peak {})\n'.format( | |
usage['VmSize'], usage['VmPeak'], | |
usage['VmRSS'], usage['VmHWM'])) | |
dat = np.arange(100000) | |
print '{} GB'.format(dat.nbytes * 1e-9) | |
process_usage() | |
ncfile = Dataset('tmp.nc', 'w', format='NETCDF4_CLASSIC') | |
ncfile.createDimension('x', 100000) | |
#ncfile.createDimension('x', 0) # Unlimited dimension | |
data = ncfile.createVariable('data', np.dtype('float64').char, ('x',)) | |
data[:] = dat | |
ncfile.close() | |
process_usage() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NetCDF saving with unlimited dimensions increases the file size on disk by ~x5.5, it also increases the resident set size (RAM) usage by ~x12 for the test case above.