diff --git a/roles/notifs/backend/templates/fmn.consumer.py b/roles/notifs/backend/templates/fmn.consumer.py index c92f1d3fc3..6576b5c039 100644 --- a/roles/notifs/backend/templates/fmn.consumer.py +++ b/roles/notifs/backend/templates/fmn.consumer.py @@ -8,6 +8,31 @@ ircnick = "fedora-notifs" base = "https://apps.%s/notifications/" % domain +from dogpile.core.readwrite_lock import ReadWriteMutex +from dogpile.cache.backends.file import AbstractFileLock + +class MutexLock(AbstractFileLock): + """ Use an in-memory lock for our dogpile cache + in an attempt to reduce thread competition. + """ + def __init__(self, filename): + self.mutex = ReadWriteMutex() + + def acquire_read_lock(self, wait): + ret = self.mutex.acquire_read_lock(wait) + return wait or ret + + def acquire_write_lock(self, wait): + ret = self.mutex.acquire_write_lock(wait) + return wait or ret + + def release_read_lock(self): + return self.mutex.release_read_lock() + + def release_write_lock(self): + return self.mutex.release_write_lock() + + config = { {% if env == 'staging' %} # Pull in messages from production so we can more thoroughly test in stg. @@ -56,6 +81,7 @@ config = { "expiration_time": 56700, "arguments": { "filename": "/dev/shm/fmn-cache.dbm", + "lock_factory": MutexLock, # Use on-disk cache but in-memory lock. }, },