We recently installed mobile_tools on a relatively high traffic site and noticed that the variables cache started being re-written to the database almost constantly. Our site has a lot of modules installed, so the associated database writes quickly became a resource issue. We tracked the issue down to the mobile_tools_boot function. By commenting out the two variable set calls, we drastically reduced database writes:

  if ($_SESSION['mobile-tools-site-type'] == 'mobile' || $theme_switched) {  
    // variable_set('default_main_nodes', variable_get('default_nodes_main_mobile', 5));
  } 
  else {
    // variable_set('default_main_nodes', variable_get('default_nodes_main_original', 10));
  }

Those variables don't get used on our site, so the fix above worked for us. However, I wanted to open an issue since it could affect others. We can probably come up with a patch, but I wanted to go ahead mention the issue first.

Comments

twom’s picture

Hi,

Performance is an issue with theme switching in Drupal. However, I don't see immediate why commenting out these to variables reduces the database rewrites... If you can help me out with this, I can optimize the module.

Further, as you will see in the module, I do something stupid, being clearing the cache at almost each page request.

/**
 * Implementation of hook_exit();
 */ 
function mobile_tools_exit() {
  // FIX ME: check what cases don't need this. Bad for performance
  cache_clear_all(NULL, 'cache_page', TRUE);
}

The only two ways to resolve this is:
- to write a different cache mechanism (should not be too hard)
- redirect each page request to the same url, but with a new argument e.g. ?mobile=true, this way the mobile page is being cached

Performance clearly need some thought! :)

twom’s picture

btw, the module seems to clear the cache in the hook_boot: cache_clear_all(NULL, 'cache_page', TRUE);

This has to change!!!

john morahan’s picture

Version: 6.x-1.11 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new2.2 KB

This only tackles the variables not the page cache

twom’s picture

Part of the issue has been fixed in a previous release: the cache is not cleared for every page request.

I removed also the setting of the variables in the boot method.

This is open for testing :)

Tom

twom’s picture

Assigned: Unassigned » twom
domesticat’s picture

Priority: Normal » Critical

I'm upgrading this to critical while I test this patch. 6.x-1.12 stable, with this bug, can fill a mysqlbinlog in under a half an hour on a not-busy personal site. I shudder to think of what it could do to a truly busy site. On my site it was continually writing and trashing over 70K of mysql query data for every single page load.

I need about a day to test this issue -- my mysqlbinlog is still a bit artificially inflated because the cache is still rebuilding -- but if this indeed fixes the issue, I would urge you in the strongest possible terms to roll this into a stable release ASAP.

twom’s picture

Hi,

Thank you for helping out and testing. Let me know what your findings are.
I'll create a stable release when your findings are ok.

Thanks,
Tom

domesticat’s picture

Status: Needs review » Reviewed & tested by the community

I'm only able to do limited testing (I only have one mobile device to test with) but the binlogs aren't whirling out of control and performance has improved. I'm marking this RTBC so we can get it into a stable release ASAP.

kiphaas7’s picture

#1: You could always look at the source code of the Domain module (more specifically the Domain Theme module) how they handle switching...

domesticat’s picture

Nudging this issue again. The fix is working, at least on our end, and some sort of fix REALLY needs to be rolled into the stable release, ASAP.

twom’s picture

I did some updates on the dev version to change the way caching is handled if theme switching is being used.

I added the mobile_tools_cache.inc file that overwrites the default caching in order to support theme switching. No cache clears are being used anymore in the module...

However if you are using a non-default caching mechanism, you should have a look at the mobile_tools_cache.inc file to learn how to work with caching.

Feedback appreciated!

PS: the dev should be rather stable.

domesticat’s picture

@twom - If the dev is stable, please release it as a new stable version. Some users will not or cannot use -dev versions on their site per contract terms, and won't upgrade to a dev version. A new stable version is appropriate in this case.

minoroffense’s picture

Status: Reviewed & tested by the community » Closed (fixed)

I'm going to close this since I'm assuming it's been committed already. Please reopen if necessary.