SlideShare uma empresa Scribd logo
1 de 35
© All rights reserved. Zend Technologies, Inc.
Introduction to Column
Oriented Databases in PHP
By Slavey Karadzhov slavey.karadzhov@zend.com
To watch the webinar please go to:
http://www.zend.com/en/webinar/PHP/70170000000bZ2X-
CODB-20110708.flv
© All rights reserved. Zend Technologies, Inc.
About Me
•Name: Slavey Karadzhov (Славей Караджов)
•Programmer since my early days
•PHP programmer since 1999
•Open source fan and supporter
•Hobby (software) inventor
Won the best “IT Innovation of the Year 2004” from PC Magazine
•Working for Zend Technologies since 2008
•In Stuttgart, Germany
•As a programmer, consultant and trainer
2 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Agenda
•How Do They Look?
•Why New Type Of Database?
•The Details
•Supported Operations
•Available Open Source CODB engines
•Putting Everything Together
•How To Use It From PHP
•Is CODB For Me?
•Questions
3 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
How Do They Look?
… and what is the difference to relational databases?
© All rights reserved. Zend Technologies, Inc.
How do they look?
•Representation in Relational (Row Oriented) DB
•Representation in Column Oriented DB (CODB)
Introduction to Colum Oriented Databases in PHP5
© All rights reserved. Zend Technologies, Inc.
How do they look? (2)
•Table http://labs.google.com/papers/bigtable.html
Associative array
Sparse
Multidimensional
Distributed
Persistent
Sorted
Introduction to Colum Oriented Databases in PHP6
© All rights reserved. Zend Technologies, Inc.
How do they look? (3)
•Column Families
Family – columnA, columnB,…
Qualifier – one, two, three
Three dimensions + 1
• Row, Family, Qualifier
• +1 more dimension: time
Introduction to Colum Oriented Databases in PHP7
© All rights reserved. Zend Technologies, Inc.
Why New Type Of Database?
… and aren’t the relational databases enough?
© All rights reserved. Zend Technologies, Inc.
Why New Type Of Database?
9 Introduction to Colum Oriented Databases in PHP
2001 / 1 server, PHP and MySQL / 200 users
2002 / 2 PHP machines, 1 MySQL machine / 2k users
PHP PHP
MySQL
PHP
MySQL
2003 / 4+ PHP machines, 1 MySQL machine /20k users
© All rights reserved. Zend Technologies, Inc.
Why New Type Of Database?(2)
•Problem 1:
The Db is not scalable
2x more powerful machine brings less than 1,5x performance
boost and costs a lot
•Solution 1:
Sharding
• Move different tables to different DBs
• Splits one table by row into two or more tables on different DB
machines
Using commodity software
10 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Why New Type Of Database?(3)
•Sharding has to be done on the client
MySQL and other relational DBs do not support sharding on the
server side
•Problem 2:
The PHP code becomes complex
• Difficult to use and understand
Resizing the shards is manual painful work
Sorting and merging of data becomes real problem
For speed more data needs to be redundant
Joins between shards are almost impossible
11 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Why New Type Of Database?(4)
•Example:
Prerequisites:
• Social web site.
• Every user has friends. Not all friends in one shard
• Every user has activity: adding a comment, blog post, image upload,
etc.
• Every user has avatar icon and name
Give me the last 20 activities from my friends
• Sound simple, right?
12 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Why New Type Of Database?(5)
•Example (cont’d):
Give me the last 20 activities from my friends
• Here is how it is done:
– Get the list of friends for an user
– Get information about the friends – name, avatar, shard
– Group the friends in shards
– For each shard get the last 20 activities per friend
– In PHP merge all the incoming data and sort it by date so that the first
20 show up
For this 20 results the PHP needs (quite often)
• 60 or more MB RAM
• >10 seconds CPU time
13 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Why New Type Of Database?(6)
•Activity table as a CODB table
•And in CODB you have to do
SCAN activity, { COLUMNS=“friends:0000001”, LIMIT=20}
•Be patient, the details are in the next slides
14 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
The Details
… must-know when designing a table
15Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
The Details
•There are no joins between tables.
•The row keys are always sorted in alphabetical order
•The type of the column value is always string, unless a
counter
•The generation of the row key is very important
There is no auto-increment of the key
No key constraints (no primary, no unique, etc)
16 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
The Details (2)
•The generation of the row key is very important (2)
The fastest search is by using the row key
• Secondary indexes are “almost” not supported
One cannot search in the value of the columns
• Nothing like columnB=“de”
But can search if a column family exists:
• “columA:one”
17 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Supported Operations
… list of the most important ones
18Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Supported Operations
•CREATE – creating a table
CREATE tableName, columnA, columnB, columnC
Plus options to the table column families:
• Versions – how many versions of the cell value to keep
• In Memory – if the cell value should be kept in memory for faster
search
• Counter – if the column family will be used for autonomous
increment and decrement
– The value of the cell is integer and adding or decreasing the value is
thread-safe (no race conditions)
• Compression – good for storing, bad for searching
19 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Supported Operations(2)
•PUT – for adding a cell
PUT table „rowKey‟, „columnFamilyKey‟, „value‟
• PUT table „row1‟,‟columnA:one‟, „eins‟
• PUT table „row1‟,‟columnA:two‟, „zwei‟
• PUT table „row1‟,‟columnA:three‟, „drei‟
• PUT table „row1‟,‟columnB‟, „de‟
• PUT table „row1‟,‟columnC‟, „German‟
•GET – get row by its row key value
GET table, „rowKey‟, { COLUMNS, VERSIONS}
• GET table, „row2‟, { „columnB:one‟}
20 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Supported Operations(3)
•There is no UPDATE!
•DELETE – for deleting a cell or complete row
DELETE table, „rowKey‟, „columnFamilyKey‟ – for a cell
DELETE table, „rowKey‟
•SCAN – find rows
SCAN table, {COLUMNS=array(), LIMIT=<int>, STARTROW=string,
STOPROW
• SCAN table, { COLUMNS=[„columnB:one‟]}
– Returns all rows that have the cell column family B and qualifier one
• SCAN table, { STARTROW=„ro‟, STOPROW=„row3‟}
- Returns all rows for which the row key starts with ro and ends with row3
21 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Available Open Source
CODB engines
… as of today
22Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Available Open Source CODB engines
•Hbase
Uses Hadoop as distributed storage backend
Written in Java
Large community base
No single point of failure (ZooKeeper)
•Hypertable
Also Hadoop
Written in C
• May be faster and less memory/CPU intensive
Smaller community base
No single point of failure (Own manager for the Zoo)
23 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Putting Everything
Together
… without PHP
© All rights reserved. Zend Technologies, Inc.
Putting Everything Together
•Activity table
•SCAN activity, { COLUMNS=“friends:0000001”, LIMIT=20}
•The result
Sorted by key
Limited to 20 results
Taken, as if, from one server (no extra sharding logic)
25 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Putting Everything Together(2)
•SCAN activity, { COLUMNS=“friends:0000001”, LIMIT=20}
•What needs to be done additionally is:
Get the user data for your friends and merge it in PHP
26 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
How To Use It From
PHP
… some code examples
27Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
How To Use It From PHP
•Activity as an ActiveRecord
28 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
How To Use It From PHP(2)
•ActiveRecord
29 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
How To Use It From PHP (3)
•The PHP code is much simpler
•Resizing the shards is done automatically and transparently
If the load gets high just add new CODB server
•Failover, no single point of failure
•Sorting is fast
•Merging of the data, if the table is well-designed, is also
fasts
30 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Is CODB For Me?
… who should use it
31Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Is CODB For Me?
•Require a lot of memory and hard disk space
More redundant, more de-normalized
Rational DBs have decades of optimizations behind them
Does not makes sense to use it for small websites
• Although this may change if CODB becomes main stream
•Not for a bank system
No transaction safety
Can be partially/eventually consistent
•Works fine if the final result is a relatively small set of data
32 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Thank you very much
… questions anyone?
© All rights reserved. Zend Technologies, Inc.
References
• BigTable paper: http://labs.google.com/papers/bigtable.html
• Hypertable: http://hypertable.org/
• Apache Hbase: http://hbase.apache.org/
• Apache Hadoop: http://hadoop.apache.org/
• Sharding:
http://en.wikipedia.org/wiki/Shard_(database_architecture)
• Active Record Pattern:
http://en.wikipedia.org/wiki/Active_record_pattern
34 Introduction to Colum Oriented Databases in PHP
© All rights reserved. Zend Technologies, Inc.
Webinar
To watch the webinar please go to:
http://www.zend.com/en/webinar/PHP/70170000000bZ2X-
CODB-20110708.flv
Or
http://bit.ly/qaB0w0
(a short registration is required)
35Insert->Header & Footer

Mais conteúdo relacionado

Mais procurados

Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014
soujavajug
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Muhamad Al Imran
 

Mais procurados (20)

DB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iDB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM i
 
Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014
 
Strategic Modernization with PHP on IBM i
Strategic Modernization with PHP on IBM iStrategic Modernization with PHP on IBM i
Strategic Modernization with PHP on IBM i
 
Preparing an Open Source Documentation Repository for Translations
Preparing an Open Source Documentation Repository for TranslationsPreparing an Open Source Documentation Repository for Translations
Preparing an Open Source Documentation Repository for Translations
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Install MariaDB on IBM i - Tips, troubleshooting, and more
Install MariaDB on IBM i - Tips, troubleshooting, and moreInstall MariaDB on IBM i - Tips, troubleshooting, and more
Install MariaDB on IBM i - Tips, troubleshooting, and more
 
PHP Installed on IBM i - the Nickel Tour
PHP Installed on IBM i - the Nickel TourPHP Installed on IBM i - the Nickel Tour
PHP Installed on IBM i - the Nickel Tour
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Getting started with PHP on IBM i
Getting started with PHP on IBM iGetting started with PHP on IBM i
Getting started with PHP on IBM i
 
Rest style web services (google protocol buffers) prasad nirantar
Rest style web services (google protocol buffers)   prasad nirantarRest style web services (google protocol buffers)   prasad nirantar
Rest style web services (google protocol buffers) prasad nirantar
 
Sizing your alfresco platform
Sizing your alfresco platformSizing your alfresco platform
Sizing your alfresco platform
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
HDF5 Backward and Forward Compatibility Issues
HDF5 Backward and Forward Compatibility IssuesHDF5 Backward and Forward Compatibility Issues
HDF5 Backward and Forward Compatibility Issues
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
 
Web Performance First Aid
Web Performance First AidWeb Performance First Aid
Web Performance First Aid
 
IBM i: Fertile Ground for PHP Developers
IBM i: Fertile Ground for PHP DevelopersIBM i: Fertile Ground for PHP Developers
IBM i: Fertile Ground for PHP Developers
 
De-Mystifying the Apache Phoenix QueryServer
De-Mystifying the Apache Phoenix QueryServerDe-Mystifying the Apache Phoenix QueryServer
De-Mystifying the Apache Phoenix QueryServer
 
Scale your Alfresco Solutions
Scale your Alfresco Solutions Scale your Alfresco Solutions
Scale your Alfresco Solutions
 

Semelhante a Introduction to column oriented databases in PHP

First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
Tomas Cervenka
 
Challenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on HadoopChallenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on Hadoop
DataWorks Summit
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
Ricard Clau
 

Semelhante a Introduction to column oriented databases in PHP (20)

2020 oct zowe quarterly webinar series
2020 oct zowe quarterly webinar series2020 oct zowe quarterly webinar series
2020 oct zowe quarterly webinar series
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructure
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
 
Toward Hybrid Cloud Serverless Transparency with Lithops Framework
Toward Hybrid Cloud Serverless Transparency with Lithops FrameworkToward Hybrid Cloud Serverless Transparency with Lithops Framework
Toward Hybrid Cloud Serverless Transparency with Lithops Framework
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
 
Zend Code in ZF 2.0
Zend Code in ZF 2.0Zend Code in ZF 2.0
Zend Code in ZF 2.0
 
Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)
 
