Skip to content

Instantly share code, notes, and snippets.

@patriknw
patriknw / ClusterWatch.scala
Created October 8, 2012 13:12
Spotlight for Cluster Death Watch
case object BackendRegistration
case class Job(text: String)
class Frontend extends Actor {
var backends = IndexedSeq.empty[ActorRef]
var jobCounter = 0
def receive = {
case job: Job if backends.isEmpty =>
@patriknw
patriknw / ClusterListener.scala
Created October 8, 2012 12:48
Spotlight for Cluster Membership
import akka.cluster.Cluster
import akka.cluster.ClusterEvent._
val clusterListener = system.actorOf(Props(new Actor with ActorLogging {
def receive = {
case state: CurrentClusterState ⇒
log.info("Current members: {}", state.members)
case MemberUp(member) ⇒
log.info("Member is up: {}", member)
// send a message to the "world" actor running at the member node
@patriknw
patriknw / ClusterRouter.conf
Created October 8, 2012 12:15
Spotlight for Cluster Aware Routers
akka.actor.deployment {
/statsService/workerRouter {
router = round-robin
nr-of-instances = 100
cluster {
enabled = on
routees-path = "/user/statsWorker"
}
}
}
@patriknw
patriknw / ConsistentHashingRouterSpotlight.scala
Created October 3, 2012 12:16
Spotlight for ConsistentHashingRouter
import akka.routing.ConsistentHashingRouter
import akka.routing.ConsistentHashingRouter.ConsistentHashMapping
import akka.actor.Actor
import akka.pattern.ask
case class Entry(key: String, value: String)
class Cache extends Actor {
var cache = Map.empty[String, String]
@patriknw
patriknw / CircuitBreakerSpotlight.scala
Created October 3, 2012 11:19
Circuit Breaker Spotlight
import akka.pattern.CircuitBreaker
val breaker =
CircuitBreaker(system.scheduler,
maxFailures = 5,
callTimeout = 10.seconds,
resetTimeout = 1.minute)
def dangerous: Future[String] =
breaker.withCircuitBreaker(Future(dangerousCall))
@patriknw
patriknw / RouterPerf.scala
Created September 14, 2012 08:07
Microbenchmark of akka routers
package perf
import akka.actor.ActorSystem
import akka.actor.Actor
import akka.actor.Props
import scala.concurrent.forkjoin.ThreadLocalRandom
import akka.routing.ConsistentHashingRouter
import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope
import scala.util.Random
import akka.routing.Broadcast
@patriknw
patriknw / ClusterDemoSpec.scala
Created July 6, 2012 09:59
Sample of akka cluster test
package akka.cluster
import com.typesafe.config.ConfigFactory
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.testkit._
import akka.util.duration._
import akka.cluster.MemberStatus._
object ClusterDemoMultiJvmSpec extends MultiNodeConfig {
@patriknw
patriknw / RouterApp.scala
Created May 21, 2012 19:07
Mailinglist question about watching routees for termination
package question
import java.io.IOException
import scala.util.Random
import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.OneForOneStrategy
@patriknw
patriknw / TellThroughputPerformanceSpec2.scala
Created April 2, 2012 18:56
TellThroughputPerformanceSpec used for the 50 million msg/s test
case object Run
case object Msg
class Destination extends Actor {
def receive = {
case Msg ⇒ sender ! Msg
}
}
class Client(
@patriknw
patriknw / sbt-benchmark.sh
Created March 9, 2012 11:13
Example of sbt launch script for akka benchmarks
#!/bin/sh
# Run the benchmark with this as sbt start script,
# but change the paths (/home/nordwall)
# ~/bin/sbt-benchmark.sh
# > project akka-actor-tests
# > test-only akka.performance.microbench.TellThroughputPerformanceSpec
export JAVA=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
export FLAGS="-server -Dfile.encoding=UTF8 -XX:+UseNUMA -XX:+UseCondCardMark -XX:-UseBiasedLocking"