-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (57 loc) · 1.39 KB
/
main.go
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 main
import (
"fmt"
"runtime"
"time"
"github.com/charlesderek/actor-model/actor"
"github.com/charlesderek/actor-model/log"
"github.com/charlesderek/actor-model/remote"
)
func makeRemoteEngine(addr string) *actor.Engine {
e := actor.NewEngine()
r := remote.New(e, remote.Config{ListenAddr: addr})
e.WithRemote(r)
return e
}
func benchmarkRemote() {
var (
a = makeRemoteEngine("127.0.0.1:3000")
b = makeRemoteEngine("127.0.0.1:3001")
pidB = b.SpawnFunc(func(c *actor.Context) {}, "bench", actor.WithInboxSize(1024*8))
)
its := []int{
1_000_000,
10_000_000,
}
for i := 0; i < len(its); i++ {
start := time.Now()
for j := 0; j < its[i]; j++ {
a.Send(pidB, pidB)
}
fmt.Printf("[BENCH HOLLYWOOD REMOTE] processed %d messages in %v\n", its[i], time.Since(start))
}
}
func benchmarkLocal() {
e := actor.NewEngine()
pid := e.SpawnFunc(func(c *actor.Context) {}, "bench", actor.WithInboxSize(1024*8))
its := []int{
1_000_000,
10_000_000,
}
payload := make([]byte, 128)
for i := 0; i < len(its); i++ {
start := time.Now()
for j := 0; j < its[i]; j++ {
e.Send(pid, payload)
}
fmt.Printf("[BENCH HOLLYWOOD LOCAL] processed %d messages in %v\n", its[i], time.Since(start))
}
}
func main() {
if runtime.GOMAXPROCS(runtime.NumCPU()) == 1 {
log.Fatalw("System needs more CPU...", nil)
}
log.SetLevel(log.LevelPanic)
benchmarkLocal()
benchmarkRemote()
}