Skip to content

Instantly share code, notes, and snippets.

@shijinkui
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save shijinkui/55f3206163fcb48ef045 to your computer and use it in GitHub Desktop.

Select an option

Save shijinkui/55f3206163fcb48ef045 to your computer and use it in GitHub Desktop.
import akka.actor.{Actor, ActorSystem, Props}
/**
* 平均每秒: 2500000
* cpu能跑满
* a sample
* Created by shijinkui on 15/1/15.
*/
class AkkaSample extends Actor {
val ct = System.currentTimeMillis()
override def receive: Receive = {
case m: Msg1 =>
println("11111: " + m)
self ! Msg2(m.id + 1)
case m: Msg2 =>
if (m.id % 1000000 == 0) {
val tm = (System.currentTimeMillis() - ct) / 1000
val second = if (tm > 0) tm else 1
println("avg: " + m.id / second)
}
self ! Msg2(m.id + 1)
}
}
object AkkaSample {
def main(args: Array[String]) {
val system = ActorSystem("xxx")
val actor = system.actorOf(Props[AkkaSample], "a1")
actor ! Msg1(0)
}
}
case class Msg1(id: Int)
case class Msg2(id: Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment