4x High Performance for Drupal Presented by Fabian Franz Step by - - PowerPoint PPT Presentation

4x high performance for drupal
SMART_READER_LITE
LIVE PREVIEW

4x High Performance for Drupal Presented by Fabian Franz Step by - - PowerPoint PPT Presentation

4x High Performance for Drupal Presented by Fabian Franz Step by Step Your BOSS is calling! It happens to the best of us Especially during DrupalCon or during elections. The site goes down, the site is slow, grab a tut,


slide-1
SLIDE 1

4x High Performance for Drupal

Presented by Fabian Franz

Step by Step

slide-2
SLIDE 2

Your BOSS is calling!

slide-3
SLIDE 3

It happens to the best

  • f us …
slide-4
SLIDE 4

Especially during DrupalCon …

slide-5
SLIDE 5

… or during elections.

slide-6
SLIDE 6

The site goes down, the site is slow, grab a tut’, and make it grow!

slide-7
SLIDE 7

But first …

slide-8
SLIDE 8

Lets start with a little story …

slide-9
SLIDE 9

„Where is the power

  • f Drupal ... I hate

Drupal!“

slide-10
SLIDE 10

„... I hate Drupal!“

„[...] and it always overload the database (mysql) some times the load reach 200 and it never reach it before ... I enabled core cache and the server got down again next day ..."

  • groups.drupal.org/node/158244
slide-11
SLIDE 11

My site is so slow ... HEEEEELP!

  • "Where is the power of

Drupal ... I hate Drupal!"

  • This is really sad ...
slide-12
SLIDE 12

My site is so slow ... HEEEEELP!

  • There is a need for High Performance

Drupal!

  • Faster sites earn more money
  • Faster sites get ranked higher by

Google

slide-13
SLIDE 13

My site is so slow ... HEEEEELP!

  • Visitors love fast sites
  • Mentioned in the media? What if your

server goes down exactly then?

slide-14
SLIDE 14

BUT ...

slide-15
SLIDE 15

… THE QUESTION IS …

slide-16
SLIDE 16

How do I get a blazingly fast site?

slide-17
SLIDE 17

Doing it Wrong

slide-18
SLIDE 18

Doing it Wrong

"Okay, I have now tweaked my Sauerkraut* settings, but the site is still slow. What Sauerkraut settings do I need to tweak so that it is as fast as xyz.com?"

* Sauerkraut was APC in this case, but we come to that later
slide-19
SLIDE 19

Doing it Wrong

„I have setup 10 Slave DB Servers, but

  • nce I test the site it is sooo slooooow!“
slide-20
SLIDE 20

Doing it Wrong

