Page Speed Optimization Libraries
1.13.35.1
|
#include "cache_batcher.h"
Classes | |
struct | Options |
Public Member Functions | |
CacheBatcher (const Options &options, CacheInterface *cache, AbstractMutex *mutex, Statistics *statistics) | |
Does not take ownership of the cache. Takes ownership of the mutex. | |
virtual void | Get (const GoogleString &key, Callback *callback) |
virtual void | Put (const GoogleString &key, const SharedString &value) |
virtual void | Delete (const GoogleString &key) |
virtual GoogleString | Name () const |
virtual bool | IsBlocking () const |
virtual bool | IsHealthy () const |
virtual void | ShutDown () |
Public Member Functions inherited from net_instaweb::CacheInterface | |
virtual void | MultiGet (MultiGetRequest *request) |
void | PutSwappingString (const GoogleString &key, GoogleString *value) |
virtual CacheInterface * | Backend () |
virtual bool | MustEncodeKeyInValueOnPut () const |
virtual void | PutWithKeyInValue (const GoogleString &key, const SharedString &key_and_value) |
Static Public Member Functions | |
static void | InitStats (Statistics *statistics) |
static GoogleString | FormatName (StringPiece cache, int parallelism, int max) |
Static Public Member Functions inherited from net_instaweb::CacheInterface | |
static const char * | KeyStateName (KeyState state) |
Static Public Attributes | |
static const int | kDefaultMaxParallelLookups = 1 |
static const size_t | kDefaultMaxPendingGets = 1000 |
Friends | |
class | CacheBatcherTestingPeer |
For testing use only (instrumentation, synchronization). | |
Additional Inherited Members | |
Public Types inherited from net_instaweb::CacheInterface | |
enum | KeyState { kAvailable = 0, kNotFound = 1, kOverload = 2, kNetworkError = 3, kTimeout = 4 } |
typedef std::vector< KeyCallback > | MultiGetRequest |
Protected Member Functions inherited from net_instaweb::CacheInterface | |
void | ValidateAndReportResult (const GoogleString &key, KeyState state, Callback *callback) |
Invokes callback->ValidateCandidate() and callback->Done() as appropriate. | |
void | ReportMultiGetNotFound (MultiGetRequest *request) |
Batches up cache lookups to exploit implementations that have MultiGet support. A fixed limit of outstanding cache lookups are passed through as single-key Gets when received to avoid adding latency. Above that, the keys & callbacks are queued until one of the outstanding Gets completes. When that occurs, the queued requests are passed as a single MultiGet request.
There is also a maximum queue size. If Gets stream in faster than they are completed and the queue overflows, then we respond with a fast kNotFound.
Note that this class is designed for use with an asynchronous cache implementation. To use this with a blocking cache implementation, please wrap the blocking cache in an AsyncCache.
|
virtual |
Initiates a cache fetch, calling callback->ValidateCandidate() and then callback->Done(state) when done.
Note: implementations should normally invoke the callback via ValidateAndReportResult, which will combine ValidateCandidate() and Done() together properly.
Implements net_instaweb::CacheInterface.
|
static |
Startup-time (pre-construction) initialization of statistics variables so the correct-sized shared memory can be constructed in the root Apache process.
|
inlinevirtual |
Note: CacheBatcher cannot do any batching if given a blocking cache, however it is still functional so pass on the bit.
Implements net_instaweb::CacheInterface.
|
inlinevirtual |
IsHealthy() is a rough estimation of whether cache is available for any operations. If it's false, caller may reasonably expect that making calls right now is useless as they will fail or have high latency. If it's true, operations should succeed, but some still may fail occasionally. The primary goal is to avoid sending commands to 'unhealthy' caches, e.g. if cache is under heavy load, we do not want to send even more requests.
Memory and file-based caches can simply return 'true'. It should be safe to call this frequently – the implementation shouldn't do much more that check a bool flag under mutex.
Implements net_instaweb::CacheInterface.
|
virtual |
The name of this CacheInterface – used for logging and debugging.
It is strongly recommended that you provide a static GoogleString FormatName(...) method for use in formatting the Name() return, and in testing, e.g. in third_party/pagespeed/system/system_caches_test.cc.
Implements net_instaweb::CacheInterface.
|
virtual |
Puts a value into the cache. The value that is passed in is not modified, but the SharedString is passed by non-const pointer because its reference count is bumped.
Implements net_instaweb::CacheInterface.
|
virtual |
Stops all cache activity. Further Put/Delete calls will be dropped, and MultiGet/Get will call the callback with kNotFound immediately. Note there is no Enable(); once the cache is stopped it is stopped forever. This function is intended for use during process shutdown.
Implements net_instaweb::CacheInterface.
|
static |
We are willing to only do a bounded number of parallel lookups. Note that this is independent of the number of keys in each lookup.
By setting the default at 1, we get maximum batching and minimize the number of parallel lookups we do. Note that independent of this count, there is already substantial lookup parallelism because each Apache process has its own batcher, and there can be multiple Apache servers talking to the same cache.
Further, the load-tests performed while developing this feature indicated that the best value was '1'.
|
static |
We batch up cache lookups until outstanding ones are complete. However, we bound the number of pending lookups in order to avoid exhausting memory. When the "queues" are saturated, we drop the requests, calling the callback immediately with kNotFound.