drupal performance optimization best practices

26
Drupal Performance Optimization Best Practices July 4, 2014 Ratnesh Kumar

Upload: ratnesh-tiwari

Post on 08-Sep-2014

214 views

Category:

Technology


0 download

DESCRIPTION

Drupal Performance Optimization best practices and list of tools/techniques.

TRANSCRIPT

Page 1: Drupal performance optimization Best Practices

Drupal Performance OptimizationBest Practices

July 4, 2014Ratnesh Kumar

Page 2: Drupal performance optimization Best Practices

2

Overview

• Drupal Performance

• Know the tools for performance Analysis

• Best Practices for Performance Optimization– Application Level– Server Configuration– Database Configuration

• Common mistakes which causes Performance bottlenecks

Page 3: Drupal performance optimization Best Practices

Drupal Performance

• Performance bottlenecks is a major issue with Drupal based application

• Common understanding among people, product stakeholders and web developers is:

Drupal is not a right choice for large application with lot of users and content.

It consumes lot of memory and resources.

3

Page 4: Drupal performance optimization Best Practices

4

Drupal Performance

Why Drupal is Slow?

• Because it’s not configured/deployed correctly… • Contents are dynamic not static.• Bootstrap process is complex where series of events occurs behind the scene:

Establishing a database connection Loading all settings and modules Initializing a user session Mapping the URL to page callback Render the Page (theme initialization)

On every single page request all the above events occurs in backend.

Page 5: Drupal performance optimization Best Practices

5

Drupal Performance

When do you think about performance? (Before/After Development)

Discuss and freeze the performance related NFRs carefully under requirement document, before starting the development. Set a goal for performance which needs to be achieved. Finalize Caching strategies.

Page 6: Drupal performance optimization Best Practices

Tools for performance Analysis

Page 7: Drupal performance optimization Best Practices

6

Tools for performance Analysis

www.webpagetest.org

Google pageSpeed (Chrome add ons)

Yslow (Firefox add ons)

Apache Benchmarking

www.whichloadfaster.com (compare with other sites)

Drupal module – Devel

top/htop ……. and lots more

Page 8: Drupal performance optimization Best Practices

Best Practices - Application Level

Page 9: Drupal performance optimization Best Practices

7

Best Practices - Application Level

Disable and Delete unused and non-essential modules

Disable the Update Manager module on Production.

Database logging (dblog) is enabled by default in Drupal 7, and errors can fill up your database quickly.

A better solution is to fix all PHP notices and warnings to reduce logging overhead.

Page 10: Drupal performance optimization Best Practices

8

Best Practices - Application Level

Put JS at the bottom of the page.

Custom JS/CSS should be added in the application only using drupal_add_js() and drupal_add_css() function respectively.

Aggregate and minify JS/CSS file through Drupal Admin.

Use the Fast 404 module to serve static 404s for image, icon, CSS, or other static files, rather than bootstrapping Drupal.

Page 11: Drupal performance optimization Best Practices

Best Practices – Server Configuration

Page 12: Drupal performance optimization Best Practices

9

Best Practices – Server Configuration

Cache PHP with APC(Alternative PHP cache)

Cache everything to reduce the page load time for anonymous user (Boost, Memcache/Varnish).

Page 13: Drupal performance optimization Best Practices

10

Best Practices – Server Configuration

Configure CRON to be executed at a certain timestamp in a day, instead of executing this on every request. Drupal executes cron hook on every page request.

CDN Integration – to store all static files e.g. css, js and images.

Leverage browser caching

Optimize images to reduce the total page size.

Page 14: Drupal performance optimization Best Practices

11

Best Practices – Server Configuration Boost + Memcache – Works best in most of the case as it solves performance issue for anonymous and authenticated user both

Boost provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic

Precache everything through warmup script Use cache-expire module to update cache on node insert/update/detele.

Page 15: Drupal performance optimization Best Practices

