SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
Your backend architecture
     is what matters
               Scaling your application
       Colin Charles, colin@montyprogram.com
          @bytebot / http://bytebot.net/blog/
   KL Facebook Developer Garage, February 26 2011
What are you building?

• a bunch of static fbml pages + fql+ database
  triggers+views?
• the next cool game zynga wants to acquire?
 • needs to be database driven with proper
    architecture planning
http://xkcd.com/327/
Don’t prematurely
         optimise
                Just remember the 7P’s:
Prior & Proper Planning Prevents Piss Poor Performance
Reference
        Architectures
• Is there one for the Web world?
• Your choices are to:
 • scale up
 • scale out
• Which do you pick?
Scaling out

• Buying (renting) commodity hardware
• Using the cloud to expand
 • Or using the cloud totally: e.g. http://
    heroku.com/facebook
OS
•   If you didn’t go opensource, you’re silly
•   Tuning Linux/BSD is mandatory
    •   filesystem: xfs, ext3(4)
    •   swap is the devil
    •   different schedulers work better for different
        tasks (web, database, etc.)
    •   NFS? You’d better tune that! (stopgap, scaling is
        hard)
Web server

• Apache, lighthttpd, nginx
• They all require configuration (httpd.conf)
• Simple things like maximum connections,
  worker MPM, usually go unconfigured
Language
• “PHP doesn’t scale.” - Cal Henderson, when
  he was at Flickr.com
• Languages are not meant to scale for you
• Use bytecode caches (PHP, Python, etc.)
• Compile away -- HipHop
• Library, driver support; developer
  communities
Databases

• are slow, period.
• partition data into shards
• tune that database
And that was your
basic LAMP stack
How do you scale
        easily?
• Use caches
• Disk-based caching (cache_lite via php-
  pear). RAM disks on SSDs... fast!
• In-memory caching (APC, memcached)
• Cloud-based caching (S3, MogileFS)
memcached

• Easy to setup and use
• Very fast over the network
• Scales, has failover, widely supported
• Centralised and shared across the site
S3
• Databases are good for storing relational
  data, but suck for blob storage
• S3 is a file & data store, running over HTTP
• In theory, infinitely scalable
• Centralised & shared across site
• Costs money, no Malaysian POP
• See OpenStack’s Swift Object Store
CDN
• Outsource it
• Costs a lot of money
• Aflexi is a Malaysian company making a
  pretty darn good CDN (resold via
  Exabytes?)
• Out of your control but will help you scale,
  scale, scale
Back to the database...
• Sharding
   • not all data lives in one place
   • hash records to partitions
     • partition alphabetically? put n-users/
        shard? organise by postal code?
• horizontal vs vertical partitioning
Horizontal vs Vertical
        Partitioning
192.168.0.1                                 192.168.0.1
                                                 User
     User
      id int(10)
                                                       Better if INSERT
                                                  id int(10)
                                              username char(15)
  username char(15)
  password char(15)
    email char(50)    192.168.0.3                      heavy and there’s
                                              password char(15)
                                                email char(50)



                           User
                                                        less frequently
192.168.0.2                 id int(10)
                                            192.168.0.2 changed data
                        username char(15)
                        password char(15)
     User                 email char(50)      UserInfo
      id int(10)                                 login datetime
  username char(15)                             md5 varchar(32)
  password char(15)                             guid varchar(32)
    email char(50)
MySQL has engines

• InnoDB (XtraDB) for transactional use
• MyISAM for “data warehousing” use
• Maria in time
MySQL has replication!
• Simple, easy to implement (async)
• Row based replication is better than
  statement based replication
• You do not need mysql cluster (ndb)
• Look at Tungsten Replicator, Galera, etc. for
  other topologies (e.g. many masters)
Use INDEXes


• Covering index: all fields in SELECT for
  specific table are contained in index
  • EXPLAIN will say “Using index”
Monitor everything!
• Benchmarking allows tracking performance
  over time
• Nagios
• MySQL (MariaDB/Percona Server)
  • slow query log, extended stats in slow
    query log, use EXPLAIN, microsecond
    process list, userstats v2, SHOW
    PROCESSLIST, etc.
Fulltext Search

• Don’t use the database!
• Sphinx
 • SphinxSE for MariaDB
• Lucene
Don’t
• SELECT * FROM room WHERE room_date
  BETWEEN ‘2011-02-25’ AND ‘2011-02-27’
 • not have an INDEX on field being
    operated on by range operator => full
    table scan
• not allocate a primary key
• over-normalise (3NF is fine)
Keeping state
• Session data in DB
 • PHP has files, doesn’t scale. DB
    +Memcached goes far
• Replicate/Partition/Cache state
• Cookies can be validated by checksums and
  timestamps (encryption consumes CPU)
General advice
•   Your DB servers are not your web servers and they’re not
    your load balancers
•   Write non-locking code
•   Don’t block loading unnecessarily
•   Cache partially (esp. w/dynamic pages)
•   Use UTC for time (replication across geographies?)
•   Keep everything in version control
•   Migrations are never recommended unless you’ve exceeded
    capabilities of current solutions. Beware v2 disasters.
NoSQL

• MongoDB
                  "I don't foresee StumbleUpon ever giving up on all of
                  its MySQL instances. RDBMSs are just too useful. The
                      plan, though, is to shrink what MySQL does over

• Redis            time, let MySQL do what its good at and have HBase
                    take over where MySQL is running up against limits
                    handling ever-growing write rates, table sizes, etc." -
• hBase/Hadoop    Michael Stack, hbase project chair, StumbleUpon DBA
                          http://www.theregister.co.uk/2011/01/19/

• CouchDB
                                      hbase_on_the_rise/



• And the 45 other solutions out there...
A lot of web scale tech
     comes from...
• Brad Fitzpatrick
• LiveJournal infrastructure
• memcached (distributed caching, hits less
  DB), MogileFS (distributed file system),
  Perlbal (reverse proxy load balancer),
  Gearman (remotely run code, load balanced,
  in parallel)
• next: camlistore (http://camlistore.org/)
“Without money the site can't function. Okay, let me tell
you the difference between Facebook and everyone
else, we don't crash EVER! If those servers are down for
even a day, our entire reputation is irreversibly
destroyed! Users are fickle, Friendster has proved that.
Even a few people leaving would reverberate through
the entire userbase. The users are interconnected, that is
the whole point. College kids are online because their
friends are online, and if one domino goes, the other
dominos go, don't you get that?” -- Mark Zuckerberg
(okay, not really, Jesse Eisenberg, in The Social Network)
Resources
• High Performance Web Sites (Steve
  Sounders)
• High Performance MySQL (Jeremy
  Zawodny, Baron Schwartz, Peter Zaitsev, et
  al)
• Study HyperDB (Powers wordpress.com)
• http://kb.askmonty.org/
Thanks/Q&A
Colin Charles, colin@montyprogram.com
  @bytebot | http://bytebot.net/blog/

Contenu connexe

Tendances

캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라Park Chunduck
 
PostgreSQL as an Alternative to MSSQL
PostgreSQL as an Alternative to MSSQLPostgreSQL as an Alternative to MSSQL
PostgreSQL as an Alternative to MSSQLAlexei Krasner
 
What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010jbellis
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureDmitry Buzdin
 
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库YUCHENG HU
 
MongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin HansonMongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin Hansonhungarianhc
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
TokuDB - What You Need to Know
TokuDB - What You Need to KnowTokuDB - What You Need to Know
TokuDB - What You Need to KnowJervin Real
 
How mysql handles ORDER BY, GROUP BY, and DISTINCT
How mysql handles ORDER BY, GROUP BY, and DISTINCTHow mysql handles ORDER BY, GROUP BY, and DISTINCT
How mysql handles ORDER BY, GROUP BY, and DISTINCTSergey Petrunya
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL databaseTobias Lindaaker
 
MongoDB Administration 20110922
MongoDB Administration 20110922MongoDB Administration 20110922
MongoDB Administration 20110922radiocats
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]Malin Weiss
 
Converting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQLConverting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQLJohn Ashmead
 
Fractal Tree Indexes : From Theory to Practice
Fractal Tree Indexes : From Theory to PracticeFractal Tree Indexes : From Theory to Practice
Fractal Tree Indexes : From Theory to PracticeTim Callaghan
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...Malin Weiss
 
Migrating to postgresql
Migrating to postgresqlMigrating to postgresql
Migrating to postgresqlbotsplash.com
 

Tendances (20)

캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라
 
PostgreSQL as an Alternative to MSSQL
PostgreSQL as an Alternative to MSSQLPostgreSQL as an Alternative to MSSQL
PostgreSQL as an Alternative to MSSQL
 
NOSQL Overview
NOSQL OverviewNOSQL Overview
NOSQL Overview
 
What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru Architecture
 
Percona FT / TokuDB
Percona FT / TokuDBPercona FT / TokuDB
Percona FT / TokuDB
 
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
TokuDB 高科扩展性 MySQL 和 MariaDB 数据库
 
MongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin HansonMongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin Hanson
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
TokuDB - What You Need to Know
TokuDB - What You Need to KnowTokuDB - What You Need to Know
TokuDB - What You Need to Know
 
How mysql handles ORDER BY, GROUP BY, and DISTINCT
How mysql handles ORDER BY, GROUP BY, and DISTINCTHow mysql handles ORDER BY, GROUP BY, and DISTINCT
How mysql handles ORDER BY, GROUP BY, and DISTINCT
 
Choosing the right NOSQL database
Choosing the right NOSQL databaseChoosing the right NOSQL database
Choosing the right NOSQL database
 
MongoDB Administration 20110922
MongoDB Administration 20110922MongoDB Administration 20110922
MongoDB Administration 20110922
 
PostgreSQL and MySQL
PostgreSQL and MySQLPostgreSQL and MySQL
PostgreSQL and MySQL
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
 
Converting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQLConverting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQL
 
Fractal Tree Indexes : From Theory to Practice
Fractal Tree Indexes : From Theory to PracticeFractal Tree Indexes : From Theory to Practice
Fractal Tree Indexes : From Theory to Practice
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
Migrating to postgresql
Migrating to postgresqlMigrating to postgresql
Migrating to postgresql
 

En vedette

Lake2 企业安全应急响应新思路
Lake2 企业安全应急响应新思路Lake2 企业安全应急响应新思路
Lake2 企业安全应急响应新思路drewz lin
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web ArchitectureChamnap Chhorn
 
Angular vs Angular 2 vs React. Сергей Александров
Angular vs Angular 2 vs React. Сергей АлександровAngular vs Angular 2 vs React. Сергей Александров
Angular vs Angular 2 vs React. Сергей АлександровEatDog
 
Self-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesSelf-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesEberhard Wolff
 
Enterprise service bus(esb)
Enterprise service bus(esb)Enterprise service bus(esb)
Enterprise service bus(esb)prksh89
 
SOA & ESB Presentation
SOA & ESB PresentationSOA & ESB Presentation
SOA & ESB Presentationerichleipold
 
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...Mitoc Group
 
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?OpenStack Korea Community
 

En vedette (11)

Lake2 企业安全应急响应新思路
Lake2 企业安全应急响应新思路Lake2 企业安全应急响应新思路
Lake2 企业安全应急响应新思路
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
 
Angular vs Angular 2 vs React. Сергей Александров
Angular vs Angular 2 vs React. Сергей АлександровAngular vs Angular 2 vs React. Сергей Александров
Angular vs Angular 2 vs React. Сергей Александров
 
Self-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesSelf-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to Microservices
 
Enterprise service bus(esb)
Enterprise service bus(esb)Enterprise service bus(esb)
Enterprise service bus(esb)
 
SOA & ESB Presentation
SOA & ESB PresentationSOA & ESB Presentation
SOA & ESB Presentation
 
ESB Concepts
ESB ConceptsESB Concepts
ESB Concepts
 
ESB Overview
ESB OverviewESB Overview
ESB Overview
 
How Flipkart scales PHP
How Flipkart scales PHPHow Flipkart scales PHP
How Flipkart scales PHP
 
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
 
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
 

Similaire à Your backend architecture is what matters slideshare

Intro to big data choco devday - 23-01-2014
Intro to big data   choco devday - 23-01-2014Intro to big data   choco devday - 23-01-2014
Intro to big data choco devday - 23-01-2014Hassan Islamov
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitterRoger Xia
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...smallerror
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...xlight
 
High-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and JavaHigh-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and Javasunnygleason
 
Chirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterChirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterJohn Adams
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisRicard Clau
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterChris Henry
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudyJohn Adams
 
Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoopbddmoscow
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at nightMichael Yarichuk
 
Mongo db admin_20110329
Mongo db admin_20110329Mongo db admin_20110329
Mongo db admin_20110329radiocats
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdbjixuan1989
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]Huy Do
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage SystemsSATOSHI TAGOMORI
 
Hadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerHadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerIke Ellis
 

Similaire à Your backend architecture is what matters slideshare (20)

Intro to big data choco devday - 23-01-2014
Intro to big data   choco devday - 23-01-2014Intro to big data   choco devday - 23-01-2014
Intro to big data choco devday - 23-01-2014
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Fixing_Twitter
Fixing_TwitterFixing_Twitter
Fixing_Twitter
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
High-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and JavaHigh-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and Java
 
Chirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterChirp 2010: Scaling Twitter
Chirp 2010: Scaling Twitter
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
 
Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoop
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at night
 
Mongo db admin_20110329
Mongo db admin_20110329Mongo db admin_20110329
Mongo db admin_20110329
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
From a student to an apache committer practice of apache io tdb
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdb
 
Be faster then rabbits
Be faster then rabbitsBe faster then rabbits
Be faster then rabbits
 
RavenDB in the wild
RavenDB in the wildRavenDB in the wild
RavenDB in the wild
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Hadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerHadoop for the Absolute Beginner
Hadoop for the Absolute Beginner
 

Plus de Colin Charles

Differences between MariaDB 10.3 & MySQL 8.0
Differences between MariaDB 10.3 & MySQL 8.0Differences between MariaDB 10.3 & MySQL 8.0
Differences between MariaDB 10.3 & MySQL 8.0Colin Charles
 
What is MariaDB Server 10.3?
What is MariaDB Server 10.3?What is MariaDB Server 10.3?
What is MariaDB Server 10.3?Colin Charles
 
Databases in the hosted cloud
Databases in the hosted cloud Databases in the hosted cloud
Databases in the hosted cloud Colin Charles
 
MySQL features missing in MariaDB Server
MySQL features missing in MariaDB ServerMySQL features missing in MariaDB Server
MySQL features missing in MariaDB ServerColin Charles
 
The MySQL ecosystem - understanding it, not running away from it!
The MySQL ecosystem - understanding it, not running away from it! The MySQL ecosystem - understanding it, not running away from it!
The MySQL ecosystem - understanding it, not running away from it! Colin Charles
 
Databases in the Hosted Cloud
Databases in the Hosted CloudDatabases in the Hosted Cloud
Databases in the Hosted CloudColin Charles
 
Best practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialBest practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialColin Charles
 
Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)
Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)
Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)Colin Charles
 
Capacity planning for your data stores
Capacity planning for your data storesCapacity planning for your data stores
Capacity planning for your data storesColin Charles
 
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScale
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScaleThe Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScale
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScaleColin Charles
 
Lessons from {distributed,remote,virtual} communities and companies
Lessons from {distributed,remote,virtual} communities and companiesLessons from {distributed,remote,virtual} communities and companies
Lessons from {distributed,remote,virtual} communities and companiesColin Charles
 
Forking Successfully - or is a branch better?
Forking Successfully - or is a branch better?Forking Successfully - or is a branch better?
Forking Successfully - or is a branch better?Colin Charles
 
MariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLMariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLColin Charles
 
Securing your MySQL / MariaDB Server data
Securing your MySQL / MariaDB Server dataSecuring your MySQL / MariaDB Server data
Securing your MySQL / MariaDB Server dataColin Charles
 
The MySQL Server Ecosystem in 2016
The MySQL Server Ecosystem in 2016The MySQL Server Ecosystem in 2016
The MySQL Server Ecosystem in 2016Colin Charles
 
The Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialThe Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialColin Charles
 
Best practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High AvailabilityBest practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High AvailabilityColin Charles
 
Lessons from database failures
Lessons from database failures Lessons from database failures
Lessons from database failures Colin Charles
 
Lessons from database failures
Lessons from database failuresLessons from database failures
Lessons from database failuresColin Charles
 
Lessons from database failures
Lessons from database failuresLessons from database failures
Lessons from database failuresColin Charles
 

Plus de Colin Charles (20)

Differences between MariaDB 10.3 & MySQL 8.0
Differences between MariaDB 10.3 & MySQL 8.0Differences between MariaDB 10.3 & MySQL 8.0
Differences between MariaDB 10.3 & MySQL 8.0
 
What is MariaDB Server 10.3?
What is MariaDB Server 10.3?What is MariaDB Server 10.3?
What is MariaDB Server 10.3?
 
Databases in the hosted cloud
Databases in the hosted cloud Databases in the hosted cloud
Databases in the hosted cloud
 