MongoDB: What, why, when
MongoDB: What, why, whenMongoDB: What, why, when
MongoDB: What, why, when
 
BTV PHP - Building Fast Websites
BTV PHP - Building Fast WebsitesBTV PHP - Building Fast Websites
BTV PHP - Building Fast Websites
 
Challenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on HadoopChallenges of Implementing an Advanced SQL Engine on Hadoop
Challenges of Implementing an Advanced SQL Engine on Hadoop
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
 
SQL Engines for Hadoop - The case for Impala
SQL Engines for Hadoop - The case for ImpalaSQL Engines for Hadoop - The case for Impala
SQL Engines for Hadoop - The case for Impala
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Debugging with Zend Studio for Eclipse
Debugging with Zend Studio for EclipseDebugging with Zend Studio for Eclipse
Debugging with Zend Studio for Eclipse
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
 
High Performance Machine Learning in R with H2O
High Performance Machine Learning in R with H2OHigh Performance Machine Learning in R with H2O
High Performance Machine Learning in R with H2O
 
REDIS327
REDIS327REDIS327
REDIS327
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
 

Mais de Zend by Rogue Wave Software

Mais de Zend by Rogue Wave Software (20)

Develop microservices in php
Develop microservices in phpDevelop microservices in php
Develop microservices in php
 
