Skip to content
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

adaptive netcdf cache size #441

Merged
merged 2 commits into from
Jun 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions libs/gdal/frmts/gsky_netcdf/netcdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,47 @@ void netCDFRasterBand::SetBlockSize()
nBlockYSize = (int)chunksize[nZDim - 2];
else
nBlockYSize = 1;

if(nBand == 1) {
size_t cacheSize;
size_t nElems;
float preemption;
nc_get_var_chunk_cache(cdfid, nZId, &cacheSize, &nElems, &preemption);

size_t newCacheSize = atol(CPLGetConfigOption("GDAL_NETCDF_CACHE_SIZE", "0"));
if(newCacheSize > cacheSize) {
CPLDebug("GDAL_netCDF", "newCacheSize=%ld", newCacheSize);
nc_set_var_chunk_cache(cdfid, nZId, newCacheSize, nElems, preemption);
} else {
int nd = 0;
nc_inq_varndims(cdfid, nZId, &nd);
size_t chunkSizeBytes = 1;
for(int i = 0; i < nd; i++) {
chunkSizeBytes *= chunksize[i];
}

if(cacheSize < chunkSizeBytes * 5) {
const size_t MAX_CACHE_SIZE = (size_t)4 * 1024 * 1024 * 1024;
size_t maxChunks = MAX_CACHE_SIZE / chunkSizeBytes;
if(maxChunks < 1) {
maxChunks = 1;
}
size_t desiredChunks = (size_t)(nRasterXSize / nBlockXSize);
if(desiredChunks < 5) {
desiredChunks = 5;
}
if(desiredChunks > maxChunks) {
desiredChunks = maxChunks;
}
newCacheSize = desiredChunks * chunkSizeBytes;

CPLDebug("GDAL_netCDF", "chunkSize=%ld, desiredChunks=%ld, newCacheSize=%ld, maxCacheSize=%ld",
chunkSizeBytes, desiredChunks, newCacheSize, MAX_CACHE_SIZE);

nc_set_var_chunk_cache(cdfid, nZId, newCacheSize, nElems, preemption);
}
}
}
}
}
#endif
Expand Down