The Definition Of Crazy Insanity Chris Porter D.O netw3rker [email protected].

34
The Definition Of Crazy Insanity Chris Porter D.O netw3rker [email protected]

Transcript of The Definition Of Crazy Insanity Chris Porter D.O netw3rker [email protected].

Page 1: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

The Definition Of Crazy Insanity

Chris PorterD.O netw3rker

[email protected]

Page 2: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Who is this guy?

Chris Porter - [email protected] Consultant – Acquia8 years of Drupal Experience4.5yrs Professional Services

Doesn’t learn from mistakes

Page 3: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Level 1: PHP is Crazy

Page 4: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Nervous?

Q: How many files does a single freshly installed Drupal page include? A: ~80 files

Q: How many files does my current client’s “events” page include? A: 2830* (well, actually it was ~680)

Page 5: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

CRAZY: What about 1000 requests?

How many times did PHP meet the definition of insane? Crazy = includes * (requests - 1)• Stock Drupal: 79,920• My Client: 2,150,000 (!!!!)

Actual traffic pattern for that client:3MM page views per month! 100K per day!

Page 6: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Crazy Medicine: PHP OPCode Caching

Opcode Caching is hands down the:• Easiest• Fastest• Most over-lookedSingle performance improvement you can make.It makes the PHP engine *not crazy*

Page 7: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

OPCode Caching

• Caches the pseudo compiled version of a file

• Caches the filesystem permissions

• Stores the cache in memory• Shares the memory with other

PHP processes• Some even provide fast acting

data memory space

Page 8: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Use APC – Its Easy

1) Install APC2) Add the following lines to

your php.ini file

extension=apc.soapc.enabled=1apc.shm_segments=1apc.shm_size=64apc.stat=0

3) Drink a beer

More Detail at: https://drupal.org/node/1777090

Page 9: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

This Means its working!

Page 10: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

10

APC Magic in Action50s!

15s!

APC Configuration Applied

Local doc root fix

300ms

Page 11: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Level 2:Your code

What you are probably doing that is totally bonkers.

Page 12: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

We’ve all done this at least once

*This is not real code, I made it up entirely

Page 13: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Lets break it down:

1 request results in: 1 db query+ 100 service calls

1000 requests results in: 1000 db queries 100,000 service calls

That’s a lot of crazy: about 99,900 to be exact.

Page 14: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

The Cure

Try Drupal’s Cache APIhttps://api.drupal.org/api/drupal/includes%21cache.inc/7

Use the functions: cache_get() and cache_set()If you like data organization, implement your own cache table!

Page 15: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Infrequent updates? Cache the

whole thing!

Page 16: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Now who’s crazy?

• 1 request = 100 webservice calls• 1,000 requests = 100 webservice calls• 1,000,000 requests = 100 webservice calls• No more crazy here!

Page 17: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Level 3: Drupal

How you are configuring Drupal to be crazy

Page 18: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Mass Delusion: You are making all of your users crazy

Max simultaneous requests time gap

Page 19: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Substantially reduce client requests

Page 20: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Views Caching

• Views Caching

Page 21: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Panels Caching

• Panels Caching

Page 22: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Page Caching

• Page Caching

Page 23: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Level 4: Your Webserver

Your webserver is acting crazier than you think. It probably has a gnarly case of OCD.

Page 24: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

100 pages and 1,000,000 requests

Q: How many times did Drupal “bootstrap”?A: 1,000,000 (at least)

Q: What’s the definition of crazy here?A: Requests – Pages = CRAZY

Your webserver was crazy 999,900 times!

Page 25: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

OCD Training: Front-end Caching

Things to consider about front end caches:

• Provide extremely fast content delivery• Take Drupal out of the equation for almost all

requests.• Only works for anonymous users* (mostly)

Page 26: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

OCD Meds: Varnish

• Install Varnish (*nix only)• Read Lullabot’s amazing varnish tutorial• Use Lullabot’s pre-written “high availability

VCL”• Get Drupal’s Varnish Module• Configure Drupal’s page cache options.• Wonder where your server load went

Page 27: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Level 5: Your Infrastructure

Your network is delivering the same content over and over again for no other reason than because it can.

Your network needs a Quaalude.

Page 28: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Deep thoughts:

What happens if your servers network goes down?What happens if your systems fail? (it happens)Why should users in Japan get content delivered from Colorado?

Ever wonder why websites say “server down” on one page, but not another?

Page 29: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

CDN’s to the rescue

Content Delivery Networks distribute your content around the world.Main modes of operation:• Reverse Proxy – point your DNS at them, let

the magic happen.• File Server – put static assets such as images

up on the CDN– serve fewer requests.

Page 30: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Pro’s• Rapidly scale your anonymous content globally• Deliver content in very short routes to consumers• Reduce the load on your serverCon’s• You pay by the byte of data• Do it wrong, and you’ll pay for 2x the bytes of

data• Clearing the cache can take a whileNotes:• Somewhere around 150 endpoints to deal with

Page 31: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Checking out

You just made the front page of:• Reddit• Slashdot• Drudge report

Are you still crazy?

Page 32: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Calming Meds: Expected Traffic

• The CDN will server all of that traffic except:100 pages * 150 endpoints = 15,000 requests.

• Varnish will server all previously served page requests:15,000 – 100 unique pages = 4,900 requests

• Drupal will bootstrap: 100 times

• PHP will include: 698 files[SANE]

Page 33: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

Summary: Main problem areas

• PHP – Lack of Opcode Caching• Code – Cache things you should only do once• Webserver – Use Compression• Cluster – Use reverse proxy caching• Cloud – Use a CDN

Page 34: The Definition Of Crazy Insanity Chris Porter D.O netw3rker Chris.porter@acquia.com.

That’s It!

Questions?

Resources:• Lullabot’s Varnish Writuphttp

://www.lullabot.com/blog/article/configuring-varnish-high-availability-multiple-web-servers

• Configure APC for Drupal: https://drupal.org/node/1777090• CDN Discussions: http://wimleers.com/article/key-properties-of-a-cdn• Drupal Cache API: https://api.drupal.org/api/drupal/includes%21cache.inc/7• Drupal Performance Tips:

http://www.achieveinternet.com/enterprise-drupal-blogs/enterprise-drupal-performance-caching-hosting/5-things-you-can-do-improve-performance-and-scal