-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathbenchmark.go
64 lines (52 loc) · 1.13 KB
/
benchmark.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
64
package test
import (
"testing"
"go-micro.dev/v5"
"go-micro.dev/v5/broker"
"go-micro.dev/v5/client"
"go-micro.dev/v5/registry"
"go-micro.dev/v5/server"
"go-micro.dev/v5/transport"
"go-micro.dev/v5/util/test"
)
func BenchmarkService(b *testing.B) {
cfg := ServiceTestConfig{
Name: "test-service",
NewService: newService,
Parallel: []int{1, 8, 16, 32, 64},
Sequential: []int{0},
Streams: []int{0},
// PubSub: []int{10},
}
cfg.Run(b)
}
func newService(name string, opts ...micro.Option) (micro.Service, error) {
r := registry.NewMemoryRegistry(
registry.Services(test.Data),
)
b := broker.NewMemoryBroker()
t := transport.NewHTTPTransport()
c := client.NewClient(
client.Transport(t),
client.Broker(b),
)
s := server.NewRPCServer(
server.Name(name),
server.Registry(r),
server.Transport(t),
server.Broker(b),
)
if err := s.Init(); err != nil {
return nil, err
}
options := []micro.Option{
micro.Name(name),
micro.Server(s),
micro.Client(c),
micro.Registry(r),
micro.Broker(b),
}
options = append(options, opts...)
srv := micro.NewService(options...)
return srv, nil
}