Cross-platform Memory.cache to tempfs
See original GitHub issueCurrently it is not possible use RAM / tempfs as the cache directory for the Memory class in a cross-platform way.
The corresponding logic is embedded within the MemmapingPool class,
if temp_folder is None:
temp_folder = os.environ.get('JOBLIB_TEMP_FOLDER', None)
if temp_folder is None:
if os.path.exists(SYSTEM_SHARED_MEM_FS):
try:
temp_folder = SYSTEM_SHARED_MEM_FS
pool_folder = os.path.join(temp_folder, pool_folder_name)
if not os.path.exists(pool_folder):
os.makedirs(pool_folder)
use_shared_mem = True
except IOError:
# Missing rights in the the /dev/shm partition,
# fallback to regular temp folder.
temp_folder = None
if temp_folder is None:
# Fallback to the default tmp folder, typically /tmp
temp_folder = tempfile.gettempdir()
and cannot be easily applied to the Memory class.
Maybe it could be worth moving this chunk of code into a separate private function, that could also be called for some pre-defined values of the cachedir Memory parameter (for instance cachedir=True, since cachedir=None is already taken)?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Does a tmpfs (/dev/shm) use Linux Page Cache? If it does ...
Since tmpfs lives completely in the page cache and on swap, all tmpfs pages will be shown as "Shmem" in /proc/meminfo and "Shared"...
Read more >Tmpfs - The Linux Kernel documentation
Tmpfs is a file system which keeps all of its files in virtual memory. Everything in tmpfs is temporary in the sense that...
Read more >Mount a folder into the RAM with TMPFS - WP Rocket
How to mount a folder directly into the RAM? ... A static cache system like WP Rocket stores all the website pages as...
Read more >How to use tmpfs and SSD for smart cache - Super User
first you should be clear if you want a cache or fast storage, storage cannot be at the same time used as a...
Read more >tmpfs - ArchWiki
tmpfs is a temporary filesystem that resides in memory and/or swap partition(s). Mounting directories as tmpfs can be an effective way of ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This may be premature optimization but it’s hard to tell without numbers. Not sure this applies to your use case but it could help to use module-level fixtures that would allow to load your objects once per test module rather than once per test function.
Fair enough I missed the non-writable part. Feel free to open a PR with a test if you feel like it. Probably keeping the function private as mentioned @GaelVaroquaux, i.e. starting with an underscore, is more appropriate.
Well probably not a huge performance difference, more avoiding writing to disk when it’s not necessary (also with each of my stored objects in the 1-20 MB range, after loading these objects from cache several times due to
@pytest.mark.parametrizethat can become a non negligible amount of I/O).True, but then there is also the case when
/dev/shmis not writable for some reason, which the original function handles.It any case it’s a non issue (I can just use that code), more an observation that it was a shame to have that logic embedded within the
MemmapingPool. Thanks for your response, I understand better why there is no such option inMemoryby default. Closing this issue…