Speed and security for your PHP application
Speed and security for your PHP applicationSpeed and security for your PHP application
Speed and security for your PHP application
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
 
Building web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend ExpressiveBuilding web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend Expressive
 
To PHP 7 and beyond
To PHP 7 and beyondTo PHP 7 and beyond
To PHP 7 and beyond
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
 
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
 
Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)
 
Middleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.xMiddleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.x
 
Ongoing management of your PHP 7 application
Ongoing management of your PHP 7 applicationOngoing management of your PHP 7 application
Ongoing management of your PHP 7 application
 
Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7
 
The Docker development template for PHP
The Docker development template for PHPThe Docker development template for PHP
The Docker development template for PHP
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Unit testing for project managers
Unit testing for project managersUnit testing for project managers
Unit testing for project managers
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Deploying PHP apps on the cloud
Deploying PHP apps on the cloudDeploying PHP apps on the cloud
Deploying PHP apps on the cloud
 
Data is dead. Long live data!
Data is dead. Long live data! Data is dead. Long live data!
Data is dead. Long live data!
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
Resolving problems & high availability
Resolving problems & high availabilityResolving problems & high availability
Resolving problems & high availability
 
Developing apps faster
Developing apps fasterDeveloping apps faster
Developing apps faster
 

Último

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
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 

