Skip to content

Clarify instructions to set MALLOC_TRIM_THRESHOLD_ in nanny config #5279

Description

@jbusecke

I am experiencing some machine specific (e.g. I mostly see this happening on this machine vs others) memory issues, and wanted to set the memory trimming to a very aggressive setting as suggested here.

It is not quite clear to me how to carry out the following step:

You can modify this behavior using the distributed.nanny.environ configuration value.

I tried

import dask
dask.config.set({'distributed.nanny.environ.MALLOC_TRIM_THRESHOLD_':10})

# set up dask
from dask.distributed import LocalCluster, Client
cluster = LocalCluster()
client = Client(cluster)

# check environment variables on workers
def check():
    import os
    return os.environ["MALLOC_TRIM_THRESHOLD_"]
    
# print(f'On client: {check()}')
client.run(check)

This gives the following error trace

distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-uqmljo3j', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-xca4noxo', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-hjtzgrbs', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-0gfexb3i', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-izzzhnbt', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-givixhos', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-camyfg38', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-_yl2kk0k', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-3b8l0fg6', purging
distributed.diskutils - INFO - Found stale lock file and directory '/projects/GEOCLIM/LRGROUP/jbusecke/projects/cmip6_omz/notebooks/processing/dask-worker-space/worker-cl5f0fk3', purging
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
distributed.worker - WARNING - Run Failed
Function: check
args:     ()
kwargs:   {}
Traceback (most recent call last):
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/worker.py", line 3990, in run
    result = function(*args, **kwargs)
  File "/tmp/ipykernel_185371/2848085022.py", line 12, in check
  File "/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'MALLOC_TRIM_THRESHOLD_'
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_185371/2848085022.py in <module>
     13 
     14 # print(f'On client: {check()}')
---> 15 client.run(check)

/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/client.py in run(self, function, *args, **kwargs)
   2543         >>> c.run(print_state, wait=False)  # doctest: +SKIP
   2544         """
-> 2545         return self.sync(self._run, function, *args, **kwargs)
   2546 
   2547     @_deprecated(use_instead="Client.run which detects async functions automatically")

/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/client.py in sync(self, func, asynchronous, callback_timeout, *args, **kwargs)
    859             return future
    860         else:
--> 861             return sync(
    862                 self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
    863             )

/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/utils.py in sync(loop, func, callback_timeout, *args, **kwargs)
    324     if error[0]:
    325         typ, exc, tb = error[0]
--> 326         raise exc.with_traceback(tb)
    327     else:
    328         return result[0]

/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/utils.py in f()
    307             if callback_timeout is not None:
    308                 future = asyncio.wait_for(future, callback_timeout)
--> 309             result[0] = yield future
    310         except Exception:
    311             error[0] = sys.exc_info()

/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/tornado/gen.py in run(self)
    760 
    761                     try:
--> 762                         value = future.result()
    763                     except Exception:
    764                         exc_info = sys.exc_info()

/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/site-packages/distributed/client.py in _run(self, function, nanny, workers, wait, *args, **kwargs)
   2480             elif resp["status"] == "error":
   2481                 typ, exc, tb = clean_exception(**resp)
-> 2482                 raise exc.with_traceback(tb)
   2483         if wait:
   2484             return results

/tmp/ipykernel_185371/2848085022.py in check()
     10 def check():
     11     import os
---> 12     return os.environ["MALLOC_TRIM_THRESHOLD_"]
     13 
     14 # print(f'On client: {check()}')

/scratch/gpfs2/jbusecke/conda_tigressdata/envs/cmip6_omz/lib/python3.9/os.py in __getitem__()
    677         except KeyError:
    678             # raise KeyError with the original key value
--> 679             raise KeyError(key) from None
    680         return self.decodevalue(value)
    681 

KeyError: 'MALLOC_TRIM_THRESHOLD_'

which I interpret as the fact that the env variable is actually not set?

If I set MALLOC_TRIM_THRESHOLD_=0 (note the different value) before starting my notebook, I get this output.

On client: 0
{'tcp://127.0.0.1:33430': '0',
 'tcp://127.0.0.1:35192': '0',
 'tcp://127.0.0.1:37706': '0',
 'tcp://127.0.0.1:42139': '0',
 'tcp://127.0.0.1:43006': '0',
 'tcp://127.0.0.1:44153': '0',
 'tcp://127.0.0.1:44407': '0',
 'tcp://127.0.0.1:45369': '0',
 'tcp://127.0.0.1:45910': '0',
 'tcp://127.0.0.1:46315': '0'}

I mainly have two questions:

  1. I assume I am making a mistake in setting the env variable in the first place? Or does the LocalCluster not use nannys?

  2. Is the check I am carrying out sufficient, and is in my case setting MALLOC_TRIM_THRESHOLD_ before starting the notebook sufficient?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions