SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Scaling Databases with
     DBIx::Router
        Perrin Harkins
       We Also Walk Dogs
What is DBIx::Router?

Load-balancing
Failover
Sharding
Transparent
   (Mostly.)
Why would you need this?


Web and app servers are easy to scale
   Just add another dozen boxes
Why would you need this?

Databases not so much
   Big iron
   Commercial clustering solutions
   Human sacrifice
Advice from Experts




       Brad Fitzpatrick,                Cal Henderson,               Jeremy Zawodny
“Inside LiveJournal’s Backend”   “Building Scalable Websites”       and Derek J Balling,
                                                                “High Performance MySQL”
Caching

Keep your hot data in a fast cache
You get this one for free, thanks to DBI::Gofer
Can use Cache::FastMmap, memcached, etc. through CHI
Read-only Copies
Replication to local server or remote slaves
Be careful of replication lag




                (from MySQL 5.1 docs)
Sharding
Large data is split across multiple machines
   Users A-L, M-Z
   Logs by month
   Consistent hashing algorithm
May involve directory server
JOINs are now the programmer’s problem
This is going to mean a custom database layer

And rewriting all your old code to use it

DBIx::Router tries to separate this plumbing
Shoulders of Giants

Enter DBI::Gofer
   “A scalable stateless proxy architecture for DBI”
   Bundles up requests, sends them over a transport,
   executes them, sends back results
Shoulders of Giants

Used by shopzilla.com and petfinder.com to pool connections
Lots of good stuff like caching, timeouts, tracing
DBIx::Router is a Gofer transport
   But it executes the calls locally
Shoulders of Giants

CPAN makes everything easy
   SQL::Statement parses SQL (!)
   Config::Any solves the XML problem
How does it work?

DataSources
   Individual (DSNs) or Group
   Group handles failover
   Also load-balancing
Single DataSource
  {
       name       =>   'Master1',
       dsn        =>   'dbi:Pg:dbname=lolcats',
       user       =>   ‘icanhas’,
       password   =>   ‘ch33zeburger’,
  },
Group DataSource
  {
       name        => 'ReadCluster',
       class       => 'random',
       datasources => [ ‘Slave1’, ‘Slave2’ ],
  },
Group DataSource
  {
       name        => 'ReadCluster',
       class       => 'roundrobin',
       datasources => [ ‘Slave1’, ‘Slave2’ ],
  },
Group DataSource
  {
       name          =>   'ReadCluster',
       class         =>   'roundrobin',
       datasources   =>   [ ‘Slave1’, ‘Slave2’ ],
       failover      =>   1,
       timeout       =>   8,
  },
Group DataSource
  {
       name        => 'ReadWriteCluster',
       class       => 'repeater',
       datasources => [ ‘Master1’, ‘Master2’ ],
  },
Group DataSource
    {
         name      =>   'StoreShards',
         class     =>   'shard',
         type      =>   'list',
         table     =>   'orders',
         column    =>   'store_id',
         shards    =>   [
             {
                   values     => [ 1, 3, 5 ],
                   datasource => 'EastCoast',
              },
              {
                   values     => [ 2, 4, 6 ],
                   datasource => 'WestCoast',
              },
         ],
    },
Subclass DataSources

Custom auth schemes for the paranoid
Ye olde insane load-balancing scheme
Shards with a directory server
Rules

Map queries to DataSources
Organized in RuleLists
   Most specific to least
   Can fall back to pass-through
Rule: regex
  {
       class        =>   'regex',
       datasource   =>   'ReadCluster',
       match        =>   ['^ s* SELECT b '],
       not_match    =>   ['b FOR s+ UPDATE b '],
  },
Rule: readonly
  {
       class      => 'readonly',
       datasource => 'ReadCluster',
  },
