ACM Modules

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Post Reply
TerryE
Registered User
Posts: 95
Joined: Sat May 23, 2009 12:24 am
Contact:

Re: ACM Modules

Post by TerryE »

Thanks for the ACM_APC module. :-) Given that these modules were written over two years ago and have had a few hundred downloads, many of which I suspect are now in operation on some of the heavily used phpBB boards, isn't it about time they were moved out of Area51 and into the mainstream product?

I came across this topic when I was coding around some issues that we had on my forums with some bugs in the Solaris CSK 1.3.1 implementation of APC (see Sun Forums — APC change of behaviour on CSK upgrade). We have a pretty active site running a dozen forums on a common Apache instance, and sharing a common but otherwise reasonably standard phpBB code base (see phpBB3.0.4 Migration — Detailed Implementation Notes if you want more background). I also noticed that my APC cache was being expunged every hour or so, which should really be happening. I also had a problem with cron.php which meant that the cache tidying wasn't being triggered and I pretty quickly accumulated over a quarter of a million cache/sql_* files in just over a day! So I ended up adding the following to my php.ini:
  • apc.cache_by_default=1
    apc.filters="(/cache/sql_|/cache/data_)"
I wrote up my analysis on our wiki (A PHP Cache Overview and Cache Tuning.) BTW, why don't you encourage this type of contribution to your wiki?

What I really question is the design choice of keeping the sql_* and data_* cache objects as PHP include fragments, as this has not performance gain and most PHP performance accelerators are simply not optimised to handle such a volume of tiny volatile code fragments. Why not just keep them in .data files as straight serialised text? With such an approach the main load logic in get:

Code: Select all

    global $phpEx;

    if (!$this->_exists($var_name))
    {
        return false;
    }

    @include($this->cache_dir . "data{$var_name}.$phpEx");
    return (isset($data)) ? $data : false;
would become (refactoring out some of the redundant code):

Code: Select all

    $temp =  @unserialize(file_get_contents($this->cache_dir . 'data{$var_name}.data'));
    return ($temp !== false && isset(temp[0]) && time() > $temp[0] && isset(temp[01) ) 
            ? $temp[1] : false; 
with the corresponding change in put:

Code: Select all

    if ($fp = @fopen($this->cache_dir . "data{$var_name}.$phpEx", 'wb'))
    {
        @flock($fp, LOCK_EX);
        fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . 
           ") ? true : false;\nif (\$expired) { return; }\n\n\$data =  " . 
           (sizeof($var) ? "unserialize(" . var_export(serialize($var), true) . ");" : 'array();') . "\n\n?>");
        @flock($fp, LOCK_UN);
        fclose($fp);

        if (!function_exists('phpbb_chmod'))
        {
            global $phpbb_root_path;
            include($phpbb_root_path . 'includes/functions.' . $phpEx);
        }
    }

        phpbb_chmod($this->cache_dir . "data{$var_name}.$phpEx", CHMOD_WRITE);
    }
becoming

Code: Select all

    if (file_put_contents ($this->cache_dir . 'data_{$var_name}.data', serialize(array($ttl, $vars)), LOCK_EX) !== false )
    {
        if (!function_exists('phpbb_chmod'))
        {
            global $phpbb_root_path;
            include($phpbb_root_path . 'includes/functions.' . $phpEx);
        }
    }
For most users this would result in a modest performance increase but more importantly be far less hostile to other applications which are sharing a PHP accelerator. I apologise that this is only a sketched solution rather than a fully implemented one but the APC_ACM module seems a better fit form my needs, so I don't currently have the justification to implement and test this myself.

Regards Terry

TerryE
Registered User
Posts: 95
Joined: Sat May 23, 2009 12:24 am
Contact:

Re: ACM Modules

Post by TerryE »

On a related note, these modules assume a single forum per cache. Bad assumption. (I currently have 12 forums on my server.) So I have added the lines

Code: Select all

		global $dbname, $table_prefix;
		$this->store_prefix = $dbname . '.' . $table_prefix;
to the acm method and editted the rest of the file:

Code: Select all

