I've been having serious performance issues with D7 on a shared host.
I've searched around and read loads of articles and opinions about this but at this stage I've got myself in a muddle and I'm not sure what to do next, hence the call for help.
I'm hosting a fairly complicated site on 5quid host in Edinburgh. They do not have any opcode cache, no memcache and no varnish. Since this is shared hosting I don't have the option of adding these things.
The site itself doesn't make me any money at all, so I can't really afford VPS hosting or equivalent. 5quid do a turbo+ plan which would improve performance for about £180 a year. I simply don't have the budget for that sort of hosting.
What I'm seeing in the hosts control panel is my CPU usage hitting the limiters on the shared host. This suggests to me that it's a D7 issue in PHP rather than a MySQL issue. I would expect MySQL issues to manifest more as memory problems than CPU.
It seems from reading around that Boost and Authcache are my best bets. The trouble is, this is a forum based site. It started life as a PHPBB site (which is why I'm the author of the D7 port of phpbb2drupal) and I planned new features and expansion so moved to D7.
Since it's a forum, there is very little static content, so I ruled out Boost and installed Authcache. This doesn't seem to have helped at all. If anything, I'm seeing more performance issues.
I should admit that I've not really had a play around with Authcache settings...
So, my question is simple enough. Is there anything I can do to improve CPU usage of my site? As I've said, I've read up on it and I'm a little lost.
I'm not above changing host to get this to work.
Thanks for any help you can give a confused and very tired head.
Martin...

Comments
Bottomless Pit
Hi Martin
The 2 big culprits for many Drupal sites are the number of modules you have enabled, and the block system. And it's usually a memory, not a CPU issue for Drupal sites as Drupal tries to cache everything - and Views, especially, can be a real resource gobbler.
The more modules you have enabled, the longer it takes for Drupal to build your page - in the simplest of terms Drupal will check each relevant 'hook' in every enabled module to see if it requires to execute code (I believe a typical 'simple' page calls at least 80 hooks). Likewise, for every block you have enabled, Drupal will generate the block content for every page, even if it's not actually rendered (it's why Panels and Page Manager are used more often, as they have a 'pull' architecture): so maybe reduce the numbers of blocks being called - and cache the ones you have left.. And you should also use the Devel module and see if a particular module is really slowing things up (query log, page timer and memory usage are helpful here).
As you point out, Boost is not going to help you for a forum site, where the bulk of your users will be logged in. But there are other areas of Drupal caching that can help - page caching, block caching, CSS/JS compression (at /admin/config/development/performance) should be enabled. If you are also using Views, make sure you enable caching for the relevant View/display wherever you can.
So check your site on a local install and compare performance with the deployed site. Obviously there will be a difference due to network latency, but if it's a huge difference, there may be a big problem with your host, rather than your Drupal config. Check your PHP config at /admin/reports/status/php - 256M is probably the minimum you need for decent 'memory_limit' - which you can set in /site/default/settings.php or if you have access to php.ini.
I've been using Vidahost for Drupal shared hosting - it's cheap, UK-based and the support is good. Only thing I've not been able to get working with their shared hosting packages is Drush access via SSH (seems to call a different version of PHP with bugger all memory allocated).
And lots more tips at http://groups.drupal.org/high-performance. Also worth searching through the articles on 2bits.com - they seem to be the 'go to' dudes for high performance (other web shops are available etc).
Best of luck!!
Rob
I also use and like Vidahost
I also use and like Vidahost very much. Their service is very good. I had the same memory problem with drush. After trying a lot of suggestions from Drupal discussions (it seems a very common problem, not only with hostings) I asked Vidahost. They first upgraded the memory to 256M (did not help but thank you anyway :-) and then came with the solution:
Hope this helps for you too.
Drupal Performance
Check your php version is correct, in fact go through the Drupal system requirements file and make sure everything is ok.
Check your template and inc files for badly written code, some things work but badly.
Check your .htaccess file and make sure it is optimised for your setup.
Optimise the order of Drupals js and css loading, remove or compress where possible (loading is as much as 1 second for each one).
Shared hosting for Drupal7 is crap, a VPS is way better.
Memset is a great hosting company brilliant customer service.
Cheers
Thanks for the replies both of you.
I cut out a couple of modules and while I have a lot I do need them for what I'm trying to do. I discovered that since I was using ACLs to restrict access to certain forums, there was no block caching, so I added the block cache alter module and added block caching to all of my not very many blocks. I looked into using Panels but it seems to be for the content area mainly. Since I don't have that many blocks I'm not sure if it's worth the change. I'll keep it in mind in future and when I've got more time I'll have a plan to see how it all fits together.
Rob, are you saying here that for every page request, without caching, every block is generated regardless of whether or not it's used on that page? Or does it just generate every block that could be used in that page regardless of the "display this block here" settings?
I also added some caching to the views I was using. Since it's a forum I can't really cache the views that generate the forum listings but I added a five minute cache. That should allow new posts to appear fast enough but help with concurrent users.
The usual CSS/JS caching options are enables as well as the built in page caching, but I gather it won't do much for my registered users anyway. I have installed Devel on my own setup but the problems aren't manifesting here. The issue according to the monitoring panels at my ISP are CPU related. I'm hitting the CPU limiter on the shared host. Whether increasing the memory limit will help or not I can't really tell.
I had found the high performance group but most of the advice in there is related to VPS or better hosting. While this would be ideal, I can't justify the expense for a non profit site I run myself. That sort of leads onto a bigger discussion about Drupal's future. It seems short sighted to be to require that level of resources. If I was running a big expensive profit making site then I would choose Drupal, but often those sites start as small sites on a shared host. When starting a new project of that nature, why would anyone choose Drupal when it's too inefficient to use on the sort of shared hosting where most sites start? I guess that's a bigger discussion though.
Finally, cat, I'll go over the requirements document and I've found a few suggestions for changes to the .htaccess file but how do I go about changing the order of JS and CSS loading? I'm using adaptive as my base theme and I've added very little to the templates. I've mainly added CSS changes to the files provided. All JS and CSS files and aggregated and compressed already so I don't see how changing the order would help.
Thanks both of you for the suggestions of hosting companies. That may be the fix I need, but for future projects I'm finding myself questioning the use of Drupal now. As said above, if I'm starting a project on cheap shared hosting and D7 won't do the job, should I choose something else. I'm not sure if D8 will fix this issue. The focus there seems to be on mobile and responsive, which is a great goal. In the face of opinions like cat saying shared hosting is crap, I'm not sure if Drupal is cutting off it's grass roots in favour of higher profile, and more expensive, sites. Which is a shame.
Martin...
http://darksnow.co.uk (D7) written by http://darksnow.net
Hope this helps.
Shared hosting - The reason I would recommend VPS hosting is that you can configure it yourself, some apache and php modules really make the difference. I would say this is true for Joomla Wordpress and PhpBB also, hosting companies seem to be really slack about keeping their servers up to date.
On shared hosting the .htaccess can help a lot if configured correctly.
Php version - I use Php 5.4 on my server, there is a little about Php versions here...
http://drupal.org/node/1063746
Theme - Adaptive theme uses html5.js and responsive.js for its html5 I use a custom modernizr.js my typical page source looks like the source html below.
As you can see I have modernizr loading before the Drupal stuff and the rest of my js loading after. Reason - it works better and faster.
The css which loads first has all css for the site including only the relevant css from my modules. I write it in sass then compile it to one compressed css file.
As you can see I have used the jQuery update module so that I have the most relevant jQuery script.
<link rel="stylesheet" href="http://somewebsite.com/sites/all/themes/project753/css/global.css?m6yc4k" /><script src="http://somewebsite.com/sites/all/themes/project753/js/libs/modernizr.custom.15211.js?m6yc4k"></script>
<script src="http://somewebsite.com/sites/all/modules/jquery_update/replace/jquery/1.7/jquery.min.js?v=1.7.1"></script>
<script src="http://somewebsite.com/misc/jquery.once.js?v=1.2"></script>
<script src="http://somewebsite.com/misc/drupal.js?m6yc4k"></script>
<script src="http://somewebsite.com/sites/all/themes/project753/js/mylibs/somewebsite.js?m6yc4k"></script>
This method requires some work as you need to go through module themes and select the stuff you want, also you need to make changes to your inc files - Fine If you are up to speed on theming. I do not use caching for my css or js. maximum load time on this site (which includes Mediafront module + about 125 others) is 5 seconds best is 1.5 seconds.
I also would not reccommend the sub theme thing as it is clunky but having said that AT is not a bad theme to base your own on.
Js loading - See this api page.
http://api.drupalhelp.net/api/drupal/includes--common.inc/function/drupa...
Css and tpl files - Read this article.
http://sonspring.com/journal/html5-in-drupal-7
If you are using views then you should use the semantic views module as this also cuts down on the clutter.
Cat
Also
Discussion on hosting and php versions...
http://drupal.org/node/1022384
Cheers Cat
To clarify, the resource graphs in my cPanel on the shared host are showing me hitting 100% CPU usage, and this seems to be causing the serious performance issues periodically (more often than not) so I'm looking specifically for ways to limit CPU usage.
My memory usage seems fine which suggests a PHP issue (too many modules perhaps) rather than database or anything client side that messing with CSS and JS loading orders might affect.
I've seen frequent mention of tweaking .htaccess settings but I've not found any definitive documentation about that. Do you mean using it to change Apache settings not in the default file, or changing the rewrite rules to be more efficient?
It's looking increasingly like I might need better hosting, which does beg the question of whether Drupal is suitable at all for this sort of site. 2bits.com does suggest I should be able to use Drupal on shared hosting for my level of traffic (a few thousand hits a day) but perhaps D7 has changed that.
Thanks for all the help though, much appreciated.
Martin...
http://darksnow.co.uk (D7) written by http://darksnow.net
Don't Give Up Yet
There's an interesting article comparing blocks with Panels and Context at http://www.lullabot.com/articles/assembling-pages-with-drupal, and in the 'Performance' section touches on the inefficiencies of the Drupal core block system.
But I don't think that's your problem; I suspect you could have one rogue module that's just hogging all the resources. And the only way to isolate that is turn off certain modules and evaluate CPU performance. For example, in an old D6 site I ran, I had the Biblio module - every time a user logged in the module rebuilt the entire menu table which killed the site for about 30 seconds. Took a while to find it, but a quick 'patch' (OK, a hack) and all was sorted.
Other areas you should look at:
- have you got a lot of Cron tasks? Perhaps use Elysia Cron to analyse and customise cron tasking. Configure the heavy tasks to run in the middle of the night
- How many concurrent users do you have? That could quickly gobble up memory and CPU resources if you more than a handful logged in at any one time.
D7 should run fine if you have at least 256M of memory even on shared hosting. I've had D7 running even on cheap GoDaddy packages... maybe you should shop around a bit (with a more recent version of PHP), or try running it on DrupalGardens (which is highly optimised for Drupal) if money is tight?
htaccess
These are some of the things I looked at when writing my htaccess...
http://httpd.apache.org/docs/2.2/howto/htaccess.html
https://github.com/h5bp/html5-boilerplate/blob/master/doc/htaccess.md
http://perishablepress.com/stupid-htaccess-tricks/
http://www.midwesternmac.com/blogs/jeff-geerling/drupal-7-front-end-perf...