Your SlideShare is downloading. ×
0
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Beyond relational database - Building high performance websites using Redis and PHP
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

6,412

Published on

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

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Beyond relational database Building high performance websites using Redis and PHP Pham Cong Dinh Software Developer Vega Corporation
  • 2. What I am talking about <ul><li>Relational database in our world
  • 3. High performance web apps: new challenges
  • 4. Redis: A data structure store
  • 5. Introduction to some Redis's PHP clients </li></ul>
  • 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. Consistency - Nothing in your transaction will violate the rules of the database. Integrity.
  • 8. Isolation - Each transaction operates independently of every other transaction.
  • 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. <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. <ul><li>BASE: An ACID Alternative </li><ul><li>Basically Available
  • 12. Soft state
  • 13. Eventually consistent. </li></ul><li>Data partitioning and decision between Consistency and Availability . </li></ul>Relational database in our world
  • 14. <ul><li>Relational database in high performance environments </li><ul><li>Google
  • 15. Facebook
  • 16. Wikipedia
  • 17. Live Journal
  • 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. High performance web apps: new challenges <ul><li>Web server is bottleneck </li></ul>Part 2
  • 20. <ul><li>Database is bottleneck </li></ul>High performance web apps: new challenges
  • 21. <ul><li>CPU is bottleneck </li></ul>High performance web apps: new challenges
  • 22. <ul><li>More requests: going distributed is easy </li><ul><li>Apache
  • 23. PHP </li></ul><li>Database scalability is hard </li><ul><li>Struggling with SMP: MySQL
  • 24. Replication is hard: replication is single threaded: MySQL
  • 25. Most relational databases find hard to scale WRITEs </li><ul><li>Schema constraints
  • 26. Disk I/O
  • 27. Memory constraints
  • 28. Global lock
  • 29. Complicated data types </li></ul></ul></ul>High performance web apps: new challenges
  • 30. <ul><li>Scaling for READ is easier for scaling for WRITE
  • 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. <ul><li>Relational databases is SLOW in some speical cases
  • 33. Alternatives but not drop-in solutions </li><ul><li>Document oriented databases
  • 34. Column-based databases
  • 35. Key-value datastores
  • 36. Graph databases </li></ul></ul>High performance web apps: new challenges
  • 37. REDIS: A data structure datastore <ul><li>Redis (REmote DIctionary Server)
  • 38. One of the hottest technologies in 2009 (Github)
  • 39. Network interface to language dependent client library: Python, Java, Ruby, Erlang, C# …
  • 40. Written in C, single process, single thread, event-based
  • 41. Latest version: 1.1
  • 42. Can be found at </li></ul>http://code.google.com/p/redis/ Part 3
  • 43. <ul><li>Redis is fast </li></ul>REDIS: A data structure datastore
  • 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. Not immediately durable
  • 46. Redis VM (upcoming)
  • 47. Supports set of complicated data structure
  • 48. Built-in replication </li></ul></ul></ul>REDIS: A data structure datastore
  • 49. <ul><li>Data can be partitioned using database concept </li><ul><li>SELECT index </li></ul></ul>REDIS: A data structure datastore
  • 50. <ul><li>Key => Value </li><ul><li>SET mykey myvalue
  • 51. GET mykey
  • 52. SETNX (atomic operation)
  • 53. More: MGET, MSET </li></ul><li>Key or Value is binary safe </li></ul>REDIS: A data structure datastore
  • 54. <ul><li>Redis supports manipulation on a list of values via LIST
  • 55. Think of an ordered list with the operations you would expect: appending , indexed access , and access to a range of values
  • 56. Command </li><ul><li>RPUSH mylistkey string
  • 57. LPUSH mylistkey string
  • 58. LLEN mylistkey
  • 59. LPOP mylistkey
  • 60. RPOP mylistkey
  • 61. More: LGET/LSET ... </li></ul></ul>REDIS: A data structure datastore
  • 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. SREM mysetkey member
  • 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. ZREM key member
  • 66. ZRANGE key start end </li></ul></ul></ul>REDIS: A data structure datastore
  • 67. <ul><li>Use cases </li><ul><li>Operational data
  • 68. Pre-computed data
  • 69. Logging
  • 70. Cache
  • 71. Message queue </li><ul><li>Immediate data layer </li></ul><li>Job server </li></ul></ul>REDIS: A data structure datastore
  • 72. Redis PHP clients <ul><li>Owlient's phpredis </li><ul><li>Can be found at http://github.com/owlient/phpredis
  • 73. C extension
  • 74. Sample </li><ul><li>Class: Redis
  • 75. Key-value </li><ul><li>$redis->get('key');
  • 76. $redis->set('key', 'value');
  • 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. <ul><li>Rediska: http://rediska.geometria-lab.net/
  • 79. Full Zend Framework integration
  • 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. <ul><li>Predis: http://github.com/nrk/predis
  • 82. PHP 5.3+ only
  • 83. Support PHP 5.3 namespace and functor
  • 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. Any question? Phần 5

×