Rule: parser
  {
        class => 'parser',
        match => [
            {
                structure => 'tables',
                operator => 'all',
                tokens     => ['order_history’]
            },
  },

      Operators: all, any, none, only
      Structures: command, tables, columns
Rule: not
  {
       class      => 'not',
       rule       => { class => ‘readonly’ }
       datasource => 'Master1',
  },
Rule: default
  {
       class      => 'default',
       datasource => 'Master1',
  },
{
    datasources => [
        {
            name => 'Master1',
            dsn => 'dbi:mysql:dbname=lolcats',
            user => undef,
            password => undef,
        },
        {
            name => 'Slave1',
            dsn => 'dbi:mysql:dbname=zomg1',
            user => undef,
            password => undef,
        },
        {
            name => 'Slave2',
            dsn => 'dbi:mysql:dbname=zomg2',
            user => undef,
            password => undef,
        },
        {
            name        => 'ReadCluster',
            class       => 'random',
            datasources => [ 'Slave1', 'Slave2', ],
            failover    => 1,
            timeout     => 8,
        },
    ],
    rules => [
        {
            class      => 'readonly',
            datasource => 'ReadCluster',
        },
        {
            class      => 'default',
            datasource => 'Master1',
        },
    ],
}
How do you run it?
DBI_AUTOPROXY=”dbi:Gofer: 
  transport=DBIx::Router; 
  conf=/path/to/conf.pl”

$dbh = DBI->connect("dbi:Gofer: 
  transport=DBIx::Router;        
  conf=/path/to/conf.pl;         
  dsn=$original_dsn",
  $user, $passwd, %attributes);
What’s the bad news?

AutoCommit
   But Tim plans to fix that
No streaming results
   Also fixable
Failover and sharding are tough to generalize
Status
Hosted on Google Code
Mostly there, but some bits need work
   Sharding
   Failover
Needs user feedback
Needs more tests
Future Directions

Make routing decisions optionally sticky
Support explicit hints in method call attributes
   Helps with sharding
   Workaround for tricky queries that fool SQL::Parser
Thanks!
http://code.google.com/p/dbix-router/
What else is out there?

Mostly faux DBD drivers
   DBD::Multi
   DBD::Multiplex
   DBIx::HA
DBI::Role

Contenu connexe

Tendances

BITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB
 
What's New in the PHP Driver
What's New in the PHP DriverWhat's New in the PHP Driver
What's New in the PHP DriverMongoDB
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica setsRandall Hunt
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Scott Leberknight
 
Create manula and automaticly database
Create manula and automaticly databaseCreate manula and automaticly database
Create manula and automaticly databaseAnar Godjaev
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersAmanda Gilmore
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQLNaeem Junejo
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of SlickKnoldus Inc.
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningMongoDB
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityMongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 

Tendances (18)

veracruz
veracruzveracruz
veracruz
 
BITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQL
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
 
My sql administration
My sql administrationMy sql administration
My sql administration
 
What's New in the PHP Driver
What's New in the PHP DriverWhat's New in the PHP Driver
What's New in the PHP Driver
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
Sequelize
SequelizeSequelize
Sequelize
 
Create manula and automaticly database
Create manula and automaticly databaseCreate manula and automaticly database
Create manula and automaticly database
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQL
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of Slick
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and Installation
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and Creativity
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 

En vedette

Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsPerrin Harkins
 
PyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to ProfilingPyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to ProfilingPerrin Harkins
 
Choosing a Web Architecture for Perl
Choosing a Web Architecture for PerlChoosing a Web Architecture for Perl
Choosing a Web Architecture for PerlPerrin Harkins
 
Care and Feeding of Large Web Applications
Care and Feeding of Large Web ApplicationsCare and Feeding of Large Web Applications
Care and Feeding of Large Web ApplicationsPerrin Harkins
 
Top 10 Perl Performance Tips
Top 10 Perl Performance TipsTop 10 Perl Performance Tips
Top 10 Perl Performance TipsPerrin Harkins
 

En vedette (9)

Cam on doi
Cam on doiCam on doi
Cam on doi
 
Eastern state
Eastern stateEastern state
Eastern state
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
PyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to ProfilingPyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to Profiling
 
Choosing a Web Architecture for Perl
Choosing a Web Architecture for PerlChoosing a Web Architecture for Perl
Choosing a Web Architecture for Perl
 
Care and Feeding of Large Web Applications
Care and Feeding of Large Web ApplicationsCare and Feeding of Large Web Applications
Care and Feeding of Large Web Applications
 
Introduzione al web marketing
Introduzione al web marketingIntroduzione al web marketing
Introduzione al web marketing
 
Hanh phuc
Hanh phucHanh phuc
Hanh phuc
 
Top 10 Perl Performance Tips
Top 10 Perl Performance TipsTop 10 Perl Performance Tips
Top 10 Perl Performance Tips
 

Similaire à Scaling Databases with DBIx::Router

Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
Basic Replication in MongoDB
Basic Replication in MongoDBBasic Replication in MongoDB
Basic Replication in MongoDBMongoDB
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
Kerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastKerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastJorge Lopez-Malla
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced ReplicationMongoDB
 
2013 london advanced-replication
2013 london advanced-replication2013 london advanced-replication
2013 london advanced-replicationMarc Schwering
 
Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!Harald Zeitlhofer
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Replication MongoDB Days 2013
Replication MongoDB Days 2013Replication MongoDB Days 2013
Replication MongoDB Days 2013Randall Hunt
 

Similaire à Scaling Databases with DBIx::Router (20)

Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
DataMapper
DataMapperDataMapper
DataMapper
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Basic Replication in MongoDB
Basic Replication in MongoDBBasic Replication in MongoDB
Basic Replication in MongoDB
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Kerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastKerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit east
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
Dynomite Nosql
Dynomite NosqlDynomite Nosql
Dynomite Nosql
 
2013 london advanced-replication
2013 london advanced-replication2013 london advanced-replication
2013 london advanced-replication
 
Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!
 
Php summary
Php summaryPhp summary
Php summary
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Replication MongoDB Days 2013
Replication MongoDB Days 2013Replication MongoDB Days 2013
Replication MongoDB Days 2013
 

Plus de Perrin Harkins

Care and feeding notes
Care and feeding notesCare and feeding notes
Care and feeding notesPerrin Harkins
 
Low maintenance perl notes
Low maintenance perl notesLow maintenance perl notes
Low maintenance perl notesPerrin Harkins
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with PerlPerrin Harkins
 
Efficient Shared Data in Perl
Efficient Shared Data in PerlEfficient Shared Data in Perl
Efficient Shared Data in PerlPerrin Harkins
 
Choosing a Templating System
Choosing a Templating SystemChoosing a Templating System
Choosing a Templating SystemPerrin Harkins
 
The Most Common Template Toolkit Mistake
The Most Common Template Toolkit MistakeThe Most Common Template Toolkit Mistake
The Most Common Template Toolkit MistakePerrin Harkins
 

Plus de Perrin Harkins (8)

Care and feeding notes
Care and feeding notesCare and feeding notes
Care and feeding notes
 
Scalable talk notes
Scalable talk notesScalable talk notes
Scalable talk notes
 
Low maintenance perl notes
Low maintenance perl notesLow maintenance perl notes
Low maintenance perl notes
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with Perl
 
Efficient Shared Data in Perl
Efficient Shared Data in PerlEfficient Shared Data in Perl
Efficient Shared Data in Perl
 
Choosing a Templating System
Choosing a Templating SystemChoosing a Templating System
Choosing a Templating System
 
Low-Maintenance Perl
Low-Maintenance PerlLow-Maintenance Perl
Low-Maintenance Perl
 
The Most Common Template Toolkit Mistake
The Most Common Template Toolkit MistakeThe Most Common Template Toolkit Mistake
The Most Common Template Toolkit Mistake
 

Dernier

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Scaling Databases with DBIx::Router

  • 1. Scaling Databases with DBIx::Router Perrin Harkins We Also Walk Dogs
  • 3. Why would you need this? Web and app servers are easy to scale Just add another dozen boxes
  • 4. Why would you need this? Databases not so much Big iron Commercial clustering solutions Human sacrifice
  • 5. Advice from Experts Brad Fitzpatrick, Cal Henderson, Jeremy Zawodny “Inside LiveJournal’s Backend” “Building Scalable Websites” and Derek J Balling, “High Performance MySQL”
  • 6. Caching Keep your hot data in a fast cache You get this one for free, thanks to DBI::Gofer Can use Cache::FastMmap, memcached, etc. through CHI
  • 7. Read-only Copies Replication to local server or remote slaves Be careful of replication lag (from MySQL 5.1 docs)
  • 8. Sharding Large data is split across multiple machines Users A-L, M-Z Logs by month Consistent hashing algorithm May involve directory server JOINs are now the programmer’s problem
  • 9. This is going to mean a custom database layer And rewriting all your old code to use it DBIx::Router tries to separate this plumbing
  • 10. Shoulders of Giants Enter DBI::Gofer “A scalable stateless proxy architecture for DBI” Bundles up requests, sends them over a transport, executes them, sends back results
  • 11. Shoulders of Giants Used by shopzilla.com and petfinder.com to pool connections Lots of good stuff like caching, timeouts, tracing DBIx::Router is a Gofer transport But it executes the calls locally
  • 12. Shoulders of Giants CPAN makes everything easy SQL::Statement parses SQL (!) Config::Any solves the XML problem
  • 13. How does it work? DataSources Individual (DSNs) or Group Group handles failover Also load-balancing
  • 14. Single DataSource { name => 'Master1', dsn => 'dbi:Pg:dbname=lolcats', user => ‘icanhas’, password => ‘ch33zeburger’, },
  • 15. Group DataSource { name => 'ReadCluster', class => 'random', datasources => [ ‘Slave1’, ‘Slave2’ ], },
  • 16. Group DataSource { name => 'ReadCluster', class => 'roundrobin', datasources => [ ‘Slave1’, ‘Slave2’ ], },
  • 17. Group DataSource { name => 'ReadCluster', class => 'roundrobin', datasources => [ ‘Slave1’, ‘Slave2’ ], failover => 1, timeout => 8, },
  • 18. Group DataSource { name => 'ReadWriteCluster', class => 'repeater', datasources => [ ‘Master1’, ‘Master2’ ], },
  • 19. Group DataSource { name => 'StoreShards', class => 'shard', type => 'list', table => 'orders', column => 'store_id', shards => [ { values => [ 1, 3, 5 ], datasource => 'EastCoast', }, { values => [ 2, 4, 6 ], datasource => 'WestCoast', }, ], },
  • 20. Subclass DataSources Custom auth schemes for the paranoid Ye olde insane load-balancing scheme Shards with a directory server
  • 21. Rules Map queries to DataSources Organized in RuleLists Most specific to least Can fall back to pass-through
  • 22. Rule: regex { class => 'regex', datasource => 'ReadCluster', match => ['^ s* SELECT b '], not_match => ['b FOR s+ UPDATE b '], },
  • 23. Rule: readonly { class => 'readonly', datasource => 'ReadCluster', },
  • 24. Rule: parser { class => 'parser', match => [ { structure => 'tables', operator => 'all', tokens => ['order_history’] }, }, Operators: all, any, none, only Structures: command, tables, columns
  • 25. Rule: not { class => 'not', rule => { class => ‘readonly’ } datasource => 'Master1', },
  • 26. Rule: default { class => 'default', datasource => 'Master1', },
  • 27. { datasources => [ { name => 'Master1', dsn => 'dbi:mysql:dbname=lolcats', user => undef, password => undef, }, { name => 'Slave1', dsn => 'dbi:mysql:dbname=zomg1', user => undef, password => undef, }, { name => 'Slave2', dsn => 'dbi:mysql:dbname=zomg2', user => undef, password => undef, }, { name => 'ReadCluster', class => 'random', datasources => [ 'Slave1', 'Slave2', ], failover => 1, timeout => 8, }, ], rules => [ { class => 'readonly', datasource => 'ReadCluster', }, { class => 'default', datasource => 'Master1', }, ], }
  • 28. How do you run it? DBI_AUTOPROXY=”dbi:Gofer: transport=DBIx::Router; conf=/path/to/conf.pl” $dbh = DBI->connect("dbi:Gofer: transport=DBIx::Router; conf=/path/to/conf.pl; dsn=$original_dsn", $user, $passwd, %attributes);
  • 29. What’s the bad news? AutoCommit But Tim plans to fix that No streaming results Also fixable Failover and sharding are tough to generalize
  • 30. Status Hosted on Google Code Mostly there, but some bits need work Sharding Failover Needs user feedback Needs more tests
  • 31. Future Directions Make routing decisions optionally sticky Support explicit hints in method call attributes Helps with sharding Workaround for tricky queries that fool SQL::Parser
  • 33. What else is out there? Mostly faux DBD drivers DBD::Multi DBD::Multiplex DBIx::HA DBI::Role