Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
system_caches.h
Go to the documentation of this file.
1 // Copyright 2013 Google Inc.
17 
18 #ifndef PAGESPEED_SYSTEM_SYSTEM_CACHES_H_
19 #define PAGESPEED_SYSTEM_SYSTEM_CACHES_H_
20 
21 #include <map>
22 #include <vector>
23 
34 
35 namespace net_instaweb {
36 
37 class AbstractSharedMem;
38 class AprMemCache;
39 class NamedLockManager;
40 class QueuedWorkerPool;
41 class RewriteDriverFactory;
42 class ServerContext;
43 class SlowWorker;
44 class Statistics;
45 class SystemCachePath;
46 
60 class SystemCaches {
61  public:
63  static const char kMemcachedAsync[];
64  static const char kMemcachedBlocking[];
65  static const char kRedisAsync[];
66  static const char kRedisBlocking[];
67  static const char kShmCache[];
68 
69  static const char kDefaultSharedMemoryPath[];
70 
71  enum StatFlags {
72  kDefaultStatFlags = 0,
73  kGlobalView = 1,
74  kIncludeMemcached = 2,
75  kIncludeRedis = 4
76  };
77 
79  static void InitStats(Statistics* statistics);
80 
84  AbstractSharedMem* shm_runtime,
85  int thread_limit);
86 
88  ~SystemCaches();
89 
90  bool is_root_process() const { return is_root_process_; }
91 
94  void RegisterConfig(SystemRewriteOptions* config);
95  void RootInit();
96  void ChildInit();
97 
101  void StopCacheActivity();
102 
105  void ShutDown(MessageHandler* message_handler);
106 
108  void SetupCaches(ServerContext* server_context, bool enable_property_cache);
109 
116  StringPiece name, int64 size_kb, GoogleString* error_msg);
117 
120  NamedLockManager* GetLockManager(SystemRewriteOptions* config);
121 
123  void PrintCacheStats(StatFlags flags, GoogleString* out);
124 
127  void set_thread_limit(int thread_limit) { thread_limit_ = thread_limit; }
128 
141 
142  private:
143  typedef SharedMemCache<64> MetadataShmCache;
144  struct MetadataShmCacheInfo {
145  MetadataShmCacheInfo()
146  : cache_to_use(NULL), cache_backend(NULL), initialized(false) {}
147 
149  CacheInterface* cache_to_use;
150  GoogleString segment;
151  MetadataShmCache* cache_backend;
152  bool initialized;
153  };
156 
157  struct ExternalCacheInterfaces {
158  ExternalCacheInterfaces() : async(NULL), blocking(NULL) {}
159  CacheInterface* async;
160  CacheInterface* blocking;
161  };
162 
175  ExternalCacheInterfaces ConstructExternalCacheInterfacesFromBlocking(
176  CacheInterface* backend, QueuedWorkerPool* pool,
177  int batcher_max_parallel_lookups, const char* async_stats_name,
178  const char* blocking_stats_name);
179 
186  ExternalCacheInterfaces NewMemcached(SystemRewriteOptions* config);
187  ExternalCacheInterfaces NewRedis(SystemRewriteOptions* config);
188 
193  ExternalCacheInterfaces NewExternalCache(SystemRewriteOptions* config);
194 
197  MetadataShmCacheInfo* LookupShmMetadataCache(const GoogleString& name);
198 
203  MetadataShmCacheInfo* GetShmMetadataCacheOrDefault(
204  SystemRewriteOptions* config);
205 
207  void SetupPcacheCohorts(ServerContext* server_context,
208  bool enable_property_cache);
209 
210  scoped_ptr<SlowWorker> slow_worker_;
211 
212  RewriteDriverFactory* factory_;
213  AbstractSharedMem* shared_mem_runtime_;
214  int thread_limit_;
215  bool is_root_process_;
216  bool was_shut_down_;
217 
227  typedef std::map<GoogleString, SystemCachePath*> PathCacheMap;
228  PathCacheMap path_cache_map_;
229 
236  scoped_ptr<QueuedWorkerPool> memcached_pool_;
237  scoped_ptr<QueuedWorkerPool> redis_pool_;
238 
244  std::vector<AprMemCache*> memcache_servers_;
245  std::vector<RedisCache*> redis_servers_;
246 
254  typedef std::map<GoogleString, ExternalCacheInterfaces> ExternalCachesMap;
255  ExternalCachesMap external_caches_map_;
256 
259  typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap;
260 
262  MetadataShmCacheMap metadata_shm_caches_;
263 
264  MD5Hasher cache_hasher_;
265 
266  bool default_shm_metadata_cache_creation_failed_;
267 
268 
269 };
270 
271 }
272 
273 #endif
void ShutDown(MessageHandler *message_handler)
NamedLockManager * GetLockManager(SystemRewriteOptions *config)
static const char kMemcachedAsync[]
CacheStats prefixes.
Definition: system_caches.h:63
void SetupCaches(ServerContext *server_context, bool enable_property_cache)
Configures server_context's caches based on its configuration.
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
~SystemCaches()
Note that you must call ShutDown() before this is deleted.
void PrintCacheStats(StatFlags flags, GoogleString *out)
Print out stats appropriate for the given flags combination.
Definition: system_rewrite_options.h:40
void RegisterConfig(SystemRewriteOptions *config)
bool CreateShmMetadataCache(StringPiece name, int64 size_kb, GoogleString *error_msg)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
SystemCaches(RewriteDriverFactory *factory, AbstractSharedMem *shm_runtime, int thread_limit)
Definition: abstract_shared_mem.h:86
SystemCachePath * GetCache(SystemRewriteOptions *config)
Definition: system_caches.h:60
static void InitStats(Statistics *statistics)
Registers all statistics the cache backends may use.
Abstract interface for a cache.
Definition: shared_mem_cache.h:46
Definition: system_cache_path.h:49
void set_thread_limit(int thread_limit)
Definition: system_caches.h:127
Definition: rewrite_driver_factory.h:70