MySQL features missing in MariaDB Server
MySQL features missing in MariaDB ServerMySQL features missing in MariaDB Server
MySQL features missing in MariaDB Server
 
The MySQL ecosystem - understanding it, not running away from it!
The MySQL ecosystem - understanding it, not running away from it! The MySQL ecosystem - understanding it, not running away from it!
The MySQL ecosystem - understanding it, not running away from it!
 
Databases in the Hosted Cloud
Databases in the Hosted CloudDatabases in the Hosted Cloud
Databases in the Hosted Cloud
 
Best practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialBest practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability Tutorial
 
Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)
Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)
Percona ServerをMySQL 5.6と5.7用に作るエンジニアリング(そしてMongoDBのヒント)
 
Capacity planning for your data stores
Capacity planning for your data storesCapacity planning for your data stores
Capacity planning for your data stores
 
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScale
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScaleThe Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScale
The Proxy Wars - MySQL Router, ProxySQL, MariaDB MaxScale
 
Lessons from {distributed,remote,virtual} communities and companies
Lessons from {distributed,remote,virtual} communities and companiesLessons from {distributed,remote,virtual} communities and companies
Lessons from {distributed,remote,virtual} communities and companies
 
Forking Successfully - or is a branch better?
Forking Successfully - or is a branch better?Forking Successfully - or is a branch better?
Forking Successfully - or is a branch better?
 
MariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLMariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQL
 
Securing your MySQL / MariaDB Server data
Securing your MySQL / MariaDB Server dataSecuring your MySQL / MariaDB Server data
Securing your MySQL / MariaDB Server data
 
The MySQL Server Ecosystem in 2016
The MySQL Server Ecosystem in 2016The MySQL Server Ecosystem in 2016
The MySQL Server Ecosystem in 2016
 
The Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialThe Complete MariaDB Server tutorial
The Complete MariaDB Server tutorial
 
Best practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High AvailabilityBest practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High Availability
 
Lessons from database failures
Lessons from database failures Lessons from database failures
Lessons from database failures
 
Lessons from database failures
Lessons from database failuresLessons from database failures
Lessons from database failures
 
Lessons from database failures
Lessons from database failuresLessons from database failures
Lessons from database failures
 

