Skip to content

Instantly share code, notes, and snippets.

@patriknw
patriknw / AgentStmSample.scala
Created April 26, 2011 12:12
Agent with STM
package agent
import akka.agent.Agent
import akka.stm._
object AgentStmSample {
def transfer(from: Agent[Int], to: Agent[Int], amount: Int): Boolean = {
atomic {
if (from.get < amount) false
@patriknw
patriknw / Sample.scala
Created January 22, 2012 12:42
FaultHandling Sample
package sample
import akka.actor.Actor
import akka.actor.Props
import akka.dispatch.Await
import akka.util.duration._
import akka.util.Timeout
import akka.actor.ActorRef
import akka.actor.Terminated
import akka.actor.ActorSystem
@patriknw
patriknw / AkkaConfigBean.scala
Created February 9, 2012 09:21
Illustrates a POJO API on top of Config
package akka.config.bean
import java.util.{ List ⇒ JList }
import java.util.{ ArrayList ⇒ JArrayList }
import java.util.{ HashMap ⇒ JHashMap }
import scala.reflect.BeanProperty
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
class AkkaConfigBean {
@patriknw
patriknw / gist:1826673
Created February 14, 2012 13:10
TellThroughputPerformanceSpec
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"
@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 / 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 / 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 / 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 / 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))