+ All Categories
Home > Documents > Practical Performance Tuning and...

Practical Performance Tuning and...

Date post: 22-Sep-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
46
Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter Three Saturday, November 19, 2011
Transcript
Page 1: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Practical Performance Tuning and Testing

Nick LewisSenior Dev, Chapter Three

Saturday, November 19, 2011

Page 2: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

I love to talk about myself

• Worked with the Drupal since version 4.4

• Accidental Programmer

• Nick Lewis: The blog

• Former Austinite; Kidnapped by Chapter 3.

• I am not @drupaltruth. I will make no further comments on such baseless rumors

Saturday, November 19, 2011

Page 3: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Performance Tuning...

• Not a science

• Not a strict process

• Easy to pick up

• Hard to master

Saturday, November 19, 2011

Page 4: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Performance tuning is sort of like medicine• Diagnosis comes before

treatment

• Aim to treat the root cause

• Gestaltish

• Run tests to gauge success

Saturday, November 19, 2011

Page 5: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

It’s also like detective work

• Sometimes, the beginning feels like a murder scene

• Trust and follow vague hunches

• Make note of anything “odd.”

Saturday, November 19, 2011

Page 6: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

It’s also like being an airline pilot

• Be present at all times.

• In emergencies, its essential you stay calm and focused.

• Failure means the plane crashes into the mount.

Saturday, November 19, 2011

Page 7: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

And of course, you’ll feel like him at times

I can’t change the limits of your

crappy godaddy server.

Saturday, November 19, 2011

Page 8: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

The Patient

• Site get’s tons of traffic ( > 200,000 an hour during spikes)

• 250,000 nodes

• Server frequently crashes

• Built by an outsourced firm

• Client thinks Drupal is to blame

Saturday, November 19, 2011

Page 9: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

The Plot Twist

• Varnish running? Check.

• Memcache running? Check.

• Have they turned on the (insert whatever name you’re thinking) cache? Yep.

Saturday, November 19, 2011

Page 10: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Just add more web nodes.

Switch to nginx, idiot.

MongoDB!

Saturday, November 19, 2011

Page 11: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

FEAR THE STAMPEDE

Saturday, November 19, 2011

Page 12: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

BAD PERFORMANCE IS USUALLY DUE TO

BAD PRACTICE

Saturday, November 19, 2011

Page 13: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Turn on the lights

• Create a cache free test environment.

• Seriously, turn query cache, and APC off.

• We’ll test the performance of our cache later...

Saturday, November 19, 2011

Page 14: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Test 1: MySQL• Include all public page types, e.g. taxonomy,

front, node in a file

• Wimpy siege test: siege -c 1

• Observe queries:mysql -u root -proot show processlist;

• Parse yer slow slow query log with maatkit ~/mk-query-digest /path/to/log/slow.log

Saturday, November 19, 2011

Page 15: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

We’ll do it live!

$ siege -c 1

Saturday, November 19, 2011

Page 16: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

That query is bad, m’kay

SELECT n.title,c.totalcount FROM node n LEFT JOIN node_counter c ON n.nid = c.nid ORDER BY c.totalcount DESCLIMIT 0,5

Saturday, November 19, 2011

Page 17: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

SELECT n.title,c.totalcount FROM node n INNER JOIN node_counter c ON n.nid = c.nid ORDER BY totalcount DESC

That query is good.

Saturday, November 19, 2011

Page 18: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

SELECT n.title,c.totalcount FROM node n LEFT JOIN node_counter c ON n.nid = c.nidWHERE c.totalcount > 4000ORDER BY c.totalcount DESC

That query isn’t badIt will work.

Saturday, November 19, 2011

Page 19: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

SELECT n.title,c.totalcount FROM node n LEFT JOIN node_counter c ON n.nid = c.nidWHERE c.totalcount > 4000ORDER BY c.totalcount DESC

That query isn’t badIt will work.

Saturday, November 19, 2011

Page 20: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

In a Nutshell...

• EXPLAIN will explain slow queries

• Make sure your selects are using keys.

• Avoid tmp tables at all cost!

• Use maatkit mk-query-digest to parse giant query logs

Saturday, November 19, 2011

Page 21: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

$ siege -c 1000!!!Saturday, November 19, 2011

Page 22: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Safe Load Testing

• Gradually bump -c levels

• Observe server using htop or top

• Know your load limit

• Generally, load of 1.0 is when the test is over, and you should get back to optimizing.

Saturday, November 19, 2011

Page 23: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

WE’LL DO IT LIVE!

