Your SlideShare is downloading. ×
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,330
views

Published on

Published in: Technology

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,330
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
197
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
    • 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
  • 6.
    • Question
      • How can we store our data?
    • Answer
      • Relational database
    • ACID is our love
      • 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.
    Relational database in our world Part 1
  • 10.
    • Brewer's (CAP) Theorem
      • C: Consistency - The client perceives that a set of operations has occurred all at once.
        • Strong consistency: ACID
      • A: Availability - Every operation must terminate in an intended response. Requests are to be served even when there is a partition in the cluster.
      • P: Partition tolerance - Operations will complete, even if individual components are unavailable.
    Relational database in our world
  • 11.
    • BASE: An ACID Alternative
      • Basically Available
      • 12. Soft state
      • 13. Eventually consistent.
    • Data partitioning and decision between Consistency and Availability .
    Relational database in our world
  • 14.
    • Relational database in high performance environments
    FAILED?
    • … but most companies does not need more than a single database server
    • … but modern web apps today is facing a real challenge
    Relational database in our world
  • 19. High performance web apps: new challenges
    • Web server is bottleneck
    Part 2
  • 20.
    • Database is bottleneck
    High performance web apps: new challenges
  • 21.
    • CPU is bottleneck
    High performance web apps: new challenges
  • 22.
    • More requests: going distributed is easy
    • Database scalability is hard
      • Struggling with SMP: MySQL
      • 24. Replication is hard: replication is single threaded: MySQL
      • 25. Most relational databases find hard to scale WRITEs
    High performance web apps: new challenges
  • 30.
    • Scaling for READ is easier for scaling for WRITE
    • 31. E.x: Records inserted in 14h
    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.
    • Relational databases is SLOW in some speical cases
    • 33. Alternatives but not drop-in solutions
      • Document oriented databases
      • 34. Column-based databases
      • 35. Key-value datastores
      • 36. Graph databases
    High performance web apps: new challenges
  • 37. REDIS: A data structure datastore
    • 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
    http://code.google.com/p/redis/ Part 3
  • 43.
    • Redis is fast
    REDIS: A data structure datastore
  • 44.
    • In a most basic form, it is a key – value store
      • Not yet another Memcached
        • Not memory only
        • 45. Not immediately durable
        • 46. Redis VM (upcoming)
        • 47. Supports set of complicated data structure
        • 48. Built-in replication
    REDIS: A data structure datastore
  • 49.
    • Data can be partitioned using database concept
      • SELECT index
    REDIS: A data structure datastore
  • 50.
    • Key => Value
      • SET mykey myvalue
      • 51. GET mykey
      • 52. SETNX (atomic operation)
      • 53. More: MGET, MSET
    • Key or Value is binary safe
    REDIS: A data structure datastore
  • 54.
    • 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
      • RPUSH mylistkey string
      • 57. LPUSH mylistkey string
      • 58. LLEN mylistkey
      • 59. LPOP mylistkey
      • 60. RPOP mylistkey
      • 61. More: LGET/LSET ...
    REDIS: A data structure datastore
  • 62.
    • SET in Redis is an unordered collection with no duplicate members
      • SET commands
        • SADD mysetkey member
        • 63. SREM mysetkey member
        • 64. SMEMBERS mysetkey
    • Sorted SET : similar to SET but every member is attached with a score (floating number score)
      • Sorted Set commands
        • ZADD key score member
        • 65. ZREM key member
        • 66. ZRANGE key start end
    REDIS: A data structure datastore
  • 67.
    • Use cases
      • Operational data
      • 68. Pre-computed data
      • 69. Logging
      • 70. Cache
      • 71. Message queue
        • Immediate data layer
      • Job server
    REDIS: A data structure datastore
  • 72. Redis PHP clients
    • Owlient's phpredis
      • Can be found at http://github.com/owlient/phpredis
      • 73. C extension
      • 74. Sample
        • Class: Redis
        • 75. Key-value
          • $redis->get('key');
          • 76. $redis->set('key', 'value');
          • 77. $redis->incr('key1');
        • List
          • $redis->lpush('key1', 'C');
        • Set
          • $redis->sadd('key1' , 'set1');
    Part 4
  • 78.
    • Rediska: http://rediska.geometria-lab.net/
    • 79. Full Zend Framework integration
    • 80. Sample
    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.
    • 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
    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

×