Beyond relational database   Building high performance websites using Redis and PHP Pham Cong Dinh Software Developer Vega...
What I am talking about <ul><li>Relational database in our world
High performance web apps: new challenges
Redis: A data structure store
Introduction to some Redis's PHP clients </li></ul>
<ul><li>Question </li><ul><li>How can we store our data? </li></ul><li>Answer </li><ul><li>Relational database </li></ul><...
Consistency  - Nothing in your transaction will violate the rules of the database. Integrity.
Isolation  - Each transaction operates independently of every other transaction.
Durability  - Once the database says that data is committed there is no opportunity for that to be undone. </li></ul></ul>...
<ul><li>Brewer's (CAP) Theorem </li><ul><li>C: Consistency - The client perceives that a set of operations has occurred al...
<ul><li>BASE: An ACID Alternative  </li><ul><li>Basically Available
Soft state
Eventually consistent. </li></ul><li>Data partitioning and decision between  Consistency  and  Availability . </li></ul>Re...
<ul><li>Relational database in high performance environments </li><ul><li>Google
Facebook
Wikipedia
Live Journal
Yahoo </li></ul></ul>FAILED? <ul><li>… but most companies does not need  more than a single database server </li></ul><ul>...
High performance web apps: new challenges  <ul><li>Web server is bottleneck </li></ul>Part 2
<ul><li>Database is bottleneck </li></ul>High performance web apps: new challenges
<ul><li>CPU is bottleneck </li></ul>High performance web apps: new challenges
<ul><li>More requests: going distributed is easy </li><ul><li>Apache
PHP </li></ul><li>Database scalability is hard </li><ul><li>Struggling with SMP: MySQL
Replication is hard: replication is single threaded: MySQL
Upcoming SlideShare
Loading in...5
×

Beyond relational database - Building high performance websites using Redis and PHP

6,459

