Top Banner
Sherif Ramadan PHP Performance At Scale
46
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Php performance-talk

Sherif Ramadan

PHP Performance At

Scale

Page 2: Php performance-talk

What is performance?A factor of efficiently producing output.

Finite resources must serve infinite needs.

Page 3: Php performance-talk

What is scale?A quantitative measure of need.

Dealing with sheer numbers of inputs and outputs.

Page 4: Php performance-talk

First, let’s clear up some preconceived notions

about PHP…

Page 5: Php performance-talk

Why does PHP have a bad wrap?

Page 6: Php performance-talk

“PHP can run really bad code really well” - Rasmus Lerdorf

“1” + 1 == 2

Page 7: Php performance-talk

function argument order…!!

array_map(<callback>, <array>) array_filter(<array>, <callback>)

Page 8: Php performance-talk

type juggling behavior!!

md5('240610708') == md5('QNKCDZO')

“0e462097431906509019562988736854" "0e830400451993494058024219903391"

Page 9: Php performance-talk

Bueller? Bueller? Anyone?Popularity has its price…

Page 10: Php performance-talk

We’re going back to 1995!

Page 11: Php performance-talk

The First PHPAnnouncing the Personal Home Page Tools (PHP Tools) version 1.0. These tools are a set of small tight cgi binaries written in C. They perform a number of functions including: . Logging accesses to your pages in your own private log files. Real-time viewing of log information. Providing a nice interface to this log information. Displaying last access information right on your pages. Full daily and total access counters. Banning access to users based on their domain. Password protecting pages based on users' domains. Tracking accesses ** based on users' e-mail addresses **. Tracking referring URL's - HTTP_REFERER support. Performing server-side includes without needing server support for it . Ability to not log accesses from certain domains (ie. your own) . Easily create and display forms. Ability to use form information in following documentsHere is what you don't need to use these tools:

. You do not need root access - install in your ~/public_html dir

. You do not need server-side includes enabled in your server

. You do not need access to Perl or Tcl or any other script interpreter

. You do not need access to the httpd log files The only requirement for these tools to work is that you have the ability to execute your own cgi programs. Ask your system administrator if you are not sure what this means. The tools also allow you to implement a guestbook or any otherform that needs to write information and display it to userslater in about 2 minutes.The tools are in the public domain distributed under the GNUPublic License. Yes, that means they are free!

For a complete demonstration of these tools, point your browserat: http://www.io.org/~rasmus --

Rasmus [email protected]://www.io.org/~ras

Page 12: Php performance-talk

Why do we care about performance?

Page 13: Php performance-talk

We Live In An Information Age

Page 14: Php performance-talk

More people; more data;

more time online!

Page 15: Php performance-talk

Lots of Data!!!Cisco predicts annual data transfer of a zettabyte by 2016!

Page 16: Php performance-talk

Impactful change is fundamentally disruptive…

Page 17: Php performance-talk

SELECT * FROM table LIMIT 10; !

Thank PHP!

Page 18: Php performance-talk

How do I improve performance?

Page 19: Php performance-talk

It depends…

Page 20: Php performance-talk

What matters to you?

Page 21: Php performance-talk

Factors of Performance

• Economics

• Luxury

• Speed

Page 22: Php performance-talk

Economy?

• Goes 0 - 60 (MPH) > 10 Seconds

• Does ~50 MPG

• Costs ~$24K

Page 23: Php performance-talk

Luxury?• Goes 0 - 60 (MPH) < 4 Seconds

• Does ~14 MPG

• Costs ~$200K

Page 24: Php performance-talk

Speed?

• Goes 0 - 60 (MPH) < 2 Seconds

• Does 3.1 MPG

• Costs ~$2.6 Million

Page 25: Php performance-talk

All of The Above?• Goes 0 - 60 (MPH) < 6 Seconds

• Uses ~85KwH (320 Servers)

• Costs ~$79K

Page 26: Php performance-talk

Architecture

Page 27: Php performance-talk

–Rasmus Lerdorf

“Scaling something up is hard. Scaling something down is even harder. Both are rocket

science.”

Page 28: Php performance-talk

PHP ScalePHP scales up as well as it scales down!

Page 29: Php performance-talk

Load Balancing

Page 30: Php performance-talk

PHP-FPM > mod_php?

Page 31: Php performance-talk

Distributing Load Properly

Page 32: Php performance-talk

Offloading - Gearman

Page 33: Php performance-talk

Offloading - Gearman

Page 34: Php performance-talk

Offloading - ZeroMQ

Page 35: Php performance-talk

Service Discovery with Zookeeper

Page 36: Php performance-talk

APC Cache vs Memcached

Page 37: Php performance-talk

Atomic Operations++

Page 38: Php performance-talk

Vectors

Page 39: Php performance-talk

PHP Arrays

Page 40: Php performance-talk

Implementation

Page 41: Php performance-talk

Present Day PHP Implementations

• C PHP (Defacto Standard)

• HHVM

• HipHop PHP

• Phalanger

• PHPPHP

Page 42: Php performance-talk

PHP 7Zend Engine 3.0

The Future of PHP

Page 43: Php performance-talk

PHP-NG

Page 44: Php performance-talk

PHP-NG

Page 45: Php performance-talk

PHP-NG

Page 46: Php performance-talk

Sherif Ramadan@sr_googleguy

sheriframadan.com

Thank You! !

Q&A