Skip to content

Commit a703055

Browse files
committed
optimize: service default buffer size and update online addr notification
1 parent efd9749 commit a703055

File tree

9 files changed

+44
-26
lines changed

9 files changed

+44
-26
lines changed

api/dataplane/v1/service/cluster_service_end.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ func newclusterServiceEnd(addr string, opts ...ServiceOption) (*clusterServiceEn
5858
cc := clusterv1.NewClusterServiceClient(conn)
5959

6060
end := &clusterServiceEnd{
61-
cc: cc,
62-
serviceOption: &serviceOption{},
61+
cc: cc,
62+
serviceOption: &serviceOption{
63+
readBufferSize: 1024,
64+
writeBufferSize: 1024,
65+
},
6366
rpcs: map[string]geminio.RPC{},
6467
topics: mapset.NewSet[string](),
6568
edgefrontiers: mapmap.NewBiMap(),

api/dataplane/v1/service/service_end.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func newServiceEnd(dialer client.Dialer, opts ...ServiceOption) (*serviceEnd, er
6767
func newRetryServiceEnd(dialer client.Dialer, opts ...ServiceOption) (*serviceEnd, error) {
6868
// options
6969
sopt := &serviceOption{
70-
readBufferSize: -1,
71-
writeBufferSize: -1,
70+
readBufferSize: 1024,
71+
writeBufferSize: 1024,
7272
}
7373
for _, opt := range opts {
7474
opt(sopt)

examples/iclm/edge/edge.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func main() {
5959

6060
// get edge
6161
cli, err := edge.NewEdge(dialer,
62-
edge.OptionEdgeLog(armlog.DefaultLog), edge.OptionEdgeMeta([]byte(*meta)))
62+
edge.OptionEdgeLog(armlog.DefaultLog),
63+
edge.OptionEdgeMeta([]byte(*meta)))
6364
if err != nil {
6465
armlog.Info("new edge err:", err)
6566
return

examples/iclm/service/service.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func main() {
102102
methods := pflag.String("methods", "", "method name, support echo")
103103
printmessage = pflag.Bool("printmessage", false, "whether print message out")
104104
nostdin = pflag.Bool("nostdin", false, "nostdin mode, no stdin will be accepted")
105+
buffersize := pflag.Int("buffer", 8192, "buffer size set for service")
105106
stats := pflag.Bool("stats", false, "print statistics or not")
106107

107108
pflag.Parse()
@@ -121,7 +122,7 @@ func main() {
121122
opt := []service.ServiceOption{
122123
service.OptionServiceLog(armlog.DefaultLog),
123124
service.OptionServiceName(*serviceName),
124-
service.OptionServiceBufferSize(8192, 8192)}
125+
service.OptionServiceBufferSize(*buffersize, *buffersize)}
125126
if *topics != "" {
126127
topicSlice = strings.Split(*topics, ",")
127128
opt = append(opt, service.OptionServiceReceiveTopics(topicSlice))

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module github.com/singchia/frontier
22

3+
replace "github.com/singchia/geminio" => ../geminio
4+
35
go 1.22
46

57
require (

pkg/frontier/controlplane/service/edge_service.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
v1 "github.com/singchia/frontier/api/controlplane/frontier/v1"
7+
"github.com/singchia/frontier/pkg/frontier/repo/dao/membuntdb"
78
"github.com/singchia/frontier/pkg/frontier/repo/model"
89
"github.com/singchia/frontier/pkg/frontier/repo/query"
910
)
@@ -50,7 +51,11 @@ func (cps *ControlPlaneService) listEdges(_ context.Context, req *v1.ListEdgesRe
5051
}
5152
count, err := cps.repo.CountEdges(query)
5253
if err != nil {
53-
return nil, err
54+
if err != membuntdb.ErrUnimplemented {
55+
return nil, err
56+
} else {
57+
count = -1
58+
}
5459
}
5560
retEdges := transferEdges(edges)
5661
return &v1.ListEdgesResponse{
@@ -112,7 +117,11 @@ func (cps *ControlPlaneService) listEdgeRPCs(_ context.Context, req *v1.ListEdge
112117
}
113118
count, err := cps.repo.CountEdgeRPCs(query)
114119
if err != nil {
115-
return nil, err
120+
if err != membuntdb.ErrUnimplemented {
121+
return nil, err
122+
} else {
123+
count = -1
124+
}
116125
}
117126
return &v1.ListEdgeRPCsResponse{
118127
Rpcs: rpcs,

pkg/frontier/edgebound/edge_manager.go

-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ func (em *edgeManager) ListStreams(edgeID uint64) []geminio.Stream {
187187
}
188188

189189
func (em *edgeManager) DelEdgeByID(edgeID uint64) error {
190-
// TODO test it
191190
em.mtx.RLock()
192191
defer em.mtx.RUnlock()
193192

pkg/frontier/edgebound/edge_onoff.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ func (em *edgeManager) online(end geminio.End) error {
6868

6969
// inform others
7070
if em.informer != nil {
71-
em.informer.EdgeOnline(end.ClientID(), end.Meta(), end.Addr())
71+
em.informer.EdgeOnline(end.ClientID(), end.Meta(), end.RemoteAddr())
7272
}
7373
// exchange to service
7474
if em.exchange != nil {
75-
err := em.exchange.EdgeOnline(end.ClientID(), end.Meta(), end.Addr())
75+
err := em.exchange.EdgeOnline(end.ClientID(), end.Meta(), end.RemoteAddr())
7676
if err == apis.ErrServiceNotOnline {
7777
return nil
7878
}

test/batch/edges/edges.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"net/http"
99
_ "net/http/pprof"
1010
"os"
11-
"strconv"
1211
"strings"
1312
"sync"
13+
"sync/atomic"
1414
"time"
1515

1616
armlog "github.com/jumboframes/armorigo/log"
@@ -32,7 +32,8 @@ func main() {
3232
count := pflag.Int("count", 10000, "edges to dial")
3333
topic := pflag.String("topic", "test", "topic to specific")
3434
nseconds := pflag.Int("nseconds", 10, "publish message every n seconds for every edge")
35-
sourceIPs := pflag.String("source_ips", "", "source ips to dial, if your ")
35+
msg := pflag.String("msg", "testtesttest", "the message content to publish")
36+
sourceIPs := pflag.String("source_ips", "", "source ips to dial, if you want dial more than \"65535\" source ports")
3637
pprof := pflag.String("pprof", "", "pprof addr to listen")
3738
pflag.Parse()
3839

@@ -43,7 +44,8 @@ func main() {
4344
}
4445

4546
ips := []string{}
46-
idx := 0
47+
idx := int64(0)
48+
4749
if *sourceIPs != "" {
4850
ips = strings.Split(*sourceIPs, ",")
4951
idx = 0
@@ -52,9 +54,11 @@ func main() {
5254

5355
dialer := func() (net.Conn, error) {
5456
if len(ips) != 0 {
55-
for retry := 0; retry < 2; retry++ {
57+
for retry := 0; retry < 3; retry++ {
58+
thisidx := atomic.LoadInt64(&idx)
59+
ip := ips[int(thisidx)%len(ips)]
5660
localAddr := &net.TCPAddr{
57-
IP: net.ParseIP(ips[idx]),
61+
IP: net.ParseIP(ip),
5862
}
5963
dialer := &net.Dialer{
6064
LocalAddr: localAddr,
@@ -66,14 +70,10 @@ func main() {
6670
}
6771
if strings.Contains(err.Error(), "cannot assign requested address") ||
6872
strings.Contains(err.Error(), "address already in use") {
69-
fmt.Println("source ip:", localAddr.IP.String(), localAddr.Port, err)
70-
idx += 1
71-
if idx >= len(ips) {
72-
return nil, err
73-
}
73+
atomic.AddInt64(&idx, 1)
7474
continue
7575
}
76-
fmt.Println("source ip:", localAddr.IP.String(), localAddr.Port)
76+
fmt.Printf("unknown dial err: %s, source ip: %s:%d \n", err, localAddr.IP.String(), localAddr.Port)
7777
return nil, err
7878
}
7979
}
@@ -96,7 +96,11 @@ func main() {
9696
go func(i int) {
9797
defer wg.Done()
9898
// avoid congestion of connection
99-
random := rand.Intn(*count/100) + 1
99+
n := *count / 100
100+
if n == 0 {
101+
n = 1
102+
}
103+
random := rand.Intn(n) + 1
100104
time.Sleep(time.Second * time.Duration(random))
101105
// new edge connection
102106
cli, err := edge.NewEdge(dialer,
@@ -112,9 +116,8 @@ func main() {
112116
mtx.Unlock()
113117
// publish message in loop
114118
for {
115-
str := strconv.FormatInt(int64(i), 10)
116-
msg := cli.NewMessage([]byte(str))
117-
err := cli.Publish(context.TODO(), *topic, msg)
119+
gmsg := cli.NewMessage([]byte(*msg))
120+
err := cli.Publish(context.TODO(), *topic, gmsg)
118121
if err != nil {
119122
fmt.Println("publish err", err)
120123
break

0 commit comments

Comments
 (0)