Stash
Stash copied to clipboard
Warning from filesystem driver: mkdir(): File exists in /data/www/wrbm/corporate/prod/vendor/tedivm/stash/src/Stash/Driver/FileSystem.php on line 234
This is probably related to a race, where 2 processes might be trying to create the same directory at the same time. My suggestion: if the mkdir call fails, check again if the dir exists and, if it does, use it
PS: might relate to #302
I have an idea on how to solve this (which will, unfortunately, only work on windows). However, when people start seeing this it's generally a sign that their traffic has increased to the point where they'd benefit from running the sqlite driver instead of the filesystem one.
I still see this problem at line 221 - https://github.com/tedious/Stash/blob/main/src/Stash/Driver/FileSystem.php#L221C13-L221C76
PHP Error: mkdir(): File exists from /x/y/vendor/tedivm/stash/src/Stash/Driver/FileSystem.php on line 221 {"errno":2,"errstr":"mkdir(): File exists","errfile":"/x/y/vendor/tedivm/stash/src/Stash/Driver/FileSystem.php","errline":221,
In our case, we seem to have amassed a ~30GB stash cache over 24 hours using the filesystem driver ( 'find' says this is about 1.8m files ).
I'm curious how running the purge/cleanup routine on the cache will work with PHP's stat cache when there are multiple processes involved. I'd normally have littered similar code with clearstatcache
calls but I don't see any of these.
@tedivm you mentioned using Sqlite for high traffic instances; I seem to think sqlite often has a single process lock, so calling purge() might cause callers to be blocked?
I suspect I'll move back to using a Redis backend anyway.
If you're at the point where you've got 30gb in 24 hours I would use redis.
Yes - we are/were using Redis - but we hadn't changed the default eviction policy and a busy period led us to filling up the redis cache ... so as a hot fix I moved one thing to use a filesystem cache (hence seeing the above mkdir thing!)
I was just wondering if having a table a bit like this to help people choose cache backends (my pros/cons are likely to be incorrect)
Driver | Pros | Cons |
---|---|---|
FileSystem | Simple to setup, good for low concurrency and smaller caches | Requires manual maintenance schedule (possibly time consuming), may struggle under high concurrency, not distributed. |
Redis | more scalable | requires service/server, might be a spof |
APC | v. fast, no network dependency | very limited size, per-process (?) so limited scalability |
Memcache | network service, scalable | requires memory, not as feature rich as redis |
Sqlite | good for mostly read caches, no network dependency | may not handle high concurrency well, requires maintenance schedule |