12

Best Practices – Server Configuration

Page 16: Drupal performance optimization Best Practices

13

Best Practices – Server Configuration

• Memcache You can use the Memcache module to move some common cache queries out of the database and into memory. Information held in memory will always be retrieved more quickly than information retrieved from a database query.

• APC (Alternative PHP Cache) PHP is an interpreted language, which means the files have to be reduced down into opcodes in order to actually be executed by the server. Once APC is installed on the server and configured, it will store the intermediate code of PHP files in memory so that every request does not result in fetching all those PHP files off disk and interpreting the files every time.

Page 17: Drupal performance optimization Best Practices

14

Best Practices – Server Configuration

• Integrate CDN to store all static files(JS/Images/CSS)

A content delivery network (CDN) is a collection of web servers distributed across multiple locations to deliver content more efficiently to users. The server selected for delivering content to a specific user is typically based on a measure of network proximity.

Page 18: Drupal performance optimization Best Practices

15

Best Practices – Server Configuration

• Leverage Brower Caching What browser caching does:

“Remember" the resources that the browser has already loaded. When a visitor goes to another page on your website your logo or CSS file does not need to be loaded again, because the browser has them "remembered". The end result is that your pages load much faster.

Browser caching can be enabled with few configuration added in the .htaccess file on the server.

• Set expiry time of static contents<IfModule mod_expires.c> # Enable expirations. ExpiresActive On ExpiresByType image/jpg "access 1 month"

Page 19: Drupal performance optimization Best Practices

16

Best Practices – Server Configuration

• Leverage Brower Caching• Set max-age header

<FilesMatch "(\.js\.gz|\.css\.gz)$"> Header set Cache-Control "max-age=2678400, public" ExpiresActive On ExpiresDefault "access plus 1 month“

Requirements:• mod_expire and mod_header modules needs to be installed and enabled on the server(Apache).

Page 20: Drupal performance optimization Best Practices

17

Best Practices – Server Configuration

• CRON Configuration

Misconfiguration of CRON settings results into major performance issue as Drupal executes all the cron hooks on every single page request by default.

Configure CRON to be executed at a certain timestamp in a day

Elysia cron module works perfectly for configuring cron.

It extends Drupal standard cron, allowing a fine grain control over each task and several ways to add custom cron jobs to your site.

Page 21: Drupal performance optimization Best Practices

18

Best Practices – Server Configuration

• CRON Configuration

Configuration on Server side: Connect to server through ssh Login as root user (sudo su) Command to view/edit crontab file

crontab –l (to view the list of cron script configured on the server) crontab –e (opens the crontab configuration)

Add the below line to excute the cron at 2:10 AM daily 10 2 * * * /usr/bin/wget -O - -q -t 1

http://www.createdbespoke.com/sites/all/modules/community/elysia_cron/cron.php?cron_key=sfaslsfklsfjlksfjlfsaf

Save the file and quit – wq

Page 22: Drupal performance optimization Best Practices

Best Practices – Database

Page 23: Drupal performance optimization Best Practices

19

Best Practices – Database

Do not use InnoDB for the semaphore table, use Memory ALTER TABLE semaphore ENGINE=MEMORY;

innodb_buffer_pool_size 70-80% of memory is a safe bet. I set it to 12G on 16GB box.

innodb_log_file_size – This depends on your recovery speed needs but 256M seems to be a good balance between reasonable recovery time and good performance

innodb_log_buffer_size=4M is good for most cases unless you’re piping large blobs to Innodb in this case increase it a bit.

Page 24: Drupal performance optimization Best Practices

20

Best Practices – Database

Enable MySQL query cache (i.e. query_cache_size)

Find Slow query through slow query log file.

Create indexes to optimize the query

Page 25: Drupal performance optimization Best Practices

20

Questions?

Questions?

Page 26: Drupal performance optimization Best Practices

20

Thanks…