Optimizing Drupal on Joyent Accelerators
This is a starting point for optimizing your Drupal configuration on Joyent Accelerators. There is certainly room for improvement and automation. So, if you feel so inclined to contribute, please do so.
Out of the box, drupal does pretty good on Joyent. With some tuning, Joyent has multiple production Drupal sites with recorded traffic volumes from very small to well over 1.5 Billion Page Views per month. A recent load test did 1000 requests/sec (2.5 Billion Page views per month) to a dynamic node in a well configured Drupal installation.
Change all passwords
SSH in to webserver as both shell user and 'admin' (webmin user), change webpassword with command: passwd
Change mysql root password with http://www.cyberciti.biz/faq/mysql-change-root-password/
Create new mysql database and user
CREATE DATABASE `drupal` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'pass1'; GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON databasename.* TO 'username'@'localhost'; FLUSH privileges; (note: for drupal 6 (see install.mysql.txt in root for drupal 5 (different permissions needed))
Configure PHP
(do this before installing drupal to make sure it can be installed correctly (with mysqli for example [unless using postgres])
sudo nano /opt/local/etc/php.ini edit /opt/local/etc/php.ini on webservers turn on: extension=mysqli.so turn off: ;extension=mysql.so turn on: extension=apc.so
Configure APC
For a large Drupal site, one of the biggest performance boosts one can do is to install an op-code cache/accelerator, such as APC. See this article:
http://2bits.com/articles/php-op-code-caches-accelerators-a-must-for-a-large-site.html
Here is a sample config we used that a good start for most sites.
You will add this to the bottom of your /opt/local/etc/php.ini file:
[APC] ;specifies the size for each shared memory segment apc.shm_size=32 ;max amount of memory a script can occupy apc.max_file_size=1M apc.ttl=0 apc.gc_ttl=3600 ; means we are always atomically editing the files apc.file_update_protection=0 apc.enabled=1 apc.enable_cli=0 apc.cache_by_default=1 apc.include_once_override=0 apc.localcache=0 apc.localcache.size=512 apc.num_files_hint=1000 apc.report_autofilter=0 apc.rfc1867=0 apc.slam_defense=0 apc.stat=1 apc.stat_ctime=0 acp.ttl=7200 apc.user_entries_hint=4096 apc.user_ttl=7200 apc.write_lock=1
Add the APC Dashboard
Download http://pecl.php.net/package/APC and put apc.php in your directory so you can go to yoursite.com/apc.php
Restart webserver with command: sudo svcadm restart http
Tune Accelerator(s)
Assess your system's activity and resource consumption using the prstat command. Disable Unnecessary Processes/Services:
svcs to identify running processes
If you do not need to run a mail server on your Accelerator (if you have multiple Accelerators, do this on each separate Accelerator)
sudo svcadm disable postfix sudo svcadm disable courier sudo svcadm disable courier:authlib sudo svcadm disable courier:imap
if you have multiple accelerators, you can disable Apache on the database server by running:
sudo svcadm disable httpd
Disable APACHE/PHP and MySQL if not needed on each server where it's not needed to free up resources.
Tune/Optimize MySQL
Configure my.cnf
This file lives at /opt/local/etc/my.cnf
To track slow queries, add these lines to the my.cnf file:
log-slow-queries = /var/log/mysql/mysql-slow.log long_query_time=1 log-queries-not-using-indexes
Create that log file now, otherwise mysql complains
touch /var/log/mysql/mysql-slow.log (make sure to create mysql directory) chown mysql:mysql /var/log/mysql/mysql-slow.log
Set some tables to be innodb instead of myisam by default.
<this section in testing>After the system is running for 1-2 days, you’ll want to tweak the settings in the my.conf file. See these resources:
It's highly recommended that you learn to read and use the to called MySQLReport from HackmySQL.com
http://hackmysql.com/mysqlreport
This is very valuable tool for tuning over time as your site changes. There are others of course as well. Add links…
Tune/Optimize Apache
cd to apache /opt/local/etc/httpd/
Using a CDN?
IF NOT USING A CDN or Separating your Static content to an Nginx cluster, then turning KeepAlive On — at very large #s, it is better to have this off and use a CDN and/or split off static content to a media cluster, but with smaller sites this leads to many connections to download each image/file for each page view
edit includes/keepalive.conf and turn on, KeepAliveTimeout = 2
tweak servername and serveralias
disable apache modules don't need includes/dso.conf
dav_svn_module authz_sv_module
add in ErrorLog /home/[sitename]/logs/error_log
copy drupal's .htaccess file into the
httpd/conf/virtualhosts/sitename.conf so apcahe doesn't have to look for this file on each request and add AllowOverride None and stick drupal's rules in between <directory></directory>
Add in files directory htaccess setup
<Directory /home/YOURSITE/web/public/files> SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006 Options +FollowSymlinks </Directory>
Shared NFS Storage for Content
If you have multiple webservers, setting the /files directory to be an NFS mount and sym link it to something like:
ln -s /shared/sitename/files files
By default, apache is bound to * for ease of set up
<VirtualHost *:80> very small speed hit when you leave the * instead of the actual IP, but it is a tradeoff many of our customers choose to take.
Edit htaccess to either redirect from www.domain.com to domain.com or domain.com to www.domain.com (to force one or other, no duplicate content, SEO)
Logical Diagram
Restart
restart http with svcadm restart http
Some Miscellaneous Resources Collected
* http://www.lullabot.com/articles/using-lighttpd-static-file-server
* http://www.slideshare.net/AndyForbes/scaling-drupal-the-worth-point-web-site-442294
* http://www.scribd.com/doc/2815166/BIGIP-Reference-Guide-v4-5
* http://blog.kovyrin.net/2006/05/18/nginx-as-reverse-proxy/
* http://www.scribd.com/doc/3768693/Scaling-Drupal-Hosting
* http://wiki.joyent.com/accelerators:nginx_apache_proxy#building-installing-nginx
* http://drupal.org/project/memcache
* http://drupal.org/files/infratalk_barca.pdf
* http://drupal.org/node/259374/release
* http://buytaert.net/scaling-with-mysql-replication
* http://www.mediawiki.org/wiki/Manual:Database_access
* http://drupal.org/project/cacherouter
* http://www.sauers.com/blog/setting-up-drupal/
* http://www.slantview.com/blog/slantview/drupal-caching-cache-router
* http://szeged2008.drupalcon.org/program/sessions/caching-and-performance-improvements
