Page Speed Optimization Libraries
1.3.25.1
|
00001 // Copyright 2010 Google Inc. 00017 00018 #ifndef NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_ 00019 #define NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_ 00020 00021 #include <map> 00022 #include <set> 00023 #include <vector> 00024 00025 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/cache_interface.h" 00028 #include "net/instaweb/util/public/md5_hasher.h" 00029 #include "net/instaweb/util/public/scoped_ptr.h" 00030 #include "net/instaweb/util/public/shared_mem_cache.h" 00031 #include "net/instaweb/util/public/string.h" 00032 #include "net/instaweb/util/public/string_util.h" 00033 00034 struct apr_pool_t; 00035 struct server_rec; 00036 00037 namespace net_instaweb { 00038 00039 class AbstractSharedMem; 00040 class ApacheConfig; 00041 class ApacheMessageHandler; 00042 class ApacheServerContext; 00043 class AprMemCache; 00044 class AsyncCache; 00045 class FileSystem; 00046 class Hasher; 00047 class MessageHandler; 00048 class ModSpdyFetchController; 00049 class NamedLockManager; 00050 class QueuedWorkerPool; 00051 class RewriteOptions; 00052 class SerfUrlAsyncFetcher; 00053 class ServerContext; 00054 class SharedCircularBuffer; 00055 class SharedMemRefererStatistics; 00056 class SharedMemStatistics; 00057 class SlowWorker; 00058 class StaticAssetManager; 00059 class Statistics; 00060 class SystemCachePath; 00061 class Timer; 00062 class UrlAsyncFetcher; 00063 class UrlFetcher; 00064 class UrlPollableAsyncFetcher; 00065 class Writer; 00066 00068 class ApacheRewriteDriverFactory : public RewriteDriverFactory { 00069 public: 00071 static const char kMemcached[]; 00072 static const char kShmCache[]; 00073 00076 static const char kStaticAssetPrefix[]; 00077 00078 ApacheRewriteDriverFactory(server_rec* server, const StringPiece& version); 00079 virtual ~ApacheRewriteDriverFactory(); 00080 00081 virtual Hasher* NewHasher(); 00082 00088 UrlPollableAsyncFetcher* SubResourceFetcher(); 00089 00090 GoogleString hostname_identifier() { return hostname_identifier_; } 00091 00092 AbstractSharedMem* shared_mem_runtime() const { 00093 return shared_mem_runtime_.get(); 00094 } 00095 SharedMemRefererStatistics* shared_mem_referer_statistics() const { 00096 return shared_mem_referer_statistics_.get(); 00097 } 00102 ApacheMessageHandler* apache_message_handler() { 00103 return apache_message_handler_; 00104 } 00126 bool is_root_process() const { return is_root_process_; } 00127 void RootInit(); 00128 void ChildInit(); 00129 00130 void DumpRefererStatistics(Writer* writer); 00131 00132 SlowWorker* slow_worker() { return slow_worker_.get(); } 00133 00136 Statistics* MakeGlobalSharedMemStatistics(bool logging, 00137 int64 logging_interval_ms, 00138 const GoogleString& logging_file); 00139 00141 SharedMemStatistics* AllocateAndInitSharedMemStatistics( 00142 const StringPiece& name, const bool logging, 00143 const int64 logging_interval_ms, const GoogleString& logging_file); 00144 00145 ApacheServerContext* MakeApacheServerContext(server_rec* server); 00146 00150 void set_fetch_with_gzip(bool x) { fetch_with_gzip_ = x; } 00151 bool fetch_with_gzip() const { return fetch_with_gzip_; } 00152 00155 void set_track_original_content_length(bool x) { 00156 track_original_content_length_ = x; 00157 } 00158 bool track_original_content_length() const { 00159 return track_original_content_length_; 00160 } 00161 00162 void set_num_rewrite_threads(int x) { num_rewrite_threads_ = x; } 00163 int num_rewrite_threads() const { return num_rewrite_threads_; } 00164 void set_num_expensive_rewrite_threads(int x) { 00165 num_expensive_rewrite_threads_ = x; 00166 } 00167 int num_expensive_rewrite_threads() const { 00168 return num_expensive_rewrite_threads_; 00169 } 00170 00171 void set_message_buffer_size(int x) { 00172 message_buffer_size_ = x; 00173 } 00174 00179 void list_outstanding_urls_on_error(bool x) { 00180 list_outstanding_urls_on_error_ = x; 00181 } 00182 00183 bool use_per_vhost_statistics() const { 00184 return use_per_vhost_statistics_; 00185 } 00186 00187 void set_use_per_vhost_statistics(bool x) { 00188 use_per_vhost_statistics_ = x; 00189 } 00190 00191 bool enable_property_cache() const { 00192 return enable_property_cache_; 00193 } 00194 00195 void set_enable_property_cache(bool x) { 00196 enable_property_cache_ = x; 00197 } 00198 00200 bool inherit_vhost_config() const { 00201 return inherit_vhost_config_; 00202 } 00203 00204 void set_inherit_vhost_config(bool x) { 00205 inherit_vhost_config_ = x; 00206 } 00207 00208 bool disable_loopback_routing() const { 00209 return disable_loopback_routing_; 00210 } 00211 00212 void set_disable_loopback_routing(bool x) { 00213 disable_loopback_routing_ = x; 00214 } 00215 00216 bool install_crash_handler() const { 00217 return install_crash_handler_; 00218 } 00219 00220 void set_install_crash_handler(bool x) { 00221 install_crash_handler_ = x; 00222 } 00223 00228 SystemCachePath* GetCache(ApacheConfig* config); 00229 00231 AprMemCache* NewAprMemCache(const GoogleString& spec); 00232 00240 CacheInterface* GetMemcached(ApacheConfig* config, CacheInterface* l2_cache); 00241 00247 GoogleString CreateShmMetadataCache(const GoogleString& name, int64 size_kb); 00248 00251 CacheInterface* GetShmMetadataCache(ApacheConfig* config); 00252 00255 void PrintShmMetadataCacheStats(GoogleString* out); 00256 00259 CacheInterface* GetFilesystemMetadataCache(ApacheConfig* config); 00260 00263 void StopAsyncGets(); 00264 00268 UrlAsyncFetcher* GetFetcher(ApacheConfig* config); 00269 00272 SerfUrlAsyncFetcher* GetSerfFetcher(ApacheConfig* config); 00273 00277 bool PoolDestroyed(ApacheServerContext* rm); 00278 00281 virtual RewriteOptions* NewRewriteOptions(); 00282 00285 virtual RewriteOptions* NewRewriteOptionsForQuery(); 00286 00290 static void InitStats(Statistics* statistics); 00291 static void Initialize(); 00292 static void Terminate(); 00293 00295 void PrintMemCacheStats(GoogleString* out); 00296 00304 bool SetHttpsOptions(StringPiece directive, GoogleString* error_message); 00305 00306 ModSpdyFetchController* mod_spdy_fetch_controller() { 00307 return mod_spdy_fetch_controller_.get(); 00308 } 00309 00310 protected: 00311 virtual UrlFetcher* DefaultUrlFetcher(); 00312 virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00313 virtual void StopCacheActivity(); 00314 00316 virtual MessageHandler* DefaultHtmlParseMessageHandler(); 00317 virtual MessageHandler* DefaultMessageHandler(); 00318 virtual FileSystem* DefaultFileSystem(); 00319 virtual Timer* DefaultTimer(); 00320 virtual void SetupCaches(ServerContext* resource_manager); 00321 virtual NamedLockManager* DefaultLockManager(); 00322 virtual QueuedWorkerPool* CreateWorkerPool(WorkerPoolCategory pool, 00323 StringPiece name); 00324 00327 virtual bool ShouldWriteResourcesToFileSystem() { return false; } 00328 00331 void ParentOrChildInit(); 00335 void SharedCircularBufferInit(bool is_root); 00338 void SharedMemRefererStatisticsInit(bool is_root); 00339 00342 virtual void ShutDown(); 00343 00345 virtual void InitStaticAssetManager(StaticAssetManager* static_asset_manager); 00346 00347 private: 00348 typedef SharedMemCache<64> MetadataShmCache; 00349 struct MetadataShmCacheInfo { 00350 MetadataShmCacheInfo() : cache_backend(NULL) {} 00351 00353 scoped_ptr<CacheInterface> cache_to_use; 00354 MetadataShmCache* cache_backend; 00355 }; 00356 00359 void AutoDetectThreadCounts(); 00360 00361 apr_pool_t* pool_; 00362 server_rec* server_rec_; 00363 scoped_ptr<SharedMemStatistics> shared_mem_statistics_; 00364 scoped_ptr<AbstractSharedMem> shared_mem_runtime_; 00365 scoped_ptr<SharedCircularBuffer> shared_circular_buffer_; 00366 scoped_ptr<SlowWorker> slow_worker_; 00367 00372 GoogleString version_; 00373 00374 bool statistics_frozen_; 00375 bool is_root_process_; 00376 bool fetch_with_gzip_; 00377 bool track_original_content_length_; 00378 bool list_outstanding_urls_on_error_; 00379 00380 scoped_ptr<SharedMemRefererStatistics> shared_mem_referer_statistics_; 00381 00385 const GoogleString hostname_identifier_; 00391 ApacheMessageHandler* apache_message_handler_; 00396 ApacheMessageHandler* apache_html_parse_message_handler_; 00397 00405 typedef std::set<ApacheServerContext*> ApacheServerContextSet; 00406 ApacheServerContextSet uninitialized_managers_; 00407 00411 bool use_per_vhost_statistics_; 00412 00414 bool enable_property_cache_; 00415 00417 bool inherit_vhost_config_; 00418 00421 bool disable_loopback_routing_; 00422 00424 bool install_crash_handler_; 00425 00427 bool thread_counts_finalized_; 00428 00430 int num_rewrite_threads_; 00431 int num_expensive_rewrite_threads_; 00432 00433 int max_mod_spdy_fetch_threads_; 00434 00437 int message_buffer_size_; 00438 00448 typedef std::map<GoogleString, SystemCachePath*> PathCacheMap; 00449 PathCacheMap path_cache_map_; 00450 00466 typedef std::map<GoogleString, CacheInterface*> MemcachedMap; 00467 MemcachedMap memcached_map_; 00468 scoped_ptr<QueuedWorkerPool> memcached_pool_; 00469 std::vector<AprMemCache*> memcache_servers_; 00470 std::vector<AsyncCache*> async_caches_; 00471 00474 typedef std::map<GoogleString, MetadataShmCacheInfo*> MetadataShmCacheMap; 00475 00477 MetadataShmCacheMap metadata_shm_caches_; 00478 00482 typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap; 00483 FetcherMap fetcher_map_; 00484 typedef std::map<GoogleString, SerfUrlAsyncFetcher*> SerfFetcherMap; 00485 SerfFetcherMap serf_fetcher_map_; 00486 MD5Hasher cache_hasher_; 00487 00489 scoped_ptr<ModSpdyFetchController> mod_spdy_fetch_controller_; 00490 00491 GoogleString https_options_; 00492 00493 DISALLOW_COPY_AND_ASSIGN(ApacheRewriteDriverFactory); 00494 }; 00495 00496 } 00497 00498 #endif ///< NET_INSTAWEB_APACHE_APACHE_REWRITE_DRIVER_FACTORY_H_