[RC] HTTP Guest Cache

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Suggested Hosts
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk » Wed Feb 13, 2013 11:52 am

Kot Matroskin wrote:Your mod looks very useful... but I have one significant objection regarding to -- I'd like to get guests ability to post messages on my forum. :) So, your mod required to switch off this ability (or says every user "don't worry, you'll see your message after cache expiration time" ;)).
Actually this isn't completely true; my mod won't cache pages that guests are able to manipulate; i.e - if guests can post or reply within a forum then the pages of that forum are not cached at all by my mod.

This is why I recommend minimising the number of forums on a board that allow guests to post messages, as it reduces the effectiveness of the mod. I'm considering adding an option that forces the mod to ignore these checks (and thus cache everything regardless), which would have the drawback you mentioned, but currently it won't do anything to content that would behave strangely if cached.


Our mods definitely achieve somewhat different results; yours should reduce server load per guest page-view for all guest user page-views, while mine can potentially save even more server load but has a more restricted set of conditions under which it will do so. When it does work it removes the need to query the server at all, however it has a lot more conditions required in order to do so (has to be a cache somewhere between the user(s) and the forum, has to be a page suitable for HTTP caching etc.).

User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Re: [Beta] HTTP Guest Cache

Post by Kot Matroskin » Wed Feb 13, 2013 12:04 pm

Haravikk wrote:When it does work it removes the need to query the server at all, however it has a lot more conditions required in order to do so
I agree with your explanation, but what about "puzomerka" feature? ;) I mean pretty statistics like "In total there are <strong>%d</strong> users online"? ;)

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk » Wed Feb 13, 2013 12:48 pm

Kot Matroskin wrote:
Haravikk wrote:When it does work it removes the need to query the server at all, however it has a lot more conditions required in order to do so
I agree with your explanation, but what about "puzomerka" feature? ;) I mean pretty statistics like "In total there are <strong>%d</strong> users online"? ;)
That will depend on how successful the caching is; if enough of your board's pages are being cached then yeah, the guest users online statistic may drop, but at the same time for every guest user "lost" you're eliminating some or all of the server load they might otherwise have generated, so it depends which you prefer :)

Thanks for mentioning it though as I should probably add it to my MODX file and description, so users can investigate other options. Personally I use Google Analytics for all my visitor statistics so the built-in counter isn't worth the extra server load of the guest user.

That said, it's possible I could add a work-around; such as a lightweight script that cached pages will still call in order to keep the guest user's session updated. That would eliminate the problem while keeping server load down.

[edit] Actually it may not affect stats all that much; depending upon how the guest user enters the forum they may actually first be redirected as my mod needs to add a parameter onto the end of cacheable URLs. So the first time a guest user views a page (usually the board index) they should be redirected, which will cause them to generate a session normally, even if they are then successfully redirected to a cached page.

User avatar
Stoker 4.0
Registered User
Posts: 1483
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen
Contact:

Re: [Beta] HTTP Guest Cache

Post by Stoker 4.0 » Wed Feb 13, 2013 6:51 pm

Testet with automod, not working.
Get this message:
Unexpected header, ending loop.

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk » Wed Feb 13, 2013 7:08 pm

Stoker 4.0 wrote:Testet with automod, not working.
Get this message:
Unexpected header, ending loop.
I just noticed the same problem; if you decompress it and upload the mod_http_guest_cache-0.1.1 folder into your /store/mods folder manually then it will work just fine.

I can't seem to get AutoMOD to give me any more information though; as far as I can tell there's nothing wrong with the mod :?

[edit] Okay, it seems to be some kind of problem with Mac OS X's built in utility that creates .zip files, when I used a different program to build the .zip it worked just fine, so I'll have to remember that when I build v0.2.0. I also figured out what I was doing wrong with my .xsl file, so opening the pretty DIY instructions should be easier from now on as well.

Not ETA on the next version just yet as I've got a few other additions I want to look at making, plus I should probably test what I already have a bit better ;)

User avatar
Stoker 4.0
Registered User
Posts: 1483
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen
Contact:

Re: [Beta] HTTP Guest Cache

Post by Stoker 4.0 » Wed Feb 13, 2013 7:59 pm

Installed on my testboard.

I dont understand how this should decrease serverload?