Published on

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,459
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
202
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Transcript of "Beyond relational database - Building high performance websites using Redis and PHP"

  1. 1. Beyond relational database Building high performance websites using Redis and PHP Pham Cong Dinh Software Developer Vega Corporation
  2. 2. What I am talking about <ul><li>Relational database in our world
  3. 3. High performance web apps: new challenges
  4. 4. Redis: A data structure store
  5. 5. Introduction to some Redis's PHP clients </li></ul>
  6. 6. <ul><li>Question </li><ul><li>How can we store our data? </li></ul><li>Answer </li><ul><li>Relational database </li></ul><li>ACID is our love </li><ul><li>Atomicity - all parts of a transaction succeed or none of then succeed. Integrity.
  7. 7. Consistency - Nothing in your transaction will violate the rules of the database. Integrity.
  8. 8. Isolation - Each transaction operates independently of every other transaction.
  9. 9. Durability - Once the database says that data is committed there is no opportunity for that to be undone. </li></ul></ul>Relational database in our world Part 1
  10. 10. <ul><li>Brewer's (CAP) Theorem </li><ul><li>C: Consistency - The client perceives that a set of operations has occurred all at once. </li><ul><li>Strong consistency: ACID </li></ul></ul></ul><ul><ul><li>A: Availability - Every operation must terminate in an intended response. Requests are to be served even when there is a partition in the cluster. </li></ul></ul><ul><ul><li>P: Partition tolerance - Operations will complete, even if individual components are unavailable. </li></ul></ul>Relational database in our world
  11. 11. <ul><li>BASE: An ACID Alternative </li><ul><li>Basically Available
  12. 12. Soft state
  13. 13. Eventually consistent. </li></ul><li>Data partitioning and decision between Consistency and Availability . </li></ul>Relational database in our world
  14. 14. <ul><li>Relational database in high performance environments </li><ul><li>Google
  15. 15. Facebook
  16. 16. Wikipedia
  17. 17. Live Journal
  18. 18. Yahoo </li></ul></ul>FAILED? <ul><li>… but most companies does not need more than a single database server </li></ul><ul><li>… but modern web apps today is facing a real challenge </li></ul>Relational database in our world
  19. 19. High performance web apps: new challenges <ul><li>Web server is bottleneck </li></ul>Part 2
  20. 20. <ul><li>Database is bottleneck </li></ul>High performance web apps: new challenges
  21. 21. <ul><li>CPU is bottleneck </li></ul>High performance web apps: new challenges
  22. 22. <ul><li>More requests: going distributed is easy </li><ul><li>Apache
  23. 23. PHP </li></ul><li>Database scalability is hard </li><ul><li>Struggling with SMP: MySQL
  24. 24. Replication is hard: replication is single threaded: MySQL
  25. 25. Most relational databases find hard to scale WRITEs </li><ul><li>Schema constraints
  26. 26. Disk I/O
  27. 27. Memory constraints
  28. 28. Global lock
  29. 29. Complicated data types </li></ul></ul></ul>High performance web apps: new challenges
  30. 30. <ul><li>Scaling for READ is easier for scaling for WRITE
  31. 31. E.x: Records inserted in 14h </li></ul>High performance web apps: new challenges mysql> select count(1) from setacc; +----------+ | count(1) | +----------+ | 3982438 | +----------+ 1 row in set (0.00 sec) mysql> select count(1) from setacc_del; +----------+ | count(1) | +----------+ | 4003793 | +----------+ 1 row in set (0.00 sec)
  32. 32. <ul><li>Relational databases is SLOW in some speical cases
  33. 33. Alternatives but not drop-in solutions </li><ul><li>Document oriented databases
  34. 34. Column-based databases
  35. 35. Key-value datastores
  36. 36. Graph databases </li></ul></ul>High performance web apps: new challenges
  37. 37. REDIS: A data structure datastore <ul><li>Redis (REmote DIctionary Server)
  38. 38. One of the hottest technologies in 2009 (Github)
  39. 39. Network interface to language dependent client library: Python, Java, Ruby, Erlang, C# …
  40. 40. Written in C, single process, single thread, event-based
  41. 41. Latest version: 1.1
  42. 42. Can be found at </li></ul>http://code.google.com/p/redis/ Part 3
  43. 43. <ul><li>Redis is fast </li></ul>REDIS: A data structure datastore
  44. 44. <ul><li>In a most basic form, it is a key – value store </li><ul><li>Not yet another Memcached </li><ul><li>Not memory only
  45. 45. Not immediately durable
  46. 46. Redis VM (upcoming)
  47. 47. Supports set of complicated data structure
  48. 48. Built-in replication </li></ul></ul></ul>REDIS: A data structure datastore
  49. 49. <ul><li>Data can be partitioned using database concept </li><ul><li>SELECT index </li></ul></ul>REDIS: A data structure datastore
  50. 50. <ul><li>Key => Value </li><ul><li>SET mykey myvalue
  51. 51. GET mykey
  52. 52. SETNX (atomic operation)
  53. 53. More: MGET, MSET </li></ul><li>Key or Value is binary safe </li></ul>REDIS: A data structure datastore
  54. 54. <ul><li>Redis supports manipulation on a list of values via LIST
  55. 55. Think of an ordered list with the operations you would expect: appending , indexed access , and access to a range of values
  56. 56. Command </li><ul><li>RPUSH mylistkey string
  57. 57. LPUSH mylistkey string
  58. 58. LLEN mylistkey
  59. 59. LPOP mylistkey
  60. 60. RPOP mylistkey
  61. 61. More: LGET/LSET ... </li></ul></ul>REDIS: A data structure datastore
  62. 62. <ul><li>SET in Redis is an unordered collection with no duplicate members </li><ul><li>SET commands </li><ul><li>SADD mysetkey member
  63. 63. SREM mysetkey member
  64. 64. SMEMBERS mysetkey </li></ul></ul><li>Sorted SET : similar to SET but every member is attached with a score (floating number score) </li><ul><li>Sorted Set commands </li><ul><li>ZADD key score member
  65. 65. ZREM key member
  66. 66. ZRANGE key start end </li></ul></ul></ul>REDIS: A data structure datastore
  67. 67. <ul><li>Use cases </li><ul><li>Operational data
  68. 68. Pre-computed data
  69. 69. Logging
  70. 70. Cache
  71. 71. Message queue </li><ul><li>Immediate data layer </li></ul><li>Job server </li></ul></ul>REDIS: A data structure datastore
  72. 72. Redis PHP clients <ul><li>Owlient's phpredis </li><ul><li>Can be found at http://github.com/owlient/phpredis
  73. 73. C extension
  74. 74. Sample </li><ul><li>Class: Redis
  75. 75. Key-value </li><ul><li>$redis->get('key');
  76. 76. $redis->set('key', 'value');
  77. 77. $redis->incr('key1'); </li></ul><li>List </li><ul><li>$redis->lpush('key1', 'C'); </li></ul><li>Set </li><ul><li>$redis->sadd('key1' , 'set1'); </li></ul></ul></ul></ul>Part 4
  78. 78. <ul><li>Rediska: http://rediska.geometria-lab.net/
  79. 79. Full Zend Framework integration
  80. 80. Sample </li></ul>Redis PHP clients require_once 'Rediska/Key.php'; $key = new Rediska_Key('keyName'); // Set value $key->setValue('hello'); // Get value $key = new Rediska_Key('keyName'); $key->getValue(); #=> hello
  81. 81. <ul><li>Predis: http://github.com/nrk/predis
  82. 82. PHP 5.3+ only
  83. 83. Support PHP 5.3 namespace and functor
  84. 84. Support multiple Redis instances and pipelining </li></ul>Redis PHP clients $redis = PredisClient::create( array('host' => '10.0.0.1', 'port' => 6379), array('host' => '10.0.0.2', 'port' => 6379) ); $replies = $redis->pipeline(function($pipe) { for ($i = 0; $i < 1000; $i++) { $pipe->set(&quot;key:$i&quot;, str_pad($i, 4, '0', 0)); $pipe->get(&quot;key:$i&quot;); } });
  85. 85. Any question? Phần 5
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×