A simple demonstration of sharding in an HTTP based system in Scala using Twitter's Finagle library in support of my talk at Mostly Functional in August 2013.
The talk itself is now up on Slideshare.
Note that this is in no way intended as production code and in particular omits any form of error checking or handling in order to maximise clarity!
To build - on Mac at least - YMMV on other platforms:
- Install Scala and SBT - e.g. using Homebrew
- Run
sbt assembly
to create a convenient jar - For convenience
ln -s target/scala-2.10/simple-sharder.jar
To run a simple three shard system with a single worker in each shard:
java -cp simple-sharder.jar uk.co.geoffballinger.simplesharder.Worker 8080 foo &
java -cp simple-sharder.jar uk.co.geoffballinger.simplesharder.Worker 8081 bar &
java -cp simple-sharder.jar uk.co.geoffballinger.simplesharder.Worker 8082 baz &
java -cp simple-sharder.jar uk.co.geoffballinger.simplesharder.Sharder 8083 127.0.0.1:8080 127.0.0.1:8081 127.0.0.1:8082
Now in your browser try hitting the individual workers on port 8080, 8081, and 8082; followed by the whole system on port 8083.
Geoff Ballinger