high performance social networking applications php mysql

Upload: sareeee

Post on 04-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    1/131

    !"#$%'()*#+(,-.$/#+*0#,-$1#-2

    !

    Writing a socialapplication in PHP/

    MySQLand what happens when amillion people show up on

    opening day

    Duleepa Dups WijayawardhanaMySQL Community Team

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    2/131

    Who the hell am I?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    3/131

    Who the hell am I?

    PHP/MySQL Developer since 1999/2000

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    4/131

    Who the hell am I?

    PHP/MySQL Developer since 1999/2000 MySQL Community Relations Manager in

    North America since... oh... last week :)

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    5/131

    Who the hell am I?

    PHP/MySQL Developer since 1999/2000 MySQL Community Relations Manager in

    North America since... oh... last week :)

    Web Developer for MySQL

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    6/131

    Who the hell am I?

    PHP/MySQL Developer since 1999/2000 MySQL Community Relations Manager in

    North America since... oh... last week :)

    Web Developer for MySQL Various positions at BioWare Corp.

    2001-2007

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    7/131

    Who the hell am I?

    PHP/MySQL Developer since 1999/2000 MySQL Community Relations Manager in

    North America since... oh... last week :)

    Web Developer for MySQL Various positions at BioWare Corp.

    2001-2007

    Also run the Annual St. Patricks Day DrunkDial (http://www.stpatsdrunkdial.com)

    http://www.stpatsdrunkdial.com/http://www.stpatsdrunkdial.com/http://www.stpatsdrunkdial.com/http://www.stpatsdrunkdial.com/
  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    8/131

    What makes me qualified?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    9/131

    Spent a lot of time screaming at Murphy.

    What makes me qualified?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    10/131

    Spent a lot of time screaming at Murphy. Hired by BioWare to help create the

    BioWare Community Site for Neverwinter

    Nights (launched June 2002)

    What makes me qualified?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    11/131

    Spent a lot of time screaming at Murphy. Hired by BioWare to help create the

    BioWare Community Site for Neverwinter

    Nights (launched June 2002)

    Had no clue what to expect, but the rest asthey say now is history.

    What makes me qualified?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    12/131

    Spent a lot of time screaming at Murphy. Hired by BioWare to help create the

    BioWare Community Site for Neverwinter

    Nights (launched June 2002)

    Had no clue what to expect, but the rest asthey say now is history.

    Learned lots. Still learning...

    What makes me qualified?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    13/131

    Spent a lot of time screaming at Murphy. Hired by BioWare to help create the

    BioWare Community Site for Neverwinter

    Nights (launched June 2002)

    Had no clue what to expect, but the rest asthey say now is history.

    Learned lots. Still learning... Insanity...

    What makes me qualified?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    14/131

    What are we going to cover?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    15/131

    What are we going to cover?

    A History of Disaster

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    16/131

    What are we going to cover?

    A History of Disaster Launching the BioWare

    Community

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    17/131

    What are we going to cover?

    A History of Disaster Launching the BioWare

    Community Pain Points of an Application

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    18/131

    A History of Disaster

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    19/131

    A History of Disaster

    What skill must you have to be a webdeveloper/sysadmin in charge of a majorweb application?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    20/131

    A History of Disaster

    What skill must you have to be a webdeveloper/sysadmin in charge of a majorweb application?

    The answer: You must be slightlyinsane!

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    21/131

    A History of Disaster

    What skill must you have to be a webdeveloper/sysadmin in charge of a majorweb application?

    The answer: You must be slightlyinsane!

    ... and perhaps slightly masochistic :)

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    22/131

    A History of Disaster

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    23/131

    A History of Disaster

    Web Server Crashes (typical)

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    24/131

    A History of Disaster

    Web Server Crashes (typical) Load Balancer Crashes

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    25/131

    A History of Disaster

    Web Server Crashes (typical) Load Balancer Crashes

    Major Mail System crashes

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    26/131

    A History of Disaster

    Web Server Crashes (typical) Load Balancer Crashes

    Major Mail System crashes File System Crashes (or how I came tohate NFS)

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    27/131

    A History of Disaster

    Web Server Crashes (typical) Load Balancer Crashes

    Major Mail System crashes File System Crashes (or how I came tohate NFS)

    Database Crashes (sigh)

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    28/131

    A History of Disaster

    Web Server Crashes (typical) Load Balancer Crashes

    Major Mail System crashes File System Crashes (or how I came tohate NFS)

    Database Crashes (sigh) Power outage in the building

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    29/131

    A History of Disaster

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    30/131

    A History of Disaster

    Sweden has an incredibly hot summer.Who knew.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    31/131

    A History of Disaster

    Sweden has an incredibly hot summer.Who knew. Building nearby burns down and takes

    down the city grid, we sit on thebalcony and watch the fire...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    32/131

    A History of Disaster

    Sweden has an incredibly hot summer.Who knew. Building nearby burns down and takes

    down the city grid, we sit on thebalcony and watch the fire...

    The toilet explodes and floods.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    33/131

    A History of Disaster

    Sweden has an incredibly hot summer.Who knew. Building nearby burns down and takes

    down the city grid, we sit on thebalcony and watch the fire...

    The toilet explodes and floods.

    Someone connects the storm drain tothe kitchen sink. Oops.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    34/131

    A History of Disaster

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    35/131

    A History of Disaster

    Someone pours water on the electricmainboard and explodes your mainelectrical supply the day before a release. BigOops.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    36/131

    A History of Disaster

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    37/131

    A History of Disaster

    Imagine running throughone amazingly crazyblizzard, drunk as youwatch transformers

    explode and the sweepingcone of darkness spreadacross the city.... You havethe presence of mind to do

    a sequenced shut down butyou cant see straight tobring anything back up soyou sleep on the server

    room floor to sober up.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    38/131

    What is a Social Application?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    39/131

    What is a Social Application?

    A site which primarily focuses on interactions

    between users.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    40/131

    What is a Social Application?

    A site which primarily focuses on interactions

    between users.

    MySQL.com is not a social application,

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    41/131

    What is a Social Application?

    A site which primarily focuses on interactions

    between users.

    MySQL.com is not a social application,

    Web 2.0 applications: Facebook, LinkedIn,

    MySpace, most community sites.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    42/131

    What is a Social Application?

    A site which primarily focuses on interactions

    between users.

    MySQL.com is not a social application,

    Web 2.0 applications: Facebook, LinkedIn,

    MySpace, most community sites.

    Developing and Launching a social applicationhas special challenges

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    43/131

    Neverwinter Nights Community...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    44/131

    A primer for launching a social

    application...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    45/131

    A primer for launching a social

    application...

    1. Plan to have about 10 times the number ofusers that you conservatively expect.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    46/131

    A primer for launching a social

    application...

    1. Plan to have about 10 times the number ofusers that you conservatively expect.

    2. Be prepared for getting 100 times if your

    marketing has been good.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    47/131

    A primer for launching a social

    application...

    1. Plan to have about 10 times the number ofusers that you conservatively expect.

    2. Be prepared for getting 100 times if your

    marketing has been good.3. Be prepared to scale *EVERY* aspect of

    your application: Web, DB, Mail etc.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    48/131

    A primer for launching a social

    application...

    1. Plan to have about 10 times the number ofusers that you conservatively expect.

    2. Be prepared for getting 100 times if your

    marketing has been good.3. Be prepared to scale *EVERY* aspect of

    your application: Web, DB, Mail etc.

    4. Be smart, launch softly.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    49/131

    A primer for launching a social

    application...

    1. Plan to have about 10 times the number ofusers that you conservatively expect.

    2. Be prepared for getting 100 times if your

    marketing has been good.3. Be prepared to scale *EVERY* aspect of

    your application: Web, DB, Mail etc.

    4. Be smart, launch softly.

    5. Be even smarter, dont launch on a Fridayevening.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    50/131

    Before the launch

    All cocky and sure of myself

    What could go wrong?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    51/131

    After the launch

    A picture is worth a thousandwords

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    52/131

    What we did (Dont do at home!)

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    53/131

    What we did (Dont do at home!)

    Launched on a Friday afternoon, idea wasto have less traffic.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    54/131

    What we did (Dont do at home!)

    Launched on a Friday afternoon, idea wasto have less traffic.

    Site contained a function to send an alert ifdatabase was down, when site went down,it triggered 5,000+ emails in a few mins andtook down the mail server

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    55/131

    What we did (Dont do at home!)

    Launched on a Friday afternoon, idea wasto have less traffic.

    Site contained a function to send an alert ifdatabase was down, when site went down,it triggered 5,000+ emails in a few mins andtook down the mail server

    Not enough slaves to allow the site tofunction. Ripped apart desktop computersto create functional DB slaves.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    56/131

    Key to Success

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    57/131

    Key to Success

    Figure out the pain points of anapplication

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    58/131

    Key to Success

    Figure out the pain points of anapplication

    Be prepared to scale every part of yourapplication.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    59/131

    Key to Success

    Figure out the pain points of anapplication

    Be prepared to scale every part of yourapplication.

    Be prepared to sacrifice performancefor availability, chances are good youwont be doing the other way around

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    60/131

    Key to Success

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    61/131

    Key to Success

    Become omniscient and omnipotent.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    62/131

    Key to Success

    Become omniscient and omnipotent. Identify Single Points of Failure (SPoF)...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    63/131

    Key to Success

    Become omniscient and omnipotent. Identify Single Points of Failure (SPoF)...

    If you have an SPoF... guaranteed it willfail

    SP F d h t t

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    64/131

    SPoFs and how to get

    yourself fired :)

    SP F d h t t

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    65/131

    SPoFs and how to get

    yourself fired :)

    Do an SPoF audit on your application,SPoFs can be:

    SP F d h t t

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    66/131

    SPoFs and how to get

    yourself fired :)

    Do an SPoF audit on your application,SPoFs can be:

    external dependencies (isp etc.)

    SP F d h t t

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    67/131

    SPoFs and how to get

    yourself fired :)

    Do an SPoF audit on your application,SPoFs can be:

    external dependencies (isp etc.) physical infrastructure: power.

    SP F d h t t

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    68/131

    SPoFs and how to get

    yourself fired :)

    Do an SPoF audit on your application,SPoFs can be:

    external dependencies (isp etc.) physical infrastructure: power.

    people

    SP F d h t t

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    69/131

    SPoFs and how to get

    yourself fired :)

    Do an SPoF audit on your application,SPoFs can be:

    external dependencies (isp etc.) physical infrastructure: power.

    people

    servers (db, web, load, firewall, dns...)

    SPoFs and ho to get

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    70/131

    SPoFs and how to get

    yourself fired :)

    Do an SPoF audit on your application,SPoFs can be:

    external dependencies (isp etc.) physical infrastructure: power.

    people

    servers (db, web, load, firewall, dns...)

    application hooks/CRONs

    P i P i t #1 Th W b d Fil

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    71/131

    Pain Point #1: The Web and FileServers

    Pain Point #1 The Web and File

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    72/131

    Pain Point #1: The Web and FileServers

    A typical PHP application with lots ofvisitors will have to run on a cluster of webservers.

    Pain Point #1 The Web and File

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    73/131

    Pain Point #1: The Web and FileServers

    A typical PHP application with lots ofvisitors will have to run on a cluster of webservers.

    Centralized file server or pushed filesystem?

    Pain Point #1: The Web and File

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    74/131

    Pain Point #1: The Web and FileServers

    A typical PHP application with lots ofvisitors will have to run on a cluster of webservers.

    Centralized file server or pushed filesystem?

    Centralized file server can be a bottleneck,

    pushed file system limits some programmingoptions.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    75/131

    Pain Point #2: The Database

    How will you configure the database. Master/Slave?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    76/131

    Pain Point #2: The Database

    Sharding? More common amongst newersocial applications.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    77/131

    Pain Point #2: The Database

    Perhaps MySQL Proxy? We ran MySQL Proxy as a test on

    MySQL.com, its getting there!

    http://forge.mysql.com/wiki/MySQL_Proxy

    http://forge.mysql.com/wiki/MySQL_Proxyhttp://forge.mysql.com/wiki/MySQL_Proxyhttp://forge.mysql.com/wiki/MySQL_Proxy
  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    78/131

    Pain Point #2: The Database

    Perhaps look at Cloud options such asAWS. Allows growth at the least cost and lets

    someone else handle the problem of scalingfor traffic!

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    79/131

    Pain Point #3: The Mail Server

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    80/131

    Pain Point #3: The Mail Server

    Most social applications depend on vastquantities of emails to be sent out.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    81/131

    Pain Point #3: The Mail Server

    Most social applications depend on vastquantities of emails to be sent out. What happens when your SMTP server

    gives up the ghost? Do you run SMTPservers on your web servers? Isolate theSMTP Servers?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    82/131

    Pain Point #3: The Mail Server

    Most social applications depend on vastquantities of emails to be sent out. What happens when your SMTP server

    gives up the ghost? Do you run SMTPservers on your web servers? Isolate theSMTP Servers?

    We dumped mail into a MySQL Db andsent with custom daemon.

    Pain Point #4: Controlling Master/

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    83/131

    Pain Point #4: Controlling Master/Slave Writes

    Almost every application of this kindobviously splits out reads to read slaves andwrites to masters.

    Use some sort of DNS based loadbalancing on your DB servers to sendqueries?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    84/131

    Pain Point #5: Data Caching

    Replicated setups == Replication Lag. Replicated Forum software particularly

    vulnerable with increased traffic, missing

    posts etc.

    Slave dependent queries for IDs etc. maycause issues with data integrity.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    85/131

    Pain Point #5: Data Caching

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    86/131

    Pain Point #5: Data Caching

    Memcached!!! When you write to thedatabase you write to your memcachedserver, read from memcached beforereading from the database again.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    87/131

    Pain Point #5: Data Caching

    Memcached!!! When you write to thedatabase you write to your memcachedserver, read from memcached beforereading from the database again.

    Are you going to the database too much?Counts of Users, Activity etc.?

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    88/131

    Pain Point #5: Data Caching

    Memcached!!! When you write to thedatabase you write to your memcachedserver, read from memcached beforereading from the database again.

    Are you going to the database too much?Counts of Users, Activity etc.?

    Before memcached, we used filesystem fileswritten by system processes.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    89/131

    Pain Point #6: The PHP Code

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    90/131

    Pain Point #6: The PHP Code

    XDebug. If you arent using it. Download it,learn it. Use it. Improve performance ofyour application. (http://www.xdebug.org)

    i i C

    http://www.xdebug.org/http://www.xdebug.org/
  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    91/131

    Pain Point #6: The PHP Code

    XDebug. If you arent using it. Download it,learn it. Use it. Improve performance ofyour application. (http://www.xdebug.org)

    Profile your application.

    P i P i 6 Th PHP C d

    http://www.xdebug.org/http://www.xdebug.org/
  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    92/131

    Pain Point #6: The PHP Code

    XDebug. If you arent using it. Download it,learn it. Use it. Improve performance ofyour application. (http://www.xdebug.org)

    Profile your application. Take a lesson from a high visibility site:Wikipedia, run a fraction of your requests

    through xdebug and profile.

    P i P i #6 Th PHP C d

    http://www.xdebug.org/http://www.xdebug.org/
  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    93/131

    Pain Point #6: The PHP Code

    A profile of mysql.com in April 2008

    P i P i t #6 M it i

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    94/131

    Pain Point #6: Monitoring

    P i P i t #6 M it i

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    95/131

    Pain Point #6: Monitoring

    If a person falls in the forest do you hearthe PHP Fatal Error?

    P i P i t #6 M it i

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    96/131

    Pain Point #6: Monitoring

    If a person falls in the forest do you hearthe PHP Fatal Error? Be omniscient in your applications. If

    something goes wrong do not wait forsomeone to tell you.

    P i P i t #6 M it i

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    97/131

    Pain Point #6: Monitoring

    If a person falls in the forest do you hearthe PHP Fatal Error? Be omniscient in your applications. If

    something goes wrong do not wait forsomeone to tell you.

    Build monitoring into the application, butdo you want High Performance?

    P i P i t #6 M it i

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    98/131

    Pain Point #6: Monitoring

    P i P i t #6 M it i

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    99/131

    Pain Point #6: Monitoring

    Capture your errors and logging into logfiles which are then monitored.

    Pain Point #6 Monitoring

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    100/131

    Pain Point #6: Monitoring

    Capture your errors and logging into logfiles which are then monitored. Establish a good monitoring tool which

    monitors not only the Servers but yourApplication.

    Pain Point #6 Monitoring

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    101/131

    Pain Point #6: Monitoring

    Capture your errors and logging into logfiles which are then monitored. Establish a good monitoring tool which

    monitors not only the Servers but yourApplication.

    Shameless plug for both MySQL EnterpriseMonitoring and my own open sourceBigDaddy (bigdaddymonitor.org) whichgrew out of all these pain points

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    102/131

    Pain Point #7: Your SQL Queries

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    103/131

    Pain Point #7: Your SQL Queries

    In the end a PHP/MySQL application livesand dies on the strength of your queries.

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    104/131

    Pain Point #7: Your SQL Queries

    In the end a PHP/MySQL application livesand dies on the strength of your queries. Make sure that you have good indexes on

    your tables. EXPLAIN always.

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    105/131

    Pain Point #7: Your SQL Queries

    In the end a PHP/MySQL application livesand dies on the strength of your queries. Make sure that you have good indexes on

    your tables. EXPLAIN always. Make sure that you have query caching

    turned on go examine your slow query log.

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    106/131

    Pain Point #7: Your SQL Queries

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    107/131

    Pain Point #7: Your SQL Queries

    Queries do not always scale!

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    108/131

    Pain Point #7: Your SQL Queries

    Queries do not always scale! Use some sort of query analyzer,

    custom or third party.

    Pain Point #7: Your SQL Queries

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    109/131

    Pain Point #7: Your SQL Queries

    Queries do not always scale! Use some sort of query analyzer,

    custom or third party.

    When you develop, try to testexpensive queries against a proper

    data set size.

    Pain Point #8: Ajax Javascript

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    110/131

    Pain Point #8: Ajax, Javascript

    Pain Point #8: Ajax Javascript

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    111/131

    Pain Point #8: Ajax, Javascript

    App performance is what the client sees,not what the server/server-op sees

    Pain Point #8: Ajax Javascript

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    112/131

    Pain Point #8: Ajax, Javascript

    App performance is what the client sees,not what the server/server-op sees DB Setup tuned for Web 2.0 apps? Ajax

    applications tend to be less read heavy andmore write heavy.

    Pain Point #8: Ajax Javascript

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    113/131

    Pain Point #8: Ajax, Javascript

    App performance is what the client sees,not what the server/server-op sees DB Setup tuned for Web 2.0 apps? Ajax

    applications tend to be less read heavy andmore write heavy.

    InnoDB versus MyISAM for primary keylookups.

    Pain Point #8: Ajax Javascript

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    114/131

    Pain Point #8: Ajax, Javascript

    Client tuning is essential as much as servertuning. YSlow is one option:

    Pain Point #9: All the other things

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    115/131

    Pain Point #9: All the other things

    Pain Point #9: All the other things

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    116/131

    Pain Point #9: All the other things

    Over the years pain points have come in allshapes and sizes, including our apachelogs :)

    Pain Point #9: All the other things

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    117/131

    Pain Point #9: All the other things

    Over the years pain points have come in allshapes and sizes, including our apachelogs :)

    We ended up creating a sharded db systemwith a simple perl script to dump web logsinto a MySQL database.

    Pain Point #9: All the other things

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    118/131

    Pain Point #9: All the other things

    Over the years pain points have come in allshapes and sizes, including our apachelogs :)

    We ended up creating a sharded db systemwith a simple perl script to dump web logsinto a MySQL database.

    Oddly worked as well if not better than afile system.

    Final thought...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    119/131

    Final thought...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    120/131

    Murphy's Extended Law: If a series ofevents can go wrong, they will do so in theworst possible sequence.

    Final thought...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    121/131

    Murphy's Extended Law: If a series ofevents can go wrong, they will do so in theworst possible sequence.

    NFS Crash

    Final thought...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    122/131

    Murphy's Extended Law: If a series ofevents can go wrong, they will do so in theworst possible sequence.

    NFS Crash

    File system corrupt

    Final thought...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    123/131

    Murphy's Extended Law: If a series ofevents can go wrong, they will do so in theworst possible sequence.

    NFS Crash

    File system corrupt

    DB Crash, Table corrupted

    Final thought...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    124/131

    Murphy's Extended Law: If a series ofevents can go wrong, they will do so in theworst possible sequence.

    NFS Crash

    File system corrupt

    DB Crash, Table corrupted

    Backup corrupted by another sequenceof events.

    Final thought...

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    125/131

    Murphy's Extended Law: If a series ofevents can go wrong, they will do so in theworst possible sequence.

    NFS Crash

    File system corrupt

    DB Crash, Table corrupted

    Backup corrupted by another sequenceof events.

    I was on holiday

    The moral of this sordid tale

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    126/131

    e o a o s so d d a e

    The moral of this sordid tale

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    127/131

    Murphy Loves Web ApplicationDevelopers.

    The moral of this sordid tale

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    128/131

    Murphy Loves Web ApplicationDevelopers. Everything goes wrong at some point

    The moral of this sordid tale

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    129/131

    Murphy Loves Web ApplicationDevelopers. Everything goes wrong at some point

    Just be prepared

    The moral of this sordid tale

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    130/131

    Murphy Loves Web ApplicationDevelopers. Everything goes wrong at some point

    Just be prepared Eliminate every SPoF (Single Point of

    Failure) in your system.

  • 7/29/2019 High Performance Social Networking Applications PHP MySQL

    131/131