Slide 1

Slide 1 text

Build a High-Performance Server in “No Time At All”™ Chris Skene

Slide 2

Slide 2 text

The Problem •  Drupal is slow •  MySQL is slow •  Apache is slow •  mod_php is slow

Slide 3

Slide 3 text

The Drupal 6 problem •  Drupal is slow •  MySQL is slow •  Apache is slow •  mod_php is slow •  PHP 5.2 is slow

Slide 4

Slide 4 text

The solution •  Make Drupal faster •  Use MongoDB + MySQL •  Use Nginx instead of Apache •  Use PHP FastCGI Process Manager •  Use PHP 5.3 •  (Use Drupal 7)

Slide 5

Slide 5 text

When to use this? •  All the time Especially… •  Many concurrent logged-users •  Anywhere Varnish is not available/practical But not… •  For Drupal 6 (unless you are a masochist)

Slide 6

Slide 6 text

GETTING SET UP

Slide 7

Slide 7 text

The Server •  Linode 512 MB slice •  4 cores •  10112 MB storage •  256 MB swap •  Fremont data centre

Slide 8

Slide 8 text

The configuration •  Ubuntu 12.04 LTS 64 Bit •  PHP 5.3.10 •  MySQL 5.5 •  MongoDB •  Nginx 1.1.19 •  PHP-FPM

Slide 9

Slide 9 text

The solution •  Make Drupal faster •  Use MongoDB (+ MySQL) •  Use Nginx instead of Apache •  Use PHP FastCGI Process Manager •  Use PHP 5.3 •  (Use Drupal 7)

Slide 10

Slide 10 text

INSTALLATION WALK- THROUGH

Slide 11

Slide 11 text

Getting set up •  Install Ubuntu 12.04 (or upgrade 10/11) •  Good install guides in the Linode Library – Initial setup – Security •  Install MySQL apt-get install mysql-server mysql-client •  16 minutes

Slide 12

Slide 12 text

Nginx •  Asynchronous web server •  Can serve many clients simultaneously (000’s) •  Minimal memory footprint •  Potentially much faster than Apache •  AND DOESN’T SLOW DOWN •  No .htaccess (use site .conf file instead) •  copy config from http://wiki.nginx.org/Drupal

Slide 13

Slide 13 text

Installing Nginx apt-get install nginx service nginx start

Slide 14

Slide 14 text

Nginx options In nginx.conf: •  set worker processes to 2 x server cores Advanced Nginx/Drupal config available at: https://github.com/perusio/drupal-with-nginx Complex, lots of options, requires some background knowledge. Remember to use nginx –t to debug.

Slide 15

Slide 15 text

The solution •  Make Drupal faster •  Use MongoDB (+ MySQL) •  Use Nginx instead of Apache •  Use PHP FastCGI Process Manager •  Use PHP 5.3 •  (Use Drupal 7)

Slide 16

Slide 16 text

PHP5-FPM •  Apache loads all of PHP on EVERY REQUEST •  PHP-FastCGI + FPM loads PHP once for many requests, pooling connections •  Dynamic PHP process spawning •  Gracefully start and stop PHP processes •  An alternative to spawn-fcgi

Slide 17

Slide 17 text

Install PHP5-FPM apt-get install php5-fpm service php5-fpm start

Slide 18

Slide 18 text

Configure PHP5-FPM sockets (optional) •  Open FPM configuration nano /etc/php5/fpm/pool.d/www.conf •  Change… listen=127.0.0.1:9000 to… listen=/var/run/php5-fpm.sock /etc/init.d/php5-fpm restart

Slide 19

Slide 19 text

The solution •  Make Drupal faster •  Use MongoDB (+ MySQL) •  Use Nginx instead of Apache •  Use PHP FastCGI Process Manager •  Use PHP 5.3 •  (Use Drupal 7)

Slide 20

Slide 20 text

Get extra PHP things apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5- sqlite php5-tidy php5-xmlrpc php5-xsl /etc/init.d/php5-fpm restart In php.ini: cgi.fix_pathinfo = 0;

Slide 21

Slide 21 text

MongoDB •  Document store (NoSQL), not Relational store (MySQL) •  Like MySQL, supports replication, •  Unlike MySQL, supports sharding, atomic in- place updates •  Suits “high-volume problems” and anything “document like” (e.g. nodes) •  Fast!

Slide 22

Slide 22 text

Installing MongoDB •  Import the 10gen key: apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 •  Add 10gen to /etc/sources.list: deb http://downloads-distro.mongodb.org/ repo/ubuntu-upstart dist 10gen

Slide 23

Slide 23 text

Install MongoDB (cont…) apt-get update apt-get install mongodb-10gen service mongodb start

Slide 24

Slide 24 text

The solution •  Make Drupal faster •  Use MongoDB (+ MySQL) •  Use Nginx instead of Apache •  Use PHP FastCGI Process Manager •  Use PHP 5.3 •  (Use Drupal 7)

Slide 25

Slide 25 text

Configure Nginx touch /etc/nginx/sites-available/drupal.conf copy config into drupal.conf from: http://wiki.nginx.org/Drupal set fastcgi_pass value to socket from FPM: /var/run/php5-fpm.sock or IP:Port combination: 127.0.0.1:9000

Slide 26

Slide 26 text

Configure Nginx (cont…) Change the root directory ln -s /etc/nginx/sites-available/ drupal.conf /etc/nginx/sites-enabled nginx –t service nginx restart

Slide 27

Slide 27 text

Get Drupal •  Download Drupal into your server directory •  Change ownership to Nginx user (usually www- data) •  Install!

Slide 28

Slide 28 text

Get Drupal cd /var mkdir www cd www wget http://ftp.drupal.org/files/projects/ drupal-7.12.tar.gz tar –xzf drupal-7.12.tar.gz mv drupal-7.12 drupal chown –R www-data:www-data www

Slide 29

Slide 29 text

The solution •  Make Drupal faster •  Use MongoDB (+ MySQL) •  Use Nginx instead of Apache •  Use PHP FastCGI Process Manager •  Use PHP 5.3 •  (Use Drupal 7)

Slide 30

Slide 30 text

MongoDB for Drupal •  Cache •  Field storage •  Session •  Lock •  Watchdog •  Queue •  Blocks •  API http://drupal.org/project/mongodb

Slide 31

Slide 31 text

Usage •  Cache, session, lock, queue and watchdog can be turned on straight away •  Field storage migrates existing content when saved (test) •  Block modules requires some care (test) •  Follow readme.txt instructions (test) •  Bleeding edge (test, test, test)

Slide 32

Slide 32 text

Field Storage Caveats •  Can’t be disabled •  No way to migrate content back to MySQL •  No Views integration AT ALL but •  API is EntityFieldQuery aware…

Slide 33

Slide 33 text

The solution •  Make Drupal faster •  Use MongoDB (+ MySQL) •  Use Nginx instead of Apache •  Use PHP FastCGI Process Manager •  Use PHP 5.3 •  (Use Drupal 7)

Slide 34

Slide 34 text

How long did it take? •  Ate dinner •  Wrote a presentation •  Made a cup of tea •  Checked on my son •  Watched “Shakespeare Wallah” on DVD

Slide 35

Slide 35 text

How long did it take? 1 hour 15 minutes

Slide 36

Slide 36 text

Other things you can do •  Use MySQL replacements – Maria DB – Percona Server •  APC •  Memcache •  Varnish

Slide 37

Slide 37 text

@xtfer Christopher Skene [email protected]