„I have setup NGINX with AdvAgg and Varnish combined with Entitycache and Views_Opt_Cache - still the performance remains the same. :-(“

slide-21
SLIDE 21

„Have you setup Memcache?

slide-22
SLIDE 22

???

slide-23
SLIDE 23

Doing it Wrong

“I have setup static page caching for all the pages. The high traffic day can come! What could possibly go wrong?”

slide-24
SLIDE 24

We all wish ...

slide-25
SLIDE 25

... we had ...

slide-26
SLIDE 26

THE MAGIC PILL!

slide-27
SLIDE 27

Optimization is a process

  • not a pill

„Just one pill and the site is fast!“

slide-28
SLIDE 28

Optimization is a process

  • not a pill

4 common ways to fail

  • 1. Optimizing one part to death while

neglecting all the others: "If you build the house on one pillar, it'll not hold long ..."

slide-29
SLIDE 29

Optimization is a process

  • not a pill

4 common ways to fail

  • 2. Optimizing things without knowing

where the pain is: "Is the bottleneck MySQL, PHP, Apache

  • r something else?"
slide-30
SLIDE 30

Optimization is a process

  • not a pill

4 common ways to fail

  • 3. Optimizing things with new methods

without really understanding them: "Reinvent the wheel or stand on the shoulder of giants?""

slide-31
SLIDE 31

Optimization is a process

  • not a pill

4 common ways to fail

  • 4. Optimizing things without testing it'll

hold the load: "You are featured by BigNews.com - Your server goes down."

slide-32
SLIDE 32

4 Common Ways to Fail

  • 1. Optimizing one part to death
  • 2. Optimizing just random parts
  • 3. Optimizing parts with <BuzzWord>
  • 4. Optimizing without testing
slide-33
SLIDE 33

"Ouch, that are lots of ways to fail ..."

slide-34
SLIDE 34

„That is all so complicated.“ *sigh*

slide-35
SLIDE 35

This is all so

  • complicated. *sigh*

"Is there nothing I can do to make this easier and have a fast site?"

slide-36
SLIDE 36

This is all so

  • complicated. *sigh*
  • The easy answer:

Hire a performance consultant.

slide-37
SLIDE 37

„This is all so complicated.“ *sigh* Hire a performance consultant NOW. CALL NOW IN THIS SECOND:

  • and enjoy blazingly fast sites.

0800 - DRUPAL PERFORMANCE

slide-38
SLIDE 38

The End

Now you know Performance is really difficult to get right and that you should hire a Performance Consultant.

Remember this number: 0800 - DRUPAL PERFORMANCE QUESTIONS?

slide-39
SLIDE 39

JUST KIDDING ...

  • Okay, okay. You got me ...

"Hiring a performance consultant can be really useful at times, but even more useful is learning and spreading the knowledge."

slide-40
SLIDE 40

JUST KIDDING ...

4x HIGH PERFORMANCE FOR DRUPAL

  • STEP BY STEP
  • „Lets stand on the shoulders of Giants

and walk the paths of our ancestors!“

slide-41
SLIDE 41

Your Mission

slide-42
SLIDE 42

Loading your mission ...

slide-43
SLIDE 43

The Mission

  • Drupal 7 / 8
  • Several Performance Problems
  • ... real life problems!
slide-44
SLIDE 44

Lets meet some friends …

slide-45
SLIDE 45

… and help them in their need …

slide-46
SLIDE 46

Your Mission

  • D. Pages feel

slow, sluggish and big ... ... and are totally unhappy :-( „This is sooooo heavy load.“

slide-47
SLIDE 47

Your Mission

  • Mrs. MySQL is

exhausted and needs a time

  • ut

:-( *sigh* :-( „I just need a SELECT break.“

slide-48
SLIDE 48

Your Mission

  • Mr. Apache is

sweating under the load :-(( „I give 100% all the time, but this is just too much.“

slide-49
SLIDE 49

Your Mission

  • Mr. Code is

buggy and a real trouble maker ;-) „Yeah! He he he!“

slide-50
SLIDE 50

Your Mission

  • D. Pages feel slow and are unhappy :-(
  • Mrs. MySQL is exhausted and needs a

time out :-(

  • Mr. Apache is sweating under the load

:-((

  • Mr. Code is buggy and a real trouble

maker ;-)

slide-51
SLIDE 51

The Task

  • Investigate

and Fix!

  • Let‘s go!
slide-52
SLIDE 52
  • 1. Server

Performance

slide-53
SLIDE 53

Measuring Server Performance....

slide-54
SLIDE 54

Measuring Server Performance....

  • System Load: 4.14
  • Page Load Time: 20 sec
  • Apache Load: 100%
slide-55
SLIDE 55

How to measure Performance on Server?

  • top command
slide-56
SLIDE 56

How to measure Performance on Server?

  • Handy Drush Command for page

generation time of any page (Drupal 7):

time drush php-eval '
 $path="node/17"; menu_set_active_item($path); menu_execute_active_handler($path, TRUE);' > /dev/null

slide-57
SLIDE 57

Uhm, really?

slide-58
SLIDE 58

Yes!

slide-59
SLIDE 59

Why would I need that?

slide-60
SLIDE 60

Production debugging!

slide-61
SLIDE 61

Sometimes problems

  • nly show up on

production.

slide-62
SLIDE 62

So now we know there is a problem.

slide-63
SLIDE 63

How do we solve them?

slide-64
SLIDE 64

The 4 Shoulders of the Giants

slide-65
SLIDE 65

While I have said …

slide-66
SLIDE 66

…. that you should know your pain points first …

slide-67
SLIDE 67

… there is a “stack”

slide-68
SLIDE 68

…. that many high performance sites use.

slide-69
SLIDE 69

Pressflow / Good code APC / Opcache Varnish / NGINX / CDN Memcache / Redis

slide-70
SLIDE 70

So how can those help me?

slide-71
SLIDE 71

Pressflow

  • Only really relevant for Drupal 6 sites
  • Drupal 7 already includes most

Pressflow patches / approaches

  • Drupal 8 has performance best

practices all around.

slide-72
SLIDE 72

Inofficial Pressflow

  • https://groups.drupal.org/node/

210683 (Wiki)

  • All collected performance patches

that are relevant for Drupal 7.

slide-73
SLIDE 73

APC

  • Alternative PHP Cache
  • Highly recommended (easy to install)
  • PHP PECL Extension
  • Speeds up PHP execution by caching

pre-compiled PHP objects

slide-74
SLIDE 74

Opcache (PHP >= 5.5)

  • Opcode Cache
  • Highly recommended (easy to install)
  • In PHP >=5.5 by default (Yeah!!!)
  • Speeds up PHP execution by caching

pre-compiled PHP objects

slide-75
SLIDE 75

APC: Is it worth it?

slide-76
SLIDE 76

OpCache: Is it worth it?

  • Yes
  • Saves:
  • ~ 100 ms
  • ~ 20 MB
slide-77
SLIDE 77

Memcache

  • Replaces caching in MySQL Database
  • Key/Value Store in Main Memory


store(Apple, 10)
 get(Apple) == 10

  • Very Fast!
slide-78
SLIDE 78

Memcache: What does it get me?

slide-79
SLIDE 79

Memcache: What does it get me?

  • Way less load on the database
  • Overall faster caches
  • Much easier to scale up


( Distributed key-value storage)

slide-80
SLIDE 80

Varnish

  • Save whole response to memory
  • Serve response from memory
  • Like a “shield” for your server
  • Varnish is crucial for high throughput.


(unless you use NGINX)

slide-81
SLIDE 81

Varnish: That sounds pretty complicated!

slide-82
SLIDE 82

Varnish: That sounds pretty complicated!

  • Best practice configurations:
  • https://fourkitchens.atlassian.net/

wiki/display/TECH/Configure+Varnish +3+for+Drupal+7

  • https://www.lullabot.com/blog/article/

configuring-varnish-high-availability- multiple-web-servers

slide-83
SLIDE 83

Varnish: What does it get me?

  • 50 ms response times!
slide-84
SLIDE 84

Your Mission: UPDATE!

slide-85
SLIDE 85

Your Mission: UPDATE!

  • Anonymous Pages: „We are

blazingly fast, still big, but quite happy“.

slide-86
SLIDE 86

Your Mission: UPDATE!

  • Mrs. MySQL: „I have less to do

now, but if I have it is still too

  • much. Those authenticated users

...“

slide-87
SLIDE 87

Your Mission: UPDATE!

  • Mr. Apache: „I have much less to

do, but when those authenticated users come, I still sweat.“

  • „And I hate those anonymous

utm_ requests!“

slide-88
SLIDE 88

Quick Fix for GA Problem

  • VCL (Varnish 2.1.x) Rule:
# Strip out Google Analytics campaign variables.
 # They are only needed by the javascript 
 # running on the page.
 # utm_source, utm_medium, utm_campaign, gclid if(req.url ~ "(\?|&)(gclid|utm_[a-z]+)=") { set req.url = regsuball(req.url, "(gclid|utm_[a-z] +)=[^\&]+&?", ""); set req.url = regsub(req.url, "(\?|&)$", ""); }
slide-89
SLIDE 89
  • 2. Client

Performance

slide-90
SLIDE 90

Measuring Client Performance....

slide-91
SLIDE 91

Measuring Client Performance....

  • Page Load Size: 300 kB
  • Page Load Time: 20 sec
slide-92
SLIDE 92

How to measure Performance on Client?

  • Use Google Chrome

Developer Toolbar

➡Network Tab

slide-93
SLIDE 93

How to measure Performance on Client?

  • http://

webpagetest.org

slide-94
SLIDE 94

Why are those pages so big?

slide-95
SLIDE 95

Need Compression of CSS and JS!

slide-96
SLIDE 96

Compression of CSS and JS

  • Very easy to setup
  • In Drupal 7 Core:
  • Administration Menu

➡Configuration ➡Development ➡Performance

slide-97
SLIDE 97

Compression of CSS and JS

  • Very easy to setup
  • In Drupal 8 Core:
  • Enabled by default!
slide-98
SLIDE 98

Compression of CSS and JS

  • Aggregation and

Compression

  • Do this before Go-

Live!

  • Users will thank you

for it!

  • Needs: mod_rewrite

and mod_headers

slide-99
SLIDE 99

Compression of CSS and JS (Drupal 6)

  • Can be also done in Apache (e.g.)
  • mod_deflate
  • But: Can put high load on the server!

✓Combine with: Varnish

slide-100
SLIDE 100

Minimize CSS and JS source files!

slide-101
SLIDE 101

AdvAgg (Drupal 7)

  • => Way less

aggregates

slide-102
SLIDE 102

Set proper caching headers

slide-103
SLIDE 103

Set proper caching headers

  • Goal: Cache for some

time on Client machine

  • Drupal 7 sets the

headers for you

  • Just need to adjust

the numbers.

slide-104
SLIDE 104

Client Performance: What did we achieve?

  • Only 4 HTTP requests.
  • Much faster page load time.
slide-105
SLIDE 105

Your Mission: UPDATE!

slide-106
SLIDE 106

Your Mission: UPDATE!

✓Anonymous Pages: „We are

blazingly fast, really slick, and really really happy :-)“.

slide-107
SLIDE 107

Your Mission: UPDATE!

  • Anonymous Pages: „We are

blazingly fast, really slick, and really really happy :-)“.

slide-108
SLIDE 108

Additional techniques

  • CDN: Content

Delivery Network

  • Caches files close to

the users location

  • Useful for images, CSS

/ JS files

  • http://drupal.org/

project/cdn

slide-109
SLIDE 109

Additional techniques

  • AJAX/PJAX: Only re-

load the content you need

  • Useful for pagers,

image galleries

  • http://drupal.org/

project/pjax

slide-110
SLIDE 110

Quick-Tip: Fix slow JS!

  • Unresponsive script error on loading
  • f page?
  • Workaround -- Wrap Code in:



 setTimeout(function() {
 // Old code
 }, 100);

slide-111
SLIDE 111
  • 3. Module

Performance

slide-112
SLIDE 112

Measuring Module Performance....

slide-113
SLIDE 113

Measuring Module Performance....

  • Drupal Bootstrap: 240 ms
  • menu_execute_active_handler: 6 sec
  • Memory Usage: 104 MB
slide-114
SLIDE 114

How to measure Module Performance?

  • Use xhprof PHP

extension

  • Integration via

xhprof module

➡admin/config/

development/devel

slide-115
SLIDE 115

How to measure Module Performance?

  • Use github.com/

LionsAd/xhprof-kit

  • Setup via ./xhprof-

kit/setup.sh

➡/index-perf.php?url=/

node

slide-116
SLIDE 116

Common Pitfalls

slide-117
SLIDE 117

Common Pitfalls

  • variable_set on each page request
  • ➡Can bring your DB server to its knees!
slide-118
SLIDE 118

Common Pitfalls

  • Anonymous $SESSION set for saving

simple data

  • Example: low_bw flag

➡Disables anonymous caching ➡Solution: Use Javascript to set/receive

cookies directly and change page.

slide-119
SLIDE 119

Common Pitfalls

  • Having installed way

toooooooooooooooooooooooooooo many modules

➡Adds a little to the page request every

  • time. (Drupal 6: worse)
slide-120
SLIDE 120

Interesting Pitfalls

  • views loading 5000 nodes in one page

request for openlayers

  • ➡Can easily exceed memory and takes

quite some time to attach fields.

➡Adv. Solution:

  • penlayers_quick_query sandbox
slide-121
SLIDE 121

Improve performance

  • Use block caching
  • Use render caching

(render_cache module)

slide-122
SLIDE 122

Improve performance

  • Use

blockcache_alter module

➡Lots of more

  • pportunities for

caching then by default

slide-123
SLIDE 123

Improve performance

  • Setup views caching
  • Setup panels caching
  • => Click those

checkboxes and see what is acceptable for your users!

slide-124
SLIDE 124

Module Performance: What did we achieve?

  • We found the bad code and removed

it!

  • Page is much faster now!
slide-125
SLIDE 125

Your Mission: UPDATE!

slide-126
SLIDE 126

Your Mission: UPDATE!

  • Mrs. MySQL: Almost Happy. She

feels still kinda slow sometimes

✓Apache: Really happy! ✓D. Pages: Really Happy!

slide-127
SLIDE 127
  • 4. Database

Performance

slide-128
SLIDE 128

Measuring MySQL Performance....

slide-129
SLIDE 129

Measuring MySQL Performance....

  • Slow SQL Query: 10 sec
slide-130
SLIDE 130

Measuring MySQL Performance....

  • Tip: Use Percona’s mysql slow query

log analyzer

  • https://www.percona.com/doc/

percona-toolkit/2.2/pt-query- digest.html

slide-131
SLIDE 131

How to measure MySQL Performance?

  • Enable slow query log
  • dbtuner module (6.x
  • nly) / mysqltuner

script for 7.x

  • EXPLAIN queries
slide-132
SLIDE 132

Common Tweaks

slide-133
SLIDE 133

Common Tweaks

  • Use Inno DB
  • ✓Default: Most current MySQL

configuratios

slide-134
SLIDE 134

Common Tweaks

  • Be aware of the barrier!
  • nobarrier=1 for ext3/ext4 file systems
  • Newer Linux kernels / Ubuntu
  • Many many threads by Developers
slide-135
SLIDE 135

Common Tweaks

  • Be aware of the barrier!

➡Attention: Needs to be used with

special hardware for production usage.

➡Useful Guide: Red Hat Handbook

slide-136
SLIDE 136

Common Tweaks

  • Use XFS file system
  • Good and proven file system for

MySQL databases

  • Size appropriately to the use-case
slide-137
SLIDE 137

Fix Slow Queries

  • EXPLAIN queries

✓Add indexes where necessary

  • Run EXPLAIN again
slide-138
SLIDE 138

MySQL Performance: What did we achieve?

  • No more slow queries! (YEAH!)
slide-139
SLIDE 139

Your Mission: UPDATE!

slide-140
SLIDE 140

Werbung / Commercials

slide-141
SLIDE 141

Recap: Best Practices

slide-142
SLIDE 142

Best Practices

  • Setup Base Performance
slide-143
SLIDE 143

Best Practices

  • You want to have your own



 „High Performance Stack“

slide-144
SLIDE 144

Best Practices

  • Having your own stack is not

difficult ...

  • ... as you have seen
slide-145
SLIDE 145

Best Practices

  • Analyze Pain Points first
slide-146
SLIDE 146

Where is the problem?

  • Server based?
  • Client based?
  • Modules?
  • Database?
slide-147
SLIDE 147

Best Practices

  • Optimize Pain Points
slide-148
SLIDE 148

Your Mission: UPDATE!

slide-149
SLIDE 149

Your Mission: UPDATE!

✓Mrs. MySQL: Very Happy! ✓Apache: Really happy! ✓D. Pages: Really Happy!

slide-150
SLIDE 150

Mission: Completed!

Wake up, Neo!

slide-151
SLIDE 151

QUESTIONS?

slide-152
SLIDE 152

FOLLOW ME!

  • Fabian Franz
  • @Fabianx
  • twitter: @fabianfranz
  • github: LionsAd
  • Tag1 Consulting