$ siege -c 3$ siege -c 5$ siege -c 8$ siege -c 10$ siege -c 12

Limit hit.

Saturday, November 19, 2011

Page 24: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

What did we learn?

• Our MySQL fix made a HUGE impact!

• Something’s up with taxonomy/term pages

• Our new limit is 12 before server overloads.

• MySQL isn’t overloaded, the apache process is.

Saturday, November 19, 2011

Page 25: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Captain Obvious says

PHP just became a suspect.

Saturday, November 19, 2011

Page 26: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

XHProf

• Built by facebook

• Not terribly easy to install, but totally worth it.

• There is a session devoted entirely to XHProf tomorrow.

Saturday, November 19, 2011

Page 27: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

I’LL PROFILE IT. AND WE’LL

DO IT LIVE.

Saturday, November 19, 2011

Page 28: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Captain Obvious says:

I think we found our man.

Saturday, November 19, 2011

Page 29: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Cache it?

Nah dude, he said optimize firstcache later.

Memcache it.

Saturday, November 19, 2011

Page 30: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

WE’RE DOING IT LIVE!$. siege -c 12 (old limit)$.siege -c 20 (new limit)

FORGET TO TURN OFF XHPROF AND THE MACBOOK

DIES

Saturday, November 19, 2011

Page 31: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Let’s Review

• The cache worked. We’ve nearly doubled our -c limit (GOOD!)

• We weren’t able to optimize our function because of a 3rd party (We’ll deal with it)

• PHP is still the bottle neck. Let’s go back to profiling.

Saturday, November 19, 2011

Page 32: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Captain Obvious says:

Drupal, panels, and views are

now all suspects.

Saturday, November 19, 2011

Page 33: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

This is a major milestone

• No slow queries.

• No out of control PHP processes

• In short, nothing glaringly wrong.

Saturday, November 19, 2011

Page 34: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

• APC reduces PHP overhead

• APC some claim good to use for cache tables that have small amounts of records, and change infrequently (e.g. cache, cache_bootstrap, cache_menu)

Time for APC

Saturday, November 19, 2011

Page 35: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

$conf['cache_backends'][] = 'sites/all/modules/apc/drupal_apc_cache.inc';$conf['cache_class_cache'] = 'DrupalAPCCache';$conf['cache_class_cache_bootstrap'] = 'DrupalAPCCache';

settings.php

php.incextension=apc.so

WE’LL DO IT LIVE!

Saturday, November 19, 2011

Page 36: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

I dunno, seemed okay.

You suck.

Memcache it.

Saturday, November 19, 2011

Page 37: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

• Remember to check apc.php to make sure you have room

• apc.shm_size = 64

• apc.stat = 0

• Let’s try again

The first rule of APC: Don’t talk about

settings.

Saturday, November 19, 2011

Page 38: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

• APC has significantly stabilized performance.

• Not a magic bullet

• We’ll want to keep an eye on it, and possibly assign more cache tables

What’s the verdict?

Saturday, November 19, 2011

Page 39: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

• Memcache is good for storing things that change frequently.

• Very effective when used in conjection with APC

Memcache

Saturday, November 19, 2011

Page 40: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

include_once('./includes/cache.inc');include_once('./sites/all/modules/memcache/memcache.inc');$conf['cache_default_class'] = 'MemCacheDrupal';

settings.php

php.incextension=memcache.so

DOING IT LIVE!

Saturday, November 19, 2011

Page 41: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

30x60x60x24 = 2,592,000 daily

Isn’t 30 uncached hits a second a lot?

We’re done. Can we go?

Saturday, November 19, 2011

Page 42: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

We are not done.

Saturday, November 19, 2011

Page 43: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

What was wrong with our test?

• A real page request will ask apache for 10 files (images, etc).

• Real traffic tends to follow not random patterns.

Saturday, November 19, 2011

Page 44: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

Further Optimization Strategies

• Panels or views cache on short time

• Develop “smart” panels cache plugins.

Saturday, November 19, 2011

Page 45: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

The Future!

• Queue API

• Edge side includes

• Context based caching system

Saturday, November 19, 2011

Page 46: Practical Performance Tuning and Testingnicklewis.org/sites/default/files/practicalperformancetuning.pdf · Practical Performance Tuning and Testing Nick Lewis Senior Dev, Chapter

The Future!

• Queue API

• Edge side includes

• Context based caching system

Can you show that graph again? That was awesome.

I propose that server tuning could have solved everything.

Your session in one word:I wish i knew about nginx

Saturday, November 19, 2011


Recommended