improve speed of metadata
* don't load every possible answer, only do what is needed * cache instance data for a given address for a 15 seconds using either memcache or fake memcache (in-memory). This means only a single queue/db lookup for multiple calls to metadata service * add cache expirey to fake memcache (don't grow forever) and move it to nova.common.memorycache Addresses Bug #851159 Change-Id: Icf794156e055b18915b8b5be9ba2ab97d2338bbe
This commit is contained in:

committed by
Vishvananda Ishaya

parent
a8ce5c9794
commit
610df5e87d
@@ -96,7 +96,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
if FLAGS.memcached_servers:
|
if FLAGS.memcached_servers:
|
||||||
import memcache
|
import memcache
|
||||||
else:
|
else:
|
||||||
from nova.testing.fake import memcache
|
from nova.common import memorycache as memcache
|
||||||
|
|
||||||
|
|
||||||
# TODO(vish): make an abstract base class with the same public methods
|
# TODO(vish): make an abstract base class with the same public methods
|
||||||
|
@@ -97,7 +97,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
if FLAGS.memcached_servers:
|
if FLAGS.memcached_servers:
|
||||||
import memcache
|
import memcache
|
||||||
else:
|
else:
|
||||||
from nova.testing.fake import memcache
|
from nova.common import memorycache as memcache
|
||||||
|
|
||||||
|
|
||||||
class AuthBase(object):
|
class AuthBase(object):
|
||||||
|
@@ -29,11 +29,16 @@ class Client(object):
|
|||||||
self.cache = {}
|
self.cache = {}
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
"""Retrieves the value for a key or None."""
|
"""Retrieves the value for a key or None.
|
||||||
(timeout, value) = self.cache.get(key, (0, None))
|
|
||||||
if timeout == 0 or utils.utcnow_ts() < timeout:
|
this expunges expired keys during each get"""
|
||||||
return value
|
|
||||||
return None
|
for k in self.cache.keys():
|
||||||
|
(timeout, _value) = self.cache[k]
|
||||||
|
if timeout and utils.utcnow_ts() >= timeout:
|
||||||
|
del self.cache[k]
|
||||||
|
|
||||||
|
return self.cache.get(key, (0, None))[1]
|
||||||
|
|
||||||
def set(self, key, value, time=0, min_compress_len=0):
|
def set(self, key, value, time=0, min_compress_len=0):
|
||||||
"""Sets the value for a key."""
|
"""Sets the value for a key."""
|
@@ -1,2 +1 @@
|
|||||||
import memcache
|
|
||||||
import rabbit
|
import rabbit
|
||||||
|
Reference in New Issue
Block a user