Your backend architecture is what matters slideshare

  • 1. Your backend architecture is what matters Scaling your application Colin Charles, colin@montyprogram.com @bytebot / http://bytebot.net/blog/ KL Facebook Developer Garage, February 26 2011
  • 2.
  • 3. What are you building? • a bunch of static fbml pages + fql+ database triggers+views? • the next cool game zynga wants to acquire? • needs to be database driven with proper architecture planning
  • 5. Don’t prematurely optimise Just remember the 7P’s: Prior & Proper Planning Prevents Piss Poor Performance
  • 6. Reference Architectures • Is there one for the Web world? • Your choices are to: • scale up • scale out • Which do you pick?
  • 7. Scaling out • Buying (renting) commodity hardware • Using the cloud to expand • Or using the cloud totally: e.g. http:// heroku.com/facebook
  • 8. OS • If you didn’t go opensource, you’re silly • Tuning Linux/BSD is mandatory • filesystem: xfs, ext3(4) • swap is the devil • different schedulers work better for different tasks (web, database, etc.) • NFS? You’d better tune that! (stopgap, scaling is hard)
  • 9. Web server • Apache, lighthttpd, nginx • They all require configuration (httpd.conf) • Simple things like maximum connections, worker MPM, usually go unconfigured
  • 10. Language • “PHP doesn’t scale.” - Cal Henderson, when he was at Flickr.com • Languages are not meant to scale for you • Use bytecode caches (PHP, Python, etc.) • Compile away -- HipHop • Library, driver support; developer communities
  • 11. Databases • are slow, period. • partition data into shards • tune that database
  • 12. And that was your basic LAMP stack
  • 13. How do you scale easily? • Use caches • Disk-based caching (cache_lite via php- pear). RAM disks on SSDs... fast! • In-memory caching (APC, memcached) • Cloud-based caching (S3, MogileFS)
  • 14. memcached • Easy to setup and use • Very fast over the network • Scales, has failover, widely supported • Centralised and shared across the site
  • 15. S3 • Databases are good for storing relational data, but suck for blob storage • S3 is a file & data store, running over HTTP • In theory, infinitely scalable • Centralised & shared across site • Costs money, no Malaysian POP • See OpenStack’s Swift Object Store
  • 16. CDN • Outsource it • Costs a lot of money • Aflexi is a Malaysian company making a pretty darn good CDN (resold via Exabytes?) • Out of your control but will help you scale, scale, scale
  • 17. Back to the database... • Sharding • not all data lives in one place • hash records to partitions • partition alphabetically? put n-users/ shard? organise by postal code? • horizontal vs vertical partitioning
  • 18. Horizontal vs Vertical Partitioning 192.168.0.1 192.168.0.1 User User id int(10) Better if INSERT id int(10) username char(15) username char(15) password char(15) email char(50) 192.168.0.3 heavy and there’s password char(15) email char(50) User less frequently 192.168.0.2 id int(10) 192.168.0.2 changed data username char(15) password char(15) User email char(50) UserInfo id int(10) login datetime username char(15) md5 varchar(32) password char(15) guid varchar(32) email char(50)
  • 19. MySQL has engines • InnoDB (XtraDB) for transactional use • MyISAM for “data warehousing” use • Maria in time
  • 20. MySQL has replication! • Simple, easy to implement (async) • Row based replication is better than statement based replication • You do not need mysql cluster (ndb) • Look at Tungsten Replicator, Galera, etc. for other topologies (e.g. many masters)
  • 21. Use INDEXes • Covering index: all fields in SELECT for specific table are contained in index • EXPLAIN will say “Using index”
  • 22. Monitor everything! • Benchmarking allows tracking performance over time • Nagios • MySQL (MariaDB/Percona Server) • slow query log, extended stats in slow query log, use EXPLAIN, microsecond process list, userstats v2, SHOW PROCESSLIST, etc.
  • 23. Fulltext Search • Don’t use the database! • Sphinx • SphinxSE for MariaDB • Lucene
  • 24. Don’t • SELECT * FROM room WHERE room_date BETWEEN ‘2011-02-25’ AND ‘2011-02-27’ • not have an INDEX on field being operated on by range operator => full table scan • not allocate a primary key • over-normalise (3NF is fine)
  • 25. Keeping state • Session data in DB • PHP has files, doesn’t scale. DB +Memcached goes far • Replicate/Partition/Cache state • Cookies can be validated by checksums and timestamps (encryption consumes CPU)
  • 26. General advice • Your DB servers are not your web servers and they’re not your load balancers • Write non-locking code • Don’t block loading unnecessarily • Cache partially (esp. w/dynamic pages) • Use UTC for time (replication across geographies?) • Keep everything in version control • Migrations are never recommended unless you’ve exceeded capabilities of current solutions. Beware v2 disasters.
  • 27. NoSQL • MongoDB "I don't foresee StumbleUpon ever giving up on all of its MySQL instances. RDBMSs are just too useful. The plan, though, is to shrink what MySQL does over • Redis time, let MySQL do what its good at and have HBase take over where MySQL is running up against limits handling ever-growing write rates, table sizes, etc." - • hBase/Hadoop Michael Stack, hbase project chair, StumbleUpon DBA http://www.theregister.co.uk/2011/01/19/ • CouchDB hbase_on_the_rise/ • And the 45 other solutions out there...
  • 28. A lot of web scale tech comes from... • Brad Fitzpatrick • LiveJournal infrastructure • memcached (distributed caching, hits less DB), MogileFS (distributed file system), Perlbal (reverse proxy load balancer), Gearman (remotely run code, load balanced, in parallel) • next: camlistore (http://camlistore.org/)
  • 29. “Without money the site can't function. Okay, let me tell you the difference between Facebook and everyone else, we don't crash EVER! If those servers are down for even a day, our entire reputation is irreversibly destroyed! Users are fickle, Friendster has proved that. Even a few people leaving would reverberate through the entire userbase. The users are interconnected, that is the whole point. College kids are online because their friends are online, and if one domino goes, the other dominos go, don't you get that?” -- Mark Zuckerberg (okay, not really, Jesse Eisenberg, in The Social Network)
  • 30. Resources • High Performance Web Sites (Steve Sounders) • High Performance MySQL (Jeremy Zawodny, Baron Schwartz, Peter Zaitsev, et al) • Study HyperDB (Powers wordpress.com) • http://kb.askmonty.org/
  • 31. Thanks/Q&A Colin Charles, colin@montyprogram.com @bytebot | http://bytebot.net/blog/