This is the stats with the mod disabled:
Time : 0.014s | 8 Queries | GZIP : Off

This is the stats with the mod enabled:
Time : 0.021s | 12 Queries | GZIP : Off

Bottom line, this mod adds more load to the server.

User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Have some comments

Post by Kot Matroskin » Wed Feb 13, 2013 8:08 pm

I'm not sure that it is necessary to include UMIL installation into the package. If an admin doesn't have UMIL on his site, he'll got the error with proposing to install or update UMIL. But if I have newest version on UMIL, and tries to install your package, my newest UMIL will be overridden by your files.

Why not use one language file instead of 2 separated? info_acp_mod_http_guest_cache.php should be enough, include it from UMIL installation. Btw, usually UMIL doesn't require for localization, in my case I just specified mod name and mod description.

Is it possible to replace these lines

Code: Select all

global $_SID, $_EXTRA_URL, $phpbb_hook/* BEGIN mod_http_guest_cache */, $user, $mod_http_guest_cache/* END mod_http_guest_cache*/
by the following?

Code: Select all

global $_SID, $_EXTRA_URL, $phpbb_hook;
// BEGIN mod_http_guest_cache
global $user, $mod_http_guest_cache;
// END mod_http_guest_cache
As you see it is much more readable, and easiest for further support.

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: Have some comments

Post by Haravikk » Wed Feb 13, 2013 8:24 pm

Kot Matroskin wrote:I'm not sure that it is necessary to include UMIL installation into the package. If an admin doesn't have UMIL on his site, he'll got the error with proposing to install or update UMIL. But if I have newest version on UMIL, and tries to install your package, my newest UMIL will be overridden by your files.

Why not use one language file instead of 2 separated? info_acp_mod_http_guest_cache.php should be enough, include it from UMIL installation. Btw, usually UMIL doesn't require for localization, in my case I just specified mod name and mod description.
Simple answer to all of these; I copied someone else's mod layout :D
I've taken everything you mentioned above into account; I got rid of the superfluous language file in favour of just using the mod name in the installer, and got rid of the UMIL folder for the next version of my mod.
Kot Matroskin wrote:Is it possible to replace these lines

Code: Select all

global $_SID, $_EXTRA_URL, $phpbb_hook/* BEGIN mod_http_guest_cache */, $user, $mod_http_guest_cache/* END mod_http_guest_cache*/
by the following?

Code: Select all

global $_SID, $_EXTRA_URL, $phpbb_hook;
// BEGIN mod_http_guest_cache
global $user, $mod_http_guest_cache;
// END mod_http_guest_cache
As you see it is much more readable, and easiest for further support.
Absolutely, I'll change those too :)

Thanks for the improvements!

User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Re: [Beta] HTTP Guest Cache

Post by Kot Matroskin » Wed Feb 13, 2013 8:26 pm

Stoker 4.0 wrote:Installed on my testboard.

I dont understand how this should decrease serverload?

This is the stats with the mod disabled:
Time : 0.014s | 8 Queries | GZIP : Off

This is the stats with the mod enabled:
Time : 0.021s | 12 Queries | GZIP : Off

Bottom line, this mod adds more load to the server.
This mod can help you significantly in case if you have caching proxy between your server and your users (Haravikk, I think you would specify it in mod description). For that case if any guest opened topic1, this page will be cached on proxy, and if any other guest will try to obtains the same page, proxy will provides that page without asking of your server.

To decrease server load you can try another mod: [Beta] Cache Guests Pages. Currently our mods are not compatible, but we are working on it. In future better result will obtained in case of using both these mods.

User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Re: [Beta] HTTP Guest Cache

Post by Kot Matroskin » Wed Feb 13, 2013 8:41 pm

Haravikk,

also I'd like to propose another place for your mod in admin console. ;) I'll suggest, you'll decided. ;)

Did you saw where my mod was installed? It is separated link "Cache guests & bots pages" in "Cache pages" group within "Mods" tab. So, why not install your mod there, within "Cache pages" group? There are will be two links:

HTTP Guest Cache
Cache guests & bots pages

In UMIL I did it by the following way:

