Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Utah PHP Users Group - 2012

2,152 views

Published on

Introduction slide deck to Riak using the PHP client.

Published in: Technology
  • Login to see the comments

  • Be the first to like this

Utah PHP Users Group - 2012

  1. 1. Intro to Riak
  2. 2. Randy Secrist @randysecristrsecrist@basho.com
  3. 3. _Intro to Riak
  4. 4. Riak is a Database
  5. 5. Riak is Open Source http://git.io/basho http://git.io/riak http://git.io/riak_core http://git.io/riak_kv
  6. 6. Riak is Eventually
  7. 7. Eventual ...Consistency
  8. 8. CAP• Consistency• Availability• Partitioning
  9. 9. BASE• Basically• Available• Soft• State
  10. 10. Riak’s Strong Areas• Availability• Partitioning
  11. 11. Riak is also ...
  12. 12. • Fault-Tolerant• Highly-Available• Geo Distributable, horizontally scaleable• Built for the Web
  13. 13. Fault-Tolerant• All nodes participate equally - no SPOF• All data is replicated• Cluster transparently survives ... • node failures • network partitions• Built on Erlang/OTP (designed for FT)
  14. 14. Highly-Available• Masterless: Any node can service client requests.• Fallbacks are used when nodes are down.• Always accepts read and write requests.• Per-Request Quorums
  15. 15. SCALES
  16. 16. Geo Distributable & Horizontally Scalable• Default configuration is in a cluster• Load and data are spread evenly• Add more nodes to get more X• Multi Data Center Replication*
  17. 17. Built for the Web• HTTP is default (but not only) interface• Does HTTP/REST well (see Webmachine)• Plays well with HTTP infrastructure - reverse proxy caches, load balancers, web servers.• Suitable for many web and mobile applications.
  18. 18. Riak Features
  19. 19. Native APIs
  20. 20. HTTP
  21. 21. Protocol Buffers
  22. 22. Client Libraries
  23. 23. Erlang
  24. 24. Ruby
  25. 25. Java
  26. 26. Python
  27. 27. PHPhttps://github.com/basho/riak-php-client
  28. 28. Many more client librarieshttp://wiki.basho.com/Client-Libraries.html
  29. 29. Querying• Key Value - get, put, delete • Value is mostly opaque (some metadata)• Secondary Indexes• Map Reduce• Links• Full Text Search (Lucene Style)
  30. 30. Storage Backends• Bitcask• LevelDB• Memory• Multi
  31. 31. Request Quorums• Every request contacts all replicas of key• N - number of replicas (default 3)• R - read quorum• W - write quorum
  32. 32. Hands on!Setting it Up!
  33. 33. brew install riak
  34. 34. /usr/local/bin/riak start
  35. 35. Use ‘join’ command to build a cluster
  36. 36. Main Config File etc/app.config
  37. 37. Rekonhttps://github.com/basho/rekon curl -s rekon.basho.com | sh or curl -s rekon.basho.com | node=node-addr:port sh
  38. 38. PHP Client Demo
  39. 39. Connecting to Riakrequire_once(riak-php-client/riak.php);$client = new RiakClient(127.0.0.1, 8098);
  40. 40. Buckets$bucket = $client->bucket(friends);
  41. 41. Writing Data$person = $bucket->newObject(‘jack’,array( ‘name’ => “Jack Bauer”, ‘age’ => 24, ‘hobbies’ => “Interrogation”));$person->store();
  42. 42. Getting Data$jack = $bucket->get(jack);$me = $bucket->get(randy);
  43. 43. Riak Objectsforeach ($me->data as $key =>$value) print($key);
  44. 44. PHP DocumentationReadme: http://git.io/pk5umAPHP Docs: http://git.io/9YYaKQ
  45. 45. s3:// compatible layer http://basho.com/products/riakcs
  46. 46. Thank You!
  47. 47. References• http://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed• http://www.odbms.org/blog/2012/08/on-eventual-consistency-an-interview-with-justin-sheehy/• http://pbs.cs.berkeley.edu/#demo• https://github.com/basho/riak-php-client/blob/master/README.md
  48. 48. Credits• Slides by Casey Rosenthal• Slides by Bryce Kerley
  49. 49. Consistent Hashing & The Ring
  50. 50. Consistent Hashing & The Ring• 160-bit integer keyspace 0 2 160/4 2 160/2
  51. 51. Consistent Hashing & The Ring• 160-bit integer keyspace• Divided into fixed 0 number of evenly-sized partitions 32 partitions 2 160/4 2 160/2
  52. 52. Consistent Hashing & The Ring node 0 node 1• 160-bit integer keyspace node 2• Divided into fixed 0 node 3 number of evenly-sized partitions• Partitions are claimed by 32 partitions 2 160/4 nodes in the cluster 2 160/2
  53. 53. Consistent Hashing & The Ring node 0 node 1• 160-bit integer keyspace node 2• Divided into fixed node 3 number of evenly-sized partitions• Partitions are claimed by nodes in the cluster• Replicas go to the N partitions following the key
  54. 54. Consistent Hashing & The Ring node 0 node 1• 160-bit integer keyspace node 2• Divided into fixed node 3 number of evenly-sized partitions• Partitions are claimed by nodes in the cluster N=3• Replicas go to the N partitions following the key hash(“utah/uphpu”)
  55. 55. Hinted Handoff
  56. 56. Hinted Handoff• Node fails X X X X X X X X
  57. 57. Hinted Handoff• Node fails X X• Requests go to fallback X X X X X X hash(“utah/uphpu”)
  58. 58. Hinted Handoff• Node fails• Requests go to fallback• Node comes back hash(“utah/uphpu”)
  59. 59. Hinted Handoff• Node fails• Requests go to fallback• Node comes back• “Handoff” - data returns to recovered node hash(“utah/uphpu”)
  60. 60. Hinted Handoff• Node fails• Requests go to fallback• Node comes back• “Handoff” - data returns to recovered node• Normal operations resume hash(“utah/uphpu”)
  61. 61. Riak ArchitectureErlang/OTP Runtime
  62. 62. Riak ArchitectureErlang/OTP Runtime Riak KV
  63. 63. Riak ArchitectureErlang/OTP Runtime Client APIs Riak KV
  64. 64. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Riak KV
  65. 65. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Riak KV
  66. 66. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Riak KV
  67. 67. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination Riak KV
  68. 68. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce Riak KV
  69. 69. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce Riak Core Riak KV
  70. 70. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing Riak Core Riak KV
  71. 71. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing membership Riak Core Riak KV
  72. 72. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff membership Riak Core Riak KV
  73. 73. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff membership node-liveness Riak Core Riak KV
  74. 74. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff gossip membership node-liveness Riak Core Riak KV
  75. 75. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff gossip membership node-liveness buckets Riak Core Riak KV
  76. 76. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff gossip membership node-liveness buckets Riak Core vnode master Riak KV
  77. 77. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff gossip membership node-liveness buckets Riak Core vnode master vnodes Riak KV
  78. 78. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff gossip membership node-liveness buckets Riak Core vnode master vnodes storage backend Riak KV
  79. 79. Riak ArchitectureErlang/OTP Runtime Client APIs HTTP Protocol Buffers Erlang local client Request Coordination get put delete map-reduce consistent hashing handoff gossip membership node-liveness buckets Riak Core vnode master vnodes JS Runtime storage backend Riak KV

×