Page Speed Optimization Libraries  1.13.35.1
 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 PAGESPEED_SYSTEM_SYSTEM_REWRITE_DRIVER_FACTORY_H_
18 #define PAGESPEED_SYSTEM_SYSTEM_REWRITE_DRIVER_FACTORY_H_
19 
20 #include <map>
21 #include <memory>
22 #include <set>
23 #include <vector>
24 
36 
37 namespace net_instaweb {
38 
39 class AbstractSharedMem;
40 class FileSystem;
41 class MessageHandler;
42 class NamedLockManager;
43 class NonceGenerator;
44 class ProcessContext;
45 class ServerContext;
46 class SharedCircularBuffer;
47 class SharedMemStatistics;
48 class StaticAssetManager;
49 class SystemCaches;
50 class SystemRewriteOptions;
51 class SystemServerContext;
52 class SystemThreadSystem;
53 class Timer;
54 class UrlAsyncFetcher;
55 
58  public:
69  SystemRewriteDriverFactory(const ProcessContext& process_context,
70  SystemThreadSystem* thread_system,
71  AbstractSharedMem* shared_mem_runtime,
72  StringPiece hostname, int port);
73  virtual ~SystemRewriteDriverFactory();
74  void Init();
75 
78  static void InitApr();
79 
80  AbstractSharedMem* shared_mem_runtime() const {
81  return shared_mem_runtime_.get();
82  }
83 
86  bool local, const StringPiece& name, const SystemRewriteOptions& options);
87 
90  virtual void NonStaticInitStats(Statistics* statistics) = 0;
91 
94 
118  bool is_root_process() const { return is_root_process_; }
119  virtual void RootInit();
120  virtual void ChildInit();
121 
124  virtual void ParentOrChildInit();
125 
133  void PostConfig(const std::vector<SystemServerContext*>& server_contexts,
134  GoogleString* error_message,
135  int* error_index,
136  Statistics** global_statistics);
137 
141  void SharedCircularBufferInit(bool is_root);
142 
154  StringPiece option,
155  StringPiece arg,
156  bool process_scope,
157  GoogleString* msg,
158  MessageHandler* handler);
159  virtual RewriteOptions::OptionSettingResult ParseAndSetOption2(
160  StringPiece option,
161  StringPiece arg1,
162  StringPiece arg2,
163  bool process_scope,
164  GoogleString* msg,
165  MessageHandler* handler);
166 
167  virtual Hasher* NewHasher();
168  virtual Timer* DefaultTimer();
169  virtual ServerContext* NewServerContext();
170 
172  virtual bool enable_property_cache() const {
173  return true;
174  }
175 
176  GoogleString hostname_identifier() { return hostname_identifier_; }
177 
180  virtual void ShutDown();
181 
182  virtual void StopCacheActivity();
183 
184  SystemCaches* caches() { return caches_.get(); }
185 
186  virtual void set_message_buffer_size(int x) {
187  message_buffer_size_ = x;
188  }
189 
193  UrlAsyncFetcher* GetFetcher(SystemRewriteOptions* config);
194 
198  track_original_content_length_ = x;
199  }
200  bool track_original_content_length() const {
201  return track_original_content_length_;
202  }
203 
209  list_outstanding_urls_on_error_ = x;
210  }
211 
215  virtual int max_queue_size() { return 500 * requests_per_host(); }
216  virtual int queued_per_host() { return 500 * requests_per_host(); }
217  virtual int requests_per_host();
218 
219  void set_static_asset_prefix(StringPiece s) {
220  s.CopyToString(&static_asset_prefix_);
221  }
222  const GoogleString& static_asset_prefix() { return static_asset_prefix_; }
223 
224  int num_rewrite_threads() const { return num_rewrite_threads_; }
225  void set_num_rewrite_threads(int x) { num_rewrite_threads_ = x; }
226  int num_expensive_rewrite_threads() const {
227  return num_expensive_rewrite_threads_;
228  }
229  void set_num_expensive_rewrite_threads(int x) {
230  num_expensive_rewrite_threads_ = x;
231  }
232  bool use_per_vhost_statistics() const {
233  return use_per_vhost_statistics_;
234  }
235  void set_use_per_vhost_statistics(bool x) {
236  use_per_vhost_statistics_ = x;
237  }
238  bool install_crash_handler() const {
239  return install_crash_handler_;
240  }
241  void set_install_crash_handler(bool x) {
242  install_crash_handler_ = x;
243  }
244 
247  virtual bool UseBeaconResultsInFilters() const {
248  return true;
249  }
250 
254  virtual bool IsServerThreaded() {
255  return false;
256  }
257 
260  virtual int LookupThreadLimit() {
261  return 1;
262  }
263 
269  virtual void StartController(const SystemRewriteOptions& options);
270 
272  virtual void NameProcess(const char* name);
273 
278  virtual void PrepareForkedProcess(const char* name);
279 
283  virtual void PrepareControllerProcess();
284 
285  protected:
288  static void InitStats(Statistics* statistics);
289 
291  virtual void InitStaticAssetManager(StaticAssetManager* static_asset_manager);
292 
293  virtual void SetupCaches(ServerContext* server_context);
295  StringPiece name);
296 
298  virtual void SetupMessageHandlers() {}
299  virtual void ShutDownMessageHandlers() {}
300  virtual void SetCircularBuffer(SharedCircularBuffer* buffer) {}
301 
304  virtual void ShutDownFetchers() {}
305 
313  typedef std::set<SystemServerContext*> SystemServerContextSet;
314  SystemServerContextSet uninitialized_server_contexts_;
315 
320 
321  virtual FileSystem* DefaultFileSystem();
323 
326  virtual void AutoDetectThreadCounts();
327 
328  bool thread_counts_finalized() { return thread_counts_finalized_; }
329 
331  std::shared_ptr<CentralController> GetCentralController(
332  NamedLockManager* lock_manager) override;
333 
334  private:
337  Statistics* SetUpGlobalSharedMemStatistics(
338  const SystemRewriteOptions& options);
339 
343  GoogleString GetFetcherKey(bool include_slurping_config,
344  const SystemRewriteOptions* config);
345 
350  UrlAsyncFetcher* GetBaseFetcher(SystemRewriteOptions* config);
351 
352  virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
353 
354  scoped_ptr<SharedMemStatistics> shared_mem_statistics_;
357  StringVector local_shm_stats_segment_names_;
358  scoped_ptr<AbstractSharedMem> shared_mem_runtime_;
359  scoped_ptr<SharedCircularBuffer> shared_circular_buffer_;
360 
361  bool statistics_frozen_;
362  bool is_root_process_;
363 
367  const GoogleString hostname_identifier_;
368 
371  int message_buffer_size_;
372 
374  scoped_ptr<SystemCaches> caches_;
375 
376  bool track_original_content_length_;
377  bool list_outstanding_urls_on_error_;
378 
391  typedef std::map<GoogleString, UrlAsyncFetcher*> FetcherMap;
392  FetcherMap base_fetcher_map_;
393  FetcherMap fetcher_map_;
394 
396  GoogleString static_asset_prefix_;
397 
399  SystemThreadSystem* system_thread_system_;
400 
404  bool use_per_vhost_statistics_;
405 
407  bool install_crash_handler_;
408 
410  bool thread_counts_finalized_;
411 
413  int num_rewrite_threads_;
414  int num_expensive_rewrite_threads_;
415 
416  std::shared_ptr<CentralControllerRpcClient> central_controller_;
417 
418 
419 };
420 
421 }
422 
423 #endif
virtual void StartController(const SystemRewriteOptions &options)
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:260
Definition: static_asset_manager.h:48
bool is_root_process() const
Definition: system_rewrite_driver_factory.h:118
std::set< SystemServerContext * > SystemServerContextSet
Definition: system_rewrite_driver_factory.h:313
SystemRewriteDriverFactory(const ProcessContext &process_context, SystemThreadSystem *thread_system, AbstractSharedMem *shared_mem_runtime, StringPiece hostname, int port)
Definition: named_lock_manager.h:82
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual void SetupCaches(ServerContext *server_context)
Definition: shared_mem_statistics.h:182
WorkerPoolCategory
Definition: rewrite_driver_factory.h:75
virtual void PrepareForkedProcess(const char *name)
void set_track_original_content_length(bool x)
Definition: system_rewrite_driver_factory.h:197
virtual int requests_per_host()
Normally 4, or #threads if that's more.
UrlAsyncFetcher * GetFetcher(SystemRewriteOptions *config)
std::shared_ptr< CentralController > GetCentralController(NamedLockManager *lock_manager) override
Delegate from RewriteDriverFactory to construct CentralController.
A server context with features specific to a psol port on a unix system.
Definition: system_rewrite_driver_factory.h:57
virtual bool IsServerThreaded()
Definition: system_rewrite_driver_factory.h:254
Definition: system_thread_system.h:32
Definition: system_rewrite_options.h:40
Definition: scoped_ptr.h:30
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: abstract_shared_mem.h:86
Definition: queued_worker_pool.h:50
virtual RewriteOptions::OptionSettingResult ParseAndSetOption1(StringPiece option, StringPiece arg, bool process_scope, GoogleString *msg, MessageHandler *handler)
Definition: file_system.h:76
static void InitStats(Statistics *statistics)
virtual void SetupMessageHandlers()
Definition: system_rewrite_driver_factory.h:298
virtual NamedLockManager * DefaultLockManager()
virtual void NonStaticInitStats(Statistics *statistics)=0
Definition: server_context.h:99
Definition: process_context.h:35
virtual int max_queue_size()
Definition: system_rewrite_driver_factory.h:215
Statistics * statistics()
Definition: rewrite_driver_factory.h:247
virtual void NameProcess(const char *name)
Set the name of this process, for debugging visibility.
OptionSettingResult
Used for return value of SetOptionFromName.
Definition: rewrite_options.h:813
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:172
Definition: message_handler.h:39
virtual void ShutDownFetchers()
Definition: system_rewrite_driver_factory.h:304
virtual UrlAsyncFetcher * AllocateFetcher(SystemRewriteOptions *config)
Definition: nonce_generator.h:28
virtual QueuedWorkerPool * CreateWorkerPool(WorkerPoolCategory pool, StringPiece name)
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
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:247
virtual void InitStaticAssetManager(StaticAssetManager *static_asset_manager)
Initializes the StaticAssetManager.
Definition: hasher.h:30
virtual ServerContext * NewServerContext()
Definition: url_async_fetcher.h:33
void list_outstanding_urls_on_error(bool x)
Definition: system_rewrite_driver_factory.h:208
Definition: rewrite_driver_factory.h:70