Code: Select all

			'module_add' => array(
				array('acp', 'ACP_CAT_DOT_MODS', 'CGP_CAT_NAME'),

				array('acp', 'CGP_CAT_NAME',
					array(
						'module_basename'	=> 'cgp', 
						'module_auth'		=> 'acl_a_server',
						),
					),
				),

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk » Wed Feb 13, 2013 9:10 pm

Ah yeah, I've actually already done this, forgot to mention, though I haven't added it to the same category as yours, it would be a good place for it though so I'll do that :)

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk » Thu Feb 14, 2013 3:00 pm

Okay, I've been looking at improving support for my mod with your Cache Guest Pages one, and a few things have come up:

index.php
It looks like you're using the same MODX command as I am which meant that depending upon the order the mods are installed my code may not execute. I think I've corrected this since I can actually execute my code after $user->session_begin();. So long as your mod is using $auth->acl($user->data); for its MODX command this should avoid any conflict.

viewforum.php
This had a similar problem to index.php but more severe as my mod needed to wait for access to $forum_data so that it can find out if the forum is locked or not.

What I've done for this is I've moved my code up so that it executes first, and included an extra query to get forum status (only if other conditions aren't met). This means I may incur an extra query but it's an extremely small and fast one so I'm hoping it's a small enough tradeoff for compatibility.

viewtopic.php
This file actually seems to be fine, which was surprising, I expected it to be the most likely to have a conflict in it, but since your code needs to wait for values that mine doesn't then everything should be fine unless you find a way to trigger your code earlier in the file. Basically the same situation as viewforum.php but in reverse, which is fine.

If you do change the behaviour on this though (e.g - just checking the values yourself instead of waiting for the more complex checks further down) then do let me know ;)

cache_guests_pages.php
Once I release v0.2.0 of my mod I will be adding a set_headers() method for overriding HTTP cache headers. As such it should be okay for you to add the following to your mod if you'd like to ensure compatibility with mine.

Find:

Code: Select all

				header('Pragma: no-cache');
After-Add:

Code: Select all

				
				/* BEGIN mod_http_guest_cache */
				global $mod_http_guest_cache;
				if (isset($mod_http_guest_cache) && $mod_http_guest_cache->is_cacheable())
				{
					if (method_exists($mod_http_guest_cache, 'set_headers'))
					{
						$mod_http_guest_cache->set_headers();
					}
				}
				/* END mod_http_guest_cache */
The above addition should be completely safe as it checks for the existence of my cache object, which won't exist if my mod isn't installed or is turned off, and checks for the presence of the set_headers() method just to be sure a compatible version is being used. If it's okay to proceed then it simply calls set_headers() to override the various HTTP headers it needs to set.

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk » Fri Feb 15, 2013 4:20 pm

Okay, I just noticed a sort-of bug in my mod, which is that if a guest user triggers a cron-job then that job may become part of the cached result of a page, meaning that every that that cached copy is viewed the cron-job will be triggered, meaning an extra PHP request. While cron.php is generally very fast, the added requests isn't very good if it happens, and can lead to inconsistent performance from cached pages.

Anyway, the fix for this will be added to v0.2.0 but I'm not ready to release it yet. Anyone that wants to add this fix ahead of time can do the following (instructions for v0.1.1 only):

Open includes/functions.php:
Find:

Code: Select all

function page_footer($run_cron = true)
{
	global
After-Add:

Code: Select all


	/* BEGIN mod_http_guest_cache */
	// Prevent addition of cron queries to cached pages (otherwise they will call cron.php every time 
	// the cached page is viewed!)
	if ($run_cron)
	{
		global $mod_http_guest_cache;
		if (isset($mod_http_guest_cache) && $mod_http_guest_cache->is_cacheable()) 
		{
			$run_cron = false;
		}
	}
	/* END mod_http_guest_cache */
If you want to add this fix to a v0.1.0 version of the mod without uninstalling then updating to v0.1.1, then simply change instances of $mod_http_guest_cache for $mod_guest_cache.

User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Re: [Beta] HTTP Guest Cache

Post by Kot Matroskin » Sat Feb 16, 2013 9:51 pm

Hi Haravikk,

do you have final version of your mod with all changes included? I've matured to install both our mods on one server and observer the results. :)

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk » Sun Feb 17, 2013 1:07 pm

I dunno about finished, but I've uploaded v0.2.0 and added it to the first-post!

Locked

Return to “[3.0.x] MODs in Development”