Skip to content

Instantly share code, notes, and snippets.

@notmyname
Created May 4, 2016 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notmyname/c4ca69c1ebf85079b673b6b153bb5bb9 to your computer and use it in GitHub Desktop.
Save notmyname/c4ca69c1ebf85079b673b6b153bb5bb9 to your computer and use it in GitHub Desktop.
From 996b2fef47ae4417f54adac77c57ef324822e497 Mon Sep 17 00:00:00 2001
From: John Dickinson <me@not.mn>
Date: Mon, 14 Sep 2015 11:16:27 -0700
Subject: [PATCH] memoize ismount with LRUCache in obj replicator memoize
base._get_info_cache to avoid memcache lookups
layering caches--what could possibly go wrong?
Change-Id: Idf2dd501c9b26f5ddb85b398860e1f5d52e5cac5
---
swift/obj/replicator.py | 10 ++++++++--
swift/proxy/controllers/base.py | 3 ++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py
index 7a8613d..c1397f8 100644
--- a/swift/obj/replicator.py
+++ b/swift/obj/replicator.py
@@ -31,9 +31,9 @@ from eventlet.support.greenlets import GreenletExit
from swift.common.ring.utils import is_local_device
from swift.common.utils import whataremyips, unlink_older_than, \
- compute_eta, get_logger, dump_recon_cache, ismount, \
+ compute_eta, get_logger, dump_recon_cache, ismount as _utils_ismount, \
rsync_module_interpolation, mkdirs, config_true_value, list_from_csv, \
- get_hub, tpool_reraise, config_auto_int_value, storage_directory
+ get_hub, tpool_reraise, config_auto_int_value, storage_directory, LRUCache
from swift.common.bufferedhttp import http_connect
from swift.common.daemon import Daemon
from swift.common.http import HTTP_OK, HTTP_INSUFFICIENT_STORAGE
@@ -46,6 +46,12 @@ DEFAULT_RSYNC_TIMEOUT = 900
hubs.use_hub(get_hub())
+@LRUCache()
+def _cached_ismount(*a, **kw):
+ return _utils_ismount(*a, **kw)
+ismount = _cached_ismount
+
+
class ObjectReplicator(Daemon):
"""
Replicate objects.
diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py
index 7dcc1ca..ccc35da 100644
--- a/swift/proxy/controllers/base.py
+++ b/swift/proxy/controllers/base.py
@@ -42,7 +42,7 @@ import six
from swift.common.wsgi import make_pre_authed_env
from swift.common.utils import Timestamp, config_true_value, \
public, split_path, list_from_csv, GreenthreadSafeIterator, \
- GreenAsyncPile, quorum_size, parse_content_type, \
+ GreenAsyncPile, quorum_size, parse_content_type, LRUCache \
document_iters_to_http_response_body
from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ChunkReadTimeout, ChunkWriteTimeout, \
@@ -452,6 +452,7 @@ def clear_info_cache(app, env, account, container=None):
_set_info_cache(app, env, account, container, None)
+@LRUCache()
def _get_info_cache(app, env, account, container=None):
"""
Get the cached info from env or memcache (if used) in that order
--
2.8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment