Statistics Caching

From SEOW Wiki
Jump to navigation Jump to search

Many people have commented that the Statistics pages can take a long time to load and can be very demanding on the MP host server. There can be two reasons for this:

  • Your MySQL campaign database is in need of repair. This manifests itself by queries taking a long time to complete, if ever. The simple MySQL analyze and repair tools often fix this.
  • More fundamentally, the Statistics pages themselves are dynamically generated. This means that each time a stats page is requested for viewing, it is generated again from scratch. Since the SQL logic in the stats is complex, this can really hit performance when many people are requesting pages at the same time, e.g. at the end of a mission. MySQL can be configured to cache SQL queries which can help performance, but there is still considerable load.


SEOW Statistics Cache

From Statistics v1.127, SEOW offers a "caching" tool for all statistics pages. This is somewhat of a misnomer because the new feature does not really produce a cache, rather it produces pre-built static HTML pages that engender very little server load to distribute to requesting clients.

The Statistics Cache is enabled/disabled by setting the following configuration variable in MP4/Statistics/MP-StatisticsMetadata.php:

 $StatsUseCache = true;       //Enable statistics page caching tools.

To use the conventional Statistics code, simply set this variable to false. Once enabled, and for each active campaign, the Statistics page will provide three cache management links under the campaign link. These links are "update", "rebuild" and "manual".

update This link should be clicked after each mission is analyzed. This will set off a chain of Statistics scripts that will create a static HTML page for the latest mission, and update the appropriate dependent pages (individual pilot details, cumulative losses, and the campaign mission history page). This may take some time if the number of pilots in the latest mission was large, so let this page run until you see the cache performance text appear at the bottom of the page.

rebuild This link should only be clicked to build ALL necessary statistics pages for a campaign. This will set off a chain of Statistics scripts that will create a static HTML page for ALL the missions, and update ALL dependent pages (individual pilot details, cumulative losses, and the campaign mission history page). This may take a LONG time if the number of pilots in the campaign is large and there are many missions, so let this page run until you see the cache performance text appear at the bottom of the page.

manual This link allows you to bypass the static HTML pages and use the conventional dynamic rendering code.

Here is an example of a Statistics page with caching enabled.

Error creating thumbnail: Unable to save thumbnail to destination


Where are the cache pages located?

Whenever a cache is enabled and built, the cache is stored in a subfolder of the MP4/Statistics folder. Note that the web server must permit the MP to create these subfolders when necessary. The subfolder name is the same as the campaign sector name with spaces removed, e.g. "Normandy", or "KhalkhinGol". The statistics home page in each subfolder is called index.html. This means you can publish links to the campaign statistics cache very easily, so your commanders and pilots do not have to know about the cache tools page and always get the benefit of the static HTML statistics.

For example, if your MP4 address is

 http://your.SEOW.server/SEOW/MP4/

and you are running a Philippines campaign for 100 pilots, simply enable your Statistics cache, keep it updated after each mission, and tell your pilots that the campaign statistics are located at

 http://your.SEOW.server/SEOW/MP4/Statistics/Philippines/

Your web server will get the same number of page hits as normal, but it will take a minuscule fraction of the effort to serve the stats pages to your friends.