My tips to optimize Drupal
   Drupal is a great CMS but it's a bit top-heavy.  I don't know how it compares to other CMS's but from my  experience it can really push your CPU and memory usage.  When we moved to our dedicated server I thought that the almost daily site-crashes would be a thing of the past, but within weeks of transferring our site as soon as traffic started to increase we ran into trouble.
These are some of the things I learned to minimize CPU and memory usage:
- Activate the Drupal cache: The built-in Drupal cache displays cached pages to anonymous users, saving the overhead of database queries to build every page.  Members that are signed-in get uncached pages
 
- Disable un-used modules.  Don't just disable them, but remove them from the modules directory completely.  Even when the modules are sitting there deactivated, they still consume memory
- Disable the Statistics module: The Drupal statistics module is great.  It tracks every pageview and every referrer and is a great way to see what is happening at the site.  The only problem is that it tracks every pageview and every referrer - creating a significant load on the CPU - causing a 30%-40% increase in CPU usage during peak traffic.  I still turn the statistics module on from time to time, but it's usually off.
- Disable (or don't use) too many filters: I disabled the WordFilter and Smiley's filter.  We have three moderators so the WordFilter isn't necessary anymore and we don't need the Smiley filter because TinyMCE has it's own smileys
- Clear the Sessions Table:  Once a week I put the site into maintenance-mode and empty the sessions table.  If you get a lot of visitors this table can grow quite large.  After clearing the sessions table you and everyone else will get logged-out and will be forced to log-in the next time you access the site.  In case you forget, the url to log yourself back in is http://yoursite.com/user  if you have SE Friendly URLs activated, http://yoursite.com/?q=user if you don't
 
- Clear the Cache: When I clear the sessions table, I also clear the cache.  Before doing this, I disable the cache
- Optimize Tables: After clearing the cache and sessions tables I optimize all of the database tables
- Upgrade your RAM: I was forced to upgrade from 1GB to 2GB of server RAM.  Prior to the upgrade my memory usage was floating around 75%-90%, and would occasionally hit 100%; swap usage was also very high.  After the upgrade to 2GB, memory usage floats around 38%-45% and rarely tops 50%; swap usage is usually now 0%
All the things I did are pretty basic, but they made a significant difference in the response time of the site and they also help keep the server from falling over.
Labels: Drupal