Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
system_rewrite_driver_factory.h
Go to the documentation of this file.
1 // Copyright 2013 Google Inc.
16 
17 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_
18 #define NET_INSTAWEB_SYSTEM_PUBLIC_SYSTEM_REWRITE_DRIVER_FACTORY_H_
19 
20 #include <map>
21 #include <set>
22 #include <vector>
23 
26 #include "pagespeed/kernel/base/basictypes.h"
27 #include "pagespeed/kernel/base/scoped_ptr.h"
28 #include "pagespeed/kernel/base/string.h"
29 #include "pagespeed/kernel/base/string_util.h"
30 
31 namespace net_instaweb {
32 
33 class AbstractSharedMem;
34 class FileSystem;
35 class Hasher;
36 class MessageHandler;
37 class NamedLockManager;
38 class NonceGenerator;
39 class ProcessContext;
40 class QueuedWorkerPool;
41 class ServerContext;
42 class SharedCircularBuffer;
43 class SharedMemStatistics;
44 class StaticAssetManager;
45 class Statistics;
46 class SystemCaches;
47 class SystemRewriteOptions;
48 class SystemServerContext;
49 class SystemThreadSystem;
50 class Timer;
51 class UrlAsyncFetcher;
52 
55  public:
66  SystemRewriteDriverFactory(const ProcessContext& process_context,
67  SystemThreadSystem* thread_system,
68  AbstractSharedMem* shared_mem_runtime,
69  StringPiece hostname, int port);
70  virtual ~SystemRewriteDriverFactory();
71  void Init();
72 
75  static void InitApr();
76 
77  AbstractSharedMem* shared_mem_runtime() const {
78  return shared_mem_runtime_.get();
79  }
80 
82  SharedMemStatistics* AllocateAndInitSharedMemStatistics(
83  bool local, const StringPiece& name, const SystemRewriteOptions& options);
84 
87  virtual void NonStaticInitStats(Statistics* statistics) = 0;
88 
90  NonceGenerator* DefaultNonceGenerator();
91 
115  bool is_root_process() const { return is_root_process_; }
116  virtual void RootInit();
117  virtual void ChildInit();
118 
121  virtual void ParentOrChildInit();
122 
130  void PostConfig(const std::vector<SystemServerContext*>& server_contexts,
131  GoogleString* error_message,
132  int* error_index,
133  Statistics** global_statistics);
134 
138  void SharedCircularBufferInit(bool is_root);
139 
151  StringPiece option,
152  StringPiece arg,
153  bool process_scope,
154  GoogleString* msg,
155  MessageHandler* handler);
156  virtual RewriteOptions::OptionSettingResult ParseAndSetOption2(
157  StringPiece option,
158  StringPiece arg1,
159  StringPiece arg2,
160  bool process_scope,
161  GoogleString* msg,
162  MessageHandler* handler);
163 
164  virtual Hasher* NewHasher();
165  virtual Timer* DefaultTimer();
166  virtual ServerContext* NewServerContext();
167 
169  virtual bool enable_property_cache() const {
170  return true;
171  }
172 
173  GoogleString hostname_identifier() { return hostname_identifier_; }
174 
177  virtual void ShutDown();
178 
179  virtual void StopCacheActivity();
180 
181  SystemCaches* caches() { return caches_.get(); }
182 
183  virtual void set_message_buffer_size(int x) {
184  message_buffer_size_ = x;
185  }
186 
190  UrlAsyncFetcher* GetFetcher(SystemRewriteOptions* config);
191 
195  track_original_content_length_ = x;
196  }
197  bool track_original_content_length() const {
198  return track_original_content_length_;
199  }
200 
206  list_outstanding_urls_on_error_ = x;
207  }
208 
212  virtual int max_queue_size() { return 500 * requests_per_host(); }
213  virtual int queued_per_host() { return 500 * requests_per_host(); }
214  virtual int requests_per_host();
215 
216  void set_static_asset_prefix(StringPiece s) {
217  s.CopyToString(&static_asset_prefix_);
218  }
219  const GoogleString& static_asset_prefix() { return static_asset_prefix_; }
220 
221  int num_rewrite_threads() const { return num_rewrite_threads_; }
222  void set_num_rewrite_threads(int x) { num_rewrite_threads_ = x; }
223  int num_expensive_rewrite_threads() const {
224  return num_expensive_rewrite_threads_;
225  }
226  void set_num_expensive_rewrite_threads(int x) {
227  num_expensive_rewrite_threads_ = x;
228  }
229  bool use_per_vhost_statistics() const {
230  return use_per_vhost_statistics_;
231  }
232  void set_use_per_vhost_statistics(bool x) {
233  use_per_vhost_statistics_ = x;
234  }
235  bool install_crash_handler() const {
236  return install_crash_handler_;
237  }
238  void set_install_crash_handler(bool x) {
239  install_crash_handler_ = x;
240  }
241 
244  virtual bool UseBeaconResultsInFilters() const {
245  return true;
246  }
247 
251  virtual bool IsServerThreaded() {
252  return false;
253  }
254 
257  virtual int LookupThreadLimit() {
258  return 1;
259  }
260 
261  protected:
264  static void InitStats(Statistics* statistics);
265 
267  virtual void InitStaticAssetManager(StaticAssetManager* static_asset_manager);
268 
269  virtual void SetupCaches(ServerContext* server_context);
270  virtual QueuedWorkerPool* CreateWorkerPool(WorkerPoolCategory pool,
271  StringPiece name);
272 
274  virtual void SetupMessageHandlers() {}
275  virtual void ShutDownMessageHandlers() {}
276  virtual void SetCircularBuffer(SharedCircularBuffer* buffer) {}
277 
280  virtual void ShutDownFetchers() {}
281 
289  typedef std::set<SystemServerContext*> SystemServerContextSet;
290  SystemServerContextSet uninitialized_server_contexts_;
291 
296 
297  virtual FileSystem* DefaultFileSystem();
298  virtual NamedLockManager* DefaultLockManager();
299 
302  virtual void AutoDetectThreadCounts();
303 
304  bool thread_counts_finalized() { return thread_counts_finalized_; }
305 
306  private:
309  Statistics* SetUpGlobalSharedMemStatistics(
310  const SystemRewriteOptions& options);
311 
315  GoogleString GetFetcherKey(bool include_slurping_config,
316  const SystemRewriteOptions* config);
317 
322  UrlAsyncFetcher* GetBaseFetcher(SystemRewriteOptions* config);
323 
324  virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
325 
326  scoped_ptr<SharedMemStatistics> shared_mem_statistics_;
329  StringVector local_shm_stats_segment_names_;
330  scoped_ptr<AbstractSharedMem> shared_mem_runtime_;
331  scoped_ptr<SharedCircularBuffer> shared_circular_buffer_;
332 
333  bool statistics_frozen_;
334  bool is_root_process_;
335 
339  const GoogleString hostname_identifier_;
340 
343  int message_buffer_size_;
344 
346  scoped_ptr<SystemCaches> caches_;
347 
348  bool track_original_content_length_;
349  bool list_outstanding_urls_on_error_;
350 
363  typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap;
364  FetcherMap base_fetcher_map_;
365  FetcherMap fetcher_map_;
366 
368  GoogleString static_asset_prefix_;
369 
371  SystemThreadSystem* system_thread_system_;
372 
376  bool use_per_vhost_statistics_;
377 
379  bool install_crash_handler_;
380 
382  bool thread_counts_finalized_;
383 
385  int num_rewrite_threads_;
386  int num_expensive_rewrite_threads_;
387 
388  DISALLOW_COPY_AND_ASSIGN(SystemRewriteDriverFactory);
389 };
390 
391 }
392 
393 #endif
void PostConfig(const std::vector< SystemServerContext * > &server_contexts, GoogleString *error_message, int *error_index, Statistics **global_statistics)
virtual int LookupThreadLimit()
Definition: system_rewrite_driver_factory.h:257
Definition: static_asset_manager.h:44
bool is_root_process() const
Definition: system_rewrite_driver_factory.h:115
std::set< SystemServerContext * > SystemServerContextSet
Definition: system_rewrite_driver_factory.h:289
SystemRewriteDriverFactory(const ProcessContext &process_context, SystemThreadSystem *thread_system, AbstractSharedMem *shared_mem_runtime, StringPiece hostname, int port)
virtual void SetupCaches(ServerContext *server_context)
WorkerPoolCategory
Definition: rewrite_driver_factory.h:78
void set_track_original_content_length(bool x)
Definition: system_rewrite_driver_factory.h:194
virtual int requests_per_host()
Normally 4, or #threads if that's more.
UrlAsyncFetcher * GetFetcher(SystemRewriteOptions *config)
A server context with features specific to a psol port on a unix system.
Definition: system_rewrite_driver_factory.h:54
virtual bool IsServerThreaded()
Definition: system_rewrite_driver_factory.h:251
Definition: system_thread_system.h:32
Definition: system_rewrite_options.h:31
virtual RewriteOptions::OptionSettingResult ParseAndSetOption1(StringPiece option, StringPiece arg, bool process_scope, GoogleString *msg, MessageHandler *handler)
static void InitStats(Statistics *statistics)
virtual void SetupMessageHandlers()
Definition: system_rewrite_driver_factory.h:274
virtual NamedLockManager * DefaultLockManager()
virtual void NonStaticInitStats(Statistics *statistics)=0
Definition: server_context.h:101
Definition: process_context.h:35
virtual int max_queue_size()
Definition: system_rewrite_driver_factory.h:212
Statistics * statistics()
Definition: rewrite_driver_factory.h:242
OptionSettingResult
Used for return value of SetOptionFromName.
Definition: rewrite_options.h:607
NonceGenerator * DefaultNonceGenerator()
Creates a HashedNonceGenerator initialized with data from /dev/random.
virtual bool enable_property_cache() const
Hook so implementations may disable the property cache.
Definition: system_rewrite_driver_factory.h:169
virtual void ShutDownFetchers()
Definition: system_rewrite_driver_factory.h:280
virtual UrlAsyncFetcher * AllocateFetcher(SystemRewriteOptions *config)
virtual QueuedWorkerPool * CreateWorkerPool(WorkerPoolCategory pool, StringPiece name)
SharedMemStatistics * AllocateAndInitSharedMemStatistics(bool local, const StringPiece &name, const SystemRewriteOptions &options)
Creates and ::Initializes a shared memory statistics object.
virtual bool UseBeaconResultsInFilters() const
Definition: system_rewrite_driver_factory.h:244
virtual void InitStaticAssetManager(StaticAssetManager *static_asset_manager)
Initializes the StaticAssetManager.
virtual ServerContext * NewServerContext()
Definition: url_async_fetcher.h:33
void list_outstanding_urls_on_error(bool x)
Definition: system_rewrite_driver_factory.h:205
Definition: rewrite_driver_factory.h:73