:%s/apc_fetch(/apc_fetch($this->store_prefix . /
:%s/apc_store(/apc_store($this->store_prefix . /
:%s/apc_delete(/apc_delete($this->store_prefix . /
The caches are again specific to forum 8-) The one thing that you need to think about is whether the purge should instead be based on a delete enurating the apc_cache_info('user') cache_list on a filter of $this->store_prefix. In my case I don't mind doing a global purge so I haven't bothered.

ToonArmy
Registered User
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK
Contact:

Re: ACM Modules

Post by ToonArmy »

Hi Terry,

We are looking at the findings from your experience running the OO.org boards and are taking your findings into consideration for our next release. I've already undertaken quite a bit of work, porting the ACM plugins to the latest 3.0 code. They are available in SVN, they will work perfectly fine on 3.0.5 and 3.0.4 as well I expect. As you suggested they also prefix the cached data with a unique key which as you point out is important when you have multiple boards sharing the same shared memory cache. I'm interested in hearing any feedback you have.

Edit and reading your performance documentation, I noted the highlighted cached query we removed that in 3.0.5 it was a mistake to cache in the first place.

Chris
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image

TerryE
Registered User
Posts: 95
Joined: Sat May 23, 2009 12:24 am
Contact:

Re: ACM Modules

Post by TerryE »

Chris, Thanks for this. I am not really a typical use-case for you guys. OOo has an active policy of sponsoring active participation of national language (NL) communities so our policy is offer a board to any NL group who wants one. The aggregate page view rates are running at about 1/sec (with the images and other furniture adding about 2-6x actual Apache requests). This is currently spread over 9 live forums and we've got another 4 test / in development, though 2 of the forums (the EN and FR ones) take up 80% of the hits.

Up to 3.0.2 we did this by cloning the largely vanilla installs with some small patches of our own. Believe it or not we were struggling to get decent response with a dedicated 4 core Solaris zone at 3.0.2 with this transactional load, which was just crazy. The configuration management was also very difficult to manage because of subtle variations in the installs. (I'm a community member, so I do all this s**t pro bono). My decision to go to a shared codebase and dig into the tuning issues was driven by these factors. We now run all forums by symlinking the pretty empty instance hierarchies back to a common code base (though we do have a few cases of conditional code to handle logic which the FR forum wants and the other don't). This works extremely well with APC -- we now just sit at 100% code cached with no expunges. The acm_files module was killing us, both in disk I/O and in flushing the APC cache. I would have preferred to switch to acm_apc, but the CSK bug was a pain, and this caused us to deadlock when using the acm_apc module -- hence my Q&D implementation of acm_mysqli (which BTW works just as well as acm_apc in I/O and CPU profile but without the hangs). When I get the Sun admins to upgrade us to CSK 1.4 I might try switching back to the standard acm_apc module. I'll post back with any material observations.

Incidentally, I run another pro-bono site (this time a wiki) on a typical low-end shared service (FTP + LAMP, no interactive access or cron). I would have thought that this sort of hosting service is a far more typical for most phpBB users. Doing a phpinfo() on this, it uses Zend but no other PHP accelerators. So at the moment a files based acm would be the only option for these people. (Wikimedia allows a DB option for this scenario through its $wgMainCacheType parameter, etc.) So I do think it would be a good performance option to offer an acm_dbal module for this sort of scenario.

I also think it would be good to have a kB or wiki article on some of these performance issues to help the admins of the busier forums on this learning curve. Do you want me to draft one? I can dump in in my user space on your wiki. I'm a bit busy at the moment but I should have time in the next month.

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: ACM Modules

Post by naderman »

Thank you for your feedback. While you're right that most of our users don't run particularly large boards we are very interested in making phpBB a viable solution for very large communities.
TerryE wrote:I also think it would be good to have a kB or wiki article on some of these performance issues to help the admins of the busier forums on this learning curve. Do you want me to draft one? I can dump in in my user space on your wiki. I'm a bit busy at the moment but I should have time in the next month.
That would be great. Maybe you could write something about caching on our wiki?

bolverk
I've been banned
Posts: 280
Joined: Mon Feb 02, 2009 5:39 pm

Re: ACM Modules

Post by bolverk »

TerryE wrote:I also think it would be good to have a kB or wiki article on some of these performance issues to help the admins of the busier forums on this learning curve.
Yes by all means do not let the reception you received in your previous request on where/how to contribute stop you. I for one enjoy reading your posts immensely and look forward to reading what you contribute. ;)

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 373
Joined: Thu Sep 16, 2004 9:02 am
Contact:

Re: ACM Modules

Post by Paul »

I never said it wasn't a good idea to post it somewhere :), only thing I said was that if you post it, you might receive a lot of questions regarding it as requires a lot more knowledge to run or use the scripts. Its ofcourse a good thing to publish it, the only question what I wanted to bring with my post there was where.

ToonArmy
Registered User
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK
Contact:

Re: ACM Modules

Post by ToonArmy »

bolverk wrote:
TerryE wrote:I also think it would be good to have a kB or wiki article on some of these performance issues to help the admins of the busier forums on this learning curve.
Yes by all means do not let the reception you received in your previous request on where/how to contribute stop you. I for one enjoy reading your posts immensely and look forward to reading what you contribute. ;)
I never saw those replies, if I had I would have commented. ;)
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image

User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: ACM Modules

Post by naderman »

Chris started an article on caching: http://wiki.phpbb.com/Cache

ToonArmy
Registered User
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK
Contact:

Re: ACM Modules

Post by ToonArmy »

naderman wrote:Chris started an article on caching: http://wiki.phpbb.com/Cache
Chris also forgot to press submit :roll:
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image

Post Reply