forked from fbettag/scala-vs-erlang
/
LiftActor.scala
executable file
·63 lines (46 loc) · 1.27 KB
/
LiftActor.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ag.bett.scala.test.lift
import net.liftweb.actor._
import akka.kernel._
import scala.compat.Platform
class ActorKernel extends Bootable {
val runs = 12000000
def startup = {
ag.bett.scala.test.lift.CounterClient.run(runs)
shutdown
}
def shutdown = sys.exit(0)
}
case object GetAndReset
case class AddCount(number:Long)
object CounterActor extends LiftActor {
var count: Long = 0
def messageHandler = {
case GetAndReset =>
val current = count
count = 0
reply(current)
case AddCount(extraCount) =>
count=count+extraCount
}
}
object CounterClient {
val counter = CounterActor
def run(runs: Long) {
runTest(runs)
}
def runTest(msgCount: Long) {
val start = Platform.currentTime
val count = theTest(msgCount)
val finish = Platform.currentTime
val elapsedTime = (finish - start) / 1000.0
printf("[lift] Count is %s%n",count)
printf("[lift] Test took %s seconds%n", elapsedTime)
printf("[lift] Throughput=%s per sec%n", msgCount / elapsedTime)
}
def theTest(msgCount: Long): Any = {
val bytesPerMsg = 100
val updates = (1L to msgCount).par.foreach((x: Long) => counter ! new AddCount(bytesPerMsg))
val count = (counter !! GetAndReset).open_!
return count
}
}