Last active
August 29, 2015 14:22
-
-
Save shijinkui/55f3206163fcb48ef045 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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