Skip to content

Commit 59c6a88

Browse files
committed
Refactor (and compute only if needed) gdal_cachemax routine in tests
1 parent dea007b commit 59c6a88

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

‎ci/scripts_utils.py‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ def broken_s2_path():
204204
return get_ci_db_dir().joinpath("broken_s2")
205205

206206

207+
def get_gdal_cachemax_mo(gdal_cachemax_pct: int):
208+
"""Returns GDAL CACHEMAX in Mo"""
209+
import psutil
210+
211+
gdal_cachemax_bytes = int(
212+
gdal_cachemax_pct / 100 * psutil.virtual_memory().available
213+
)
214+
LOGGER.debug(
215+
f"GDAL CACHEMAX[{gdal_cachemax_pct}%] = {gdal_cachemax_bytes / 1024 / 1024:.2f} Mo"
216+
)
217+
return gdal_cachemax_bytes
218+
219+
207220
def s3_env(*args, **kwargs):
208221
# See https://developmentseed.org/titiler/advanced/performance_tuning/#recommended-configuration-for-dynamic-tiling
209222
# And https://gdalcubes.github.io/source/concepts/config.html#recommended-settings-for-cloud-access
@@ -214,18 +227,8 @@ def ko_to_bytes(value):
214227
def mo_to_bytes(value):
215228
return int(value * 1e6)
216229

217-
import psutil
218230
import rasterio
219231

220-
# Defaults to 5%
221-
gdal_cachemax_pct = 10
222-
gdal_cachemax_bytes = int(
223-
gdal_cachemax_pct / 100 * psutil.virtual_memory().available
224-
)
225-
LOGGER.debug(
226-
f"GDAL CACHEMAX[{gdal_cachemax_pct}%] = {gdal_cachemax_bytes / 1024 / 1024:.2f} Mo"
227-
)
228-
229232
def decorator(function):
230233
@wraps(function)
231234
def s3_env_wrapper(*args, **kwargs):
@@ -250,12 +253,14 @@ def s3_env_wrapper(*args, **kwargs):
250253
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES="YES",
251254
#
252255
# -- useless by experience --
253-
# Size of the default block cache, can be set in byte, MB, or as a percentage of available main, memory.
254-
# GDAL_CACHEMAX=gdal_cachemax_bytes, # => doesn't seem to improve anything, in fact slows down things a bit
256+
# Size of the default block cache, can be set in byte, MB, or as a percentage of available main, memory (5% by default).
257+
# GDAL_CACHEMAX=get_gdal_cachemax_mo(gdal_cachemax_pct=10), # => doesn't seem to improve anything, in fact slows down things a bit
255258
# Number of threads GDAL can use for block reads and (de)compression, set to ALL_CPUS to use all available cores.
256259
# GDAL_NUM_THREADS="ALL_CPUS", # => doesn't seem to improve anything, in fact slows down things
257260
# Set to TRUE or EMPTY_DIR to avoid listing all files in the directory once a single file is opened (this is highly recommended).
258261
# GDAL_DISABLE_READDIR_ON_OPEN=True, # => seems to have drawbacks especially for s2
262+
# Defaults to 1000. Sets the maximum number of files to scan when searching for sidecar files in GDALOpen().
263+
# GDAL_READDIR_LIMIT_ON_OPEN=100,
259264
):
260265
return unistra.s3_env(
261266
function(*args, **kwargs), use_s3_env_var=CI_EOREADER_S3

0 commit comments

Comments
 (0)