Introduction to column oriented databases in PHP

  • 1. © All rights reserved. Zend Technologies, Inc. Introduction to Column Oriented Databases in PHP By Slavey Karadzhov slavey.karadzhov@zend.com To watch the webinar please go to: http://www.zend.com/en/webinar/PHP/70170000000bZ2X- CODB-20110708.flv
  • 2. © All rights reserved. Zend Technologies, Inc. About Me •Name: Slavey Karadzhov (Славей Караджов) •Programmer since my early days •PHP programmer since 1999 •Open source fan and supporter •Hobby (software) inventor Won the best “IT Innovation of the Year 2004” from PC Magazine •Working for Zend Technologies since 2008 •In Stuttgart, Germany •As a programmer, consultant and trainer 2 Introduction to Colum Oriented Databases in PHP
  • 3. © All rights reserved. Zend Technologies, Inc. Agenda •How Do They Look? •Why New Type Of Database? •The Details •Supported Operations •Available Open Source CODB engines •Putting Everything Together •How To Use It From PHP •Is CODB For Me? •Questions 3 Introduction to Colum Oriented Databases in PHP
  • 4. © All rights reserved. Zend Technologies, Inc. How Do They Look? … and what is the difference to relational databases?
  • 5. © All rights reserved. Zend Technologies, Inc. How do they look? •Representation in Relational (Row Oriented) DB •Representation in Column Oriented DB (CODB) Introduction to Colum Oriented Databases in PHP5
  • 6. © All rights reserved. Zend Technologies, Inc. How do they look? (2) •Table http://labs.google.com/papers/bigtable.html Associative array Sparse Multidimensional Distributed Persistent Sorted Introduction to Colum Oriented Databases in PHP6
  • 7. © All rights reserved. Zend Technologies, Inc. How do they look? (3) •Column Families Family – columnA, columnB,… Qualifier – one, two, three Three dimensions + 1 • Row, Family, Qualifier • +1 more dimension: time Introduction to Colum Oriented Databases in PHP7
  • 8. © All rights reserved. Zend Technologies, Inc. Why New Type Of Database? … and aren’t the relational databases enough?
  • 9. © All rights reserved. Zend Technologies, Inc. Why New Type Of Database? 9 Introduction to Colum Oriented Databases in PHP 2001 / 1 server, PHP and MySQL / 200 users 2002 / 2 PHP machines, 1 MySQL machine / 2k users PHP PHP MySQL PHP MySQL 2003 / 4+ PHP machines, 1 MySQL machine /20k users
  • 10. © All rights reserved. Zend Technologies, Inc. Why New Type Of Database?(2) •Problem 1: The Db is not scalable 2x more powerful machine brings less than 1,5x performance boost and costs a lot •Solution 1: Sharding • Move different tables to different DBs • Splits one table by row into two or more tables on different DB machines Using commodity software 10 Introduction to Colum Oriented Databases in PHP
  • 11. © All rights reserved. Zend Technologies, Inc. Why New Type Of Database?(3) •Sharding has to be done on the client MySQL and other relational DBs do not support sharding on the server side •Problem 2: The PHP code becomes complex • Difficult to use and understand Resizing the shards is manual painful work Sorting and merging of data becomes real problem For speed more data needs to be redundant Joins between shards are almost impossible 11 Introduction to Colum Oriented Databases in PHP
  • 12. © All rights reserved. Zend Technologies, Inc. Why New Type Of Database?(4) •Example: Prerequisites: • Social web site. • Every user has friends. Not all friends in one shard • Every user has activity: adding a comment, blog post, image upload, etc. • Every user has avatar icon and name Give me the last 20 activities from my friends • Sound simple, right? 12 Introduction to Colum Oriented Databases in PHP
  • 13. © All rights reserved. Zend Technologies, Inc. Why New Type Of Database?(5) •Example (cont’d): Give me the last 20 activities from my friends • Here is how it is done: – Get the list of friends for an user – Get information about the friends – name, avatar, shard – Group the friends in shards – For each shard get the last 20 activities per friend – In PHP merge all the incoming data and sort it by date so that the first 20 show up For this 20 results the PHP needs (quite often) • 60 or more MB RAM • >10 seconds CPU time 13 Introduction to Colum Oriented Databases in PHP
  • 14. © All rights reserved. Zend Technologies, Inc. Why New Type Of Database?(6) •Activity table as a CODB table •And in CODB you have to do SCAN activity, { COLUMNS=“friends:0000001”, LIMIT=20} •Be patient, the details are in the next slides 14 Introduction to Colum Oriented Databases in PHP
  • 15. © All rights reserved. Zend Technologies, Inc. The Details … must-know when designing a table 15Introduction to Colum Oriented Databases in PHP
  • 16. © All rights reserved. Zend Technologies, Inc. The Details •There are no joins between tables. •The row keys are always sorted in alphabetical order •The type of the column value is always string, unless a counter •The generation of the row key is very important There is no auto-increment of the key No key constraints (no primary, no unique, etc) 16 Introduction to Colum Oriented Databases in PHP
  • 17. © All rights reserved. Zend Technologies, Inc. The Details (2) •The generation of the row key is very important (2) The fastest search is by using the row key • Secondary indexes are “almost” not supported One cannot search in the value of the columns • Nothing like columnB=“de” But can search if a column family exists: • “columA:one” 17 Introduction to Colum Oriented Databases in PHP
  • 18. © All rights reserved. Zend Technologies, Inc. Supported Operations … list of the most important ones 18Introduction to Colum Oriented Databases in PHP
  • 19. © All rights reserved. Zend Technologies, Inc. Supported Operations •CREATE – creating a table CREATE tableName, columnA, columnB, columnC Plus options to the table column families: • Versions – how many versions of the cell value to keep • In Memory – if the cell value should be kept in memory for faster search • Counter – if the column family will be used for autonomous increment and decrement – The value of the cell is integer and adding or decreasing the value is thread-safe (no race conditions) • Compression – good for storing, bad for searching 19 Introduction to Colum Oriented Databases in PHP
  • 20. © All rights reserved. Zend Technologies, Inc. Supported Operations(2) •PUT – for adding a cell PUT table „rowKey‟, „columnFamilyKey‟, „value‟ • PUT table „row1‟,‟columnA:one‟, „eins‟ • PUT table „row1‟,‟columnA:two‟, „zwei‟ • PUT table „row1‟,‟columnA:three‟, „drei‟ • PUT table „row1‟,‟columnB‟, „de‟ • PUT table „row1‟,‟columnC‟, „German‟ •GET – get row by its row key value GET table, „rowKey‟, { COLUMNS, VERSIONS} • GET table, „row2‟, { „columnB:one‟} 20 Introduction to Colum Oriented Databases in PHP
  • 21. © All rights reserved. Zend Technologies, Inc. Supported Operations(3) •There is no UPDATE! •DELETE – for deleting a cell or complete row DELETE table, „rowKey‟, „columnFamilyKey‟ – for a cell DELETE table, „rowKey‟ •SCAN – find rows SCAN table, {COLUMNS=array(), LIMIT=<int>, STARTROW=string, STOPROW • SCAN table, { COLUMNS=[„columnB:one‟]} – Returns all rows that have the cell column family B and qualifier one • SCAN table, { STARTROW=„ro‟, STOPROW=„row3‟} - Returns all rows for which the row key starts with ro and ends with row3 21 Introduction to Colum Oriented Databases in PHP
  • 22. © All rights reserved. Zend Technologies, Inc. Available Open Source CODB engines … as of today 22Introduction to Colum Oriented Databases in PHP
  • 23. © All rights reserved. Zend Technologies, Inc. Available Open Source CODB engines •Hbase Uses Hadoop as distributed storage backend Written in Java Large community base No single point of failure (ZooKeeper) •Hypertable Also Hadoop Written in C • May be faster and less memory/CPU intensive Smaller community base No single point of failure (Own manager for the Zoo) 23 Introduction to Colum Oriented Databases in PHP
  • 24. © All rights reserved. Zend Technologies, Inc. Putting Everything Together … without PHP
  • 25. © All rights reserved. Zend Technologies, Inc. Putting Everything Together •Activity table •SCAN activity, { COLUMNS=“friends:0000001”, LIMIT=20} •The result Sorted by key Limited to 20 results Taken, as if, from one server (no extra sharding logic) 25 Introduction to Colum Oriented Databases in PHP
  • 26. © All rights reserved. Zend Technologies, Inc. Putting Everything Together(2) •SCAN activity, { COLUMNS=“friends:0000001”, LIMIT=20} •What needs to be done additionally is: Get the user data for your friends and merge it in PHP 26 Introduction to Colum Oriented Databases in PHP
  • 27. © All rights reserved. Zend Technologies, Inc. How To Use It From PHP … some code examples 27Introduction to Colum Oriented Databases in PHP
  • 28. © All rights reserved. Zend Technologies, Inc. How To Use It From PHP •Activity as an ActiveRecord 28 Introduction to Colum Oriented Databases in PHP
  • 29. © All rights reserved. Zend Technologies, Inc. How To Use It From PHP(2) •ActiveRecord 29 Introduction to Colum Oriented Databases in PHP
  • 30. © All rights reserved. Zend Technologies, Inc. How To Use It From PHP (3) •The PHP code is much simpler •Resizing the shards is done automatically and transparently If the load gets high just add new CODB server •Failover, no single point of failure •Sorting is fast •Merging of the data, if the table is well-designed, is also fasts 30 Introduction to Colum Oriented Databases in PHP
  • 31. © All rights reserved. Zend Technologies, Inc. Is CODB For Me? … who should use it 31Introduction to Colum Oriented Databases in PHP
  • 32. © All rights reserved. Zend Technologies, Inc. Is CODB For Me? •Require a lot of memory and hard disk space More redundant, more de-normalized Rational DBs have decades of optimizations behind them Does not makes sense to use it for small websites • Although this may change if CODB becomes main stream •Not for a bank system No transaction safety Can be partially/eventually consistent •Works fine if the final result is a relatively small set of data 32 Introduction to Colum Oriented Databases in PHP
  • 33. © All rights reserved. Zend Technologies, Inc. Thank you very much … questions anyone?
  • 34. © All rights reserved. Zend Technologies, Inc. References • BigTable paper: http://labs.google.com/papers/bigtable.html • Hypertable: http://hypertable.org/ • Apache Hbase: http://hbase.apache.org/ • Apache Hadoop: http://hadoop.apache.org/ • Sharding: http://en.wikipedia.org/wiki/Shard_(database_architecture) • Active Record Pattern: http://en.wikipedia.org/wiki/Active_record_pattern 34 Introduction to Colum Oriented Databases in PHP
  • 35. © All rights reserved. Zend Technologies, Inc. Webinar To watch the webinar please go to: http://www.zend.com/en/webinar/PHP/70170000000bZ2X- CODB-20110708.flv Or http://bit.ly/qaB0w0 (a short registration is required) 35Insert->Header & Footer