View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
RWN Math• R – Number of nodes that are read from.• W – Number of nodes that are written to.• N – Total number of nodes in the cluster.• In general: R < N and W < N for higher availability
R+W>N• Easy to determine consistent state• R + W = 2N • absolutely consistent, can provide ACID gaurantee• In all cases when R + W > N there is some overlap between read and write nodes.
R = 1, W = N• more reads than writes•W=N • 1 node failure = entire system unavailable
R = N, W =1•W=N • Chance of data inconsistency quite high•R=N • Read only possible when all nodes in the cluster are available
R = W = ceiling ((N + 1)/2)Effective quorum for eventual consistency
Eventual consistency variants• Causal consistency -- A writes and informs B then B always sees updated value• Read-your-writes-consistency -- A writes a new value and never see the old one• Session consistency -- read-your-writes-consistency within a client session• Monotonic read consistency -- once seen a new value, never return previous value• Monotonic write consistency -- serialize writes by the same process
Dynamo Techniques• Consistent Hashing (Incremental scalability)• Vector clocks (high availability for writes)• Sloppy quorum and hinted handoff (recover from temporary failure)• Gossip based membership protocol (periodic, pair wise, inter-process interactions, low reliability, random peer selection)• Anti-entropy using Merkle trees• (source: http://s3.amazonaws.com/AllThingsDistributed/sosp/amazon- dynamo-sosp2007.pdf)
Vector clocks (a trivial example)• 4 hackers: Joe, Hillary, Eric and Ajay decide to meetup• Joe -- suggests Palo Alto (t0)• Hillary and Eric -- decide to meet in Mountain View (t1)• Eric and Ajay -- decide to meet in Los Altos (t2)• Joe mails: PA, Hillary responds: Mtn View, Ajay responds: Los Altos (t3) • both Hillary and Ajay say: Eric knows
Vector clocks (how it works)• Venue : Palo Alto• Vector Clock: Joe (ver 1)• Venue: Mountain View• Vector Clock: Joe (ver 1), Hillary (ver 1), Eric (ver 1)• Venue: Los Altos• Vector Clock: Joe (ver 1), Ajay (ver 1), Eric (ver 1)
Vector clock (resolution)• Venue : Palo Alto• Vector Clock: Joe (ver 1)• Venue: Mountain View• Vector Clock: Joe (ver 1), Hillary (ver 1), Ajay (ver 0), Eric (ver 2)• Venue: Los Altos• Vector Clock: Joe (ver 1), Hillary (ver 0), Ajay (ver 1), Eric (ver 1)
Download and install• curl -O http://redis.googlecode.com/ﬁles/redis-2.2.0-rc4.tar.gz • (just a 436kb download)• tar zxvf redis-2.2.0-rc4.tar.gz• cd redis-2.2.0-rc4• make & make install (installs in /usr/local/bin)• make test (to be sure you install it correctly)
Start the redis-server• /usr/local/bin/redis-server• ...Server started, Redis version 2.1.12• ...The server is now ready to accept connections on port 6379
Connect with redis-cli• /usr/local/bin/redis-cli• redis> set key1 val1• OK• redis> get key1• "val1"
String key-value pairs• like memcached • with persistence• key and value -- binary-safe strings
Binary-safe?• redis> set "a key _" "another value"• OK• redis> get "a key _"• "another value"