Page Speed Optimization Libraries
1.8.31.3
|
A server context with features specific to a psol port on a unix system. More...
#include "system_rewrite_driver_factory.h"
Public Member Functions | |
SystemRewriteDriverFactory (const ProcessContext &process_context, SystemThreadSystem *thread_system, AbstractSharedMem *shared_mem_runtime, StringPiece hostname, int port) | |
AbstractSharedMem * | shared_mem_runtime () const |
SharedMemStatistics * | AllocateAndInitSharedMemStatistics (bool local, const StringPiece &name, const SystemRewriteOptions &options) |
Creates and ::Initializes a shared memory statistics object. | |
virtual void | NonStaticInitStats (Statistics *statistics)=0 |
NonceGenerator * | DefaultNonceGenerator () |
Creates a HashedNonceGenerator initialized with data from /dev/random. | |
bool | is_root_process () const |
virtual void | RootInit () |
virtual void | ChildInit () |
virtual void | ParentOrChildInit () |
void | PostConfig (const std::vector< SystemServerContext * > &server_contexts, GoogleString *error_message, int *error_index, Statistics **global_statistics) |
void | SharedCircularBufferInit (bool is_root) |
virtual Hasher * | NewHasher () |
virtual Timer * | DefaultTimer () |
virtual ServerContext * | NewServerContext () |
virtual bool | enable_property_cache () const |
Hook so implementations may disable the property cache. | |
GoogleString | hostname_identifier () |
virtual void | ShutDown () |
virtual void | StopCacheActivity () |
SystemCaches * | caches () |
virtual void | set_message_buffer_size (int x) |
UrlAsyncFetcher * | GetFetcher (SystemRewriteOptions *config) |
void | set_track_original_content_length (bool x) |
bool | track_original_content_length () const |
void | list_outstanding_urls_on_error (bool x) |
virtual int | requests_per_host () |
virtual int | max_queue_size () |
virtual int | queued_per_host () |
virtual bool | use_per_vhost_statistics () const |
void | set_static_asset_prefix (StringPiece s) |
const GoogleString & | static_asset_prefix () |
Static Public Member Functions | |
static void | InitApr () |
Protected Types | |
typedef std::set < SystemServerContext * > | SystemServerContextSet |
Protected Member Functions | |
virtual void | InitStaticAssetManager (StaticAssetManager *static_asset_manager) |
Initializes the StaticAssetManager. | |
virtual void | SetupCaches (ServerContext *server_context) |
virtual void | SetupMessageHandlers () |
virtual void | ShutDownMessageHandlers () |
virtual void | SetCircularBuffer (SharedCircularBuffer *buffer) |
virtual void | ShutDownFetchers () |
virtual UrlAsyncFetcher * | AllocateFetcher (SystemRewriteOptions *config) |
virtual FileSystem * | DefaultFileSystem () |
virtual NamedLockManager * | DefaultLockManager () |
Static Protected Member Functions | |
static void | InitStats (Statistics *statistics) |
Protected Attributes | |
SystemServerContextSet | uninitialized_server_contexts_ |
A server context with features specific to a psol port on a unix system.
typedef std::set<SystemServerContext*> net_instaweb::SystemRewriteDriverFactory::SystemServerContextSet [protected] |
Once ServerContexts are initialized via RewriteDriverFactory::InitServerContext, they will be managed by the RewriteDriverFactory. But in the root process the ServerContexts will never be initialized. We track these here so that SystemRewriteDriverFactory::ChildInit can iterate over all the server contexts that need to be ChildInit'd, and so that we can free them in the Root process that does not run ChildInit.
net_instaweb::SystemRewriteDriverFactory::SystemRewriteDriverFactory | ( | const ProcessContext & | process_context, |
SystemThreadSystem * | thread_system, | ||
AbstractSharedMem * | shared_mem_runtime, | ||
StringPiece | hostname, | ||
int | port | ||
) |
Takes ownership of thread_system.
On Posix systems implementors should leave shared_mem_runtime NULL, otherwise they should implement AbstractSharedMem for their platform and pass in an instance here. The factory takes ownership of the shared memory runtime if one is passed in. Implementors who don't want to support shared memory at all should set PAGESPEED_SUPPORT_POSIX_SHARED_MEM to false and pass in NULL, and the factory will use a NullSharedMem.
virtual UrlAsyncFetcher* net_instaweb::SystemRewriteDriverFactory::AllocateFetcher | ( | SystemRewriteOptions * | config | ) | [protected, virtual] |
Allocates a serf fetcher. Implementations may override this method to supply other kinds of fetchers. For example, ngx_pagespeed may return either a serf fetcher or an nginx-native fetcher depending on options.
virtual NamedLockManager* net_instaweb::SystemRewriteDriverFactory::DefaultLockManager | ( | ) | [protected, virtual] |
They may also supply a custom lock manager. The default implementation will use the file system.
Reimplemented from net_instaweb::RewriteDriverFactory.
UrlAsyncFetcher* net_instaweb::SystemRewriteDriverFactory::GetFetcher | ( | SystemRewriteOptions * | config | ) |
Finds a fetcher for the settings in this config, sharing with existing fetchers if possible, otherwise making a new one (and its required thread).
static void net_instaweb::SystemRewriteDriverFactory::InitApr | ( | ) | [static] |
If the server using this isn't using APR natively, call this to initialize the APR library.
static void net_instaweb::SystemRewriteDriverFactory::InitStats | ( | Statistics * | statistics | ) | [static, protected] |
Initializes all the statistics objects created transitively by SystemRewriteDriverFactory. Only subclasses should call this.
Reimplemented from net_instaweb::RewriteDriverFactory.
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.
bool net_instaweb::SystemRewriteDriverFactory::is_root_process | ( | ) | const [inline] |
For shared memory resources the general setup we follow is to have the first running process (aka the root) create the necessary segments and fill in their shared data structures, while processes created to actually handle requests attach to already existing shared data structures.
During normal server startup[1], RootInit() must be called from the root process and ChildInit() in every child process.
Keep in mind, however, that when fork() is involved a process may effectively see both calls, in which case the 'ChildInit' call would come second and override the previous root status. Both calls are also invoked in the debug single-process mode (In Apache, "httpd -X".).
Note that these are not static methods -- they are invoked on every SystemRewriteDriverFactory instance, which exist for the global configuration as well as all the virtual hosts.
Implementations should override RootInit and ChildInit for their setup. See ApacheRewriteDriverFactory for an example.
[1] Besides normal startup, Apache also uses a temporary process to syntax check the config file. That basically looks like a complete normal startup and shutdown to the code.
void net_instaweb::SystemRewriteDriverFactory::list_outstanding_urls_on_error | ( | bool | x | ) | [inline] |
When Serf gets a system error during polling, to avoid spamming the log we just print the number of outstanding fetch URLs. To debug this it's useful to print the complete set of URLs, in which case this should be turned on.
virtual ServerContext* net_instaweb::SystemRewriteDriverFactory::NewServerContext | ( | ) | [virtual] |
Creates a new ServerContext* object. ServerContext itself must be overridden per Factory as it has at least one pure virtual method.
Implements net_instaweb::RewriteDriverFactory.
virtual void net_instaweb::SystemRewriteDriverFactory::NonStaticInitStats | ( | Statistics * | statistics | ) | [pure virtual] |
Hook for subclasses to init their stats and call SystemRewriteDriverFactory::InitStats().
Implemented in net_instaweb::ApacheRewriteDriverFactory.
virtual void net_instaweb::SystemRewriteDriverFactory::ParentOrChildInit | ( | ) | [virtual] |
This helper method contains init procedures invoked by both RootInit() and ChildInit()
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.
void net_instaweb::SystemRewriteDriverFactory::PostConfig | ( | const std::vector< SystemServerContext * > & | server_contexts, |
GoogleString * | error_message, | ||
int * | error_index, | ||
Statistics ** | global_statistics | ||
) |
After the whole configuration has been read, we need to do additional configuration that requires a global view.
virtual int net_instaweb::SystemRewriteDriverFactory::requests_per_host | ( | ) | [inline, virtual] |
When RateLimitBackgroundFetches is enabled the fetcher needs to apply some limits. An implementation may need to tune these based on conditions only observable at startup, in which case they can override these.
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.
void net_instaweb::SystemRewriteDriverFactory::set_track_original_content_length | ( | bool | x | ) | [inline] |
Tracks the size of resources fetched from origin and populates the X-Original-Content-Length header for resources derived from them.
virtual void net_instaweb::SystemRewriteDriverFactory::SetupCaches | ( | ServerContext * | server_context | ) | [protected, virtual] |
Called from InitServerContext, but virtualized separately as it is platform-specific. This method must call on the server context: set_http_cache, set_metadata_cache, set_filesystem_metadata_cache, and MakePropertyCaches.
Implements net_instaweb::RewriteDriverFactory.
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.
virtual void net_instaweb::SystemRewriteDriverFactory::SetupMessageHandlers | ( | ) | [inline, protected, virtual] |
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.
void net_instaweb::SystemRewriteDriverFactory::SharedCircularBufferInit | ( | bool | is_root | ) |
Initialize SharedCircularBuffer and pass it to SystemMessageHandler and SystemHtmlParseMessageHandler. is_root is true if this is invoked from root (ie. parent) process.
virtual void net_instaweb::SystemRewriteDriverFactory::ShutDown | ( | ) | [virtual] |
Release all the resources. It also calls the base class ShutDown to release the base class resources.
Reimplemented from net_instaweb::RewriteDriverFactory.
virtual void net_instaweb::SystemRewriteDriverFactory::ShutDownFetchers | ( | ) | [inline, protected, virtual] |
Can be overridden by subclasses to shutdown any fetchers we don't know about.
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.
virtual bool net_instaweb::SystemRewriteDriverFactory::use_per_vhost_statistics | ( | ) | const [inline, virtual] |
By default statistics are collected separately for each virtual host. Allow implementations to indicate that they don't support this.
Reimplemented in net_instaweb::ApacheRewriteDriverFactory.