github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/prepare/23_proto_actor/remotelatency/node1/main.go (about)

     1  package main
     2  
     3  import (
     4  	"time"
     5  
     6  	console "github.com/AsynkronIT/goconsole"
     7  	"github.com/AsynkronIT/protoactor-go/actor"
     8  	"github.com/AsynkronIT/protoactor-go/examples/remotelatency/messages"
     9  	"github.com/AsynkronIT/protoactor-go/remote"
    10  
    11  	"runtime"
    12  )
    13  
    14  // import "runtime/pprof"
    15  
    16  func makeTimestamp() int64 {
    17  	return time.Now().UnixNano() / int64(time.Millisecond)
    18  }
    19  func main() {
    20  	runtime.GOMAXPROCS(runtime.NumCPU())
    21  
    22  	messageCount := 1000000
    23  
    24  	remote.Start("127.0.0.1:8081", remote.WithEndpointWriterBatchSize(10000))
    25  
    26  	rootContext := actor.EmptyRootContext
    27  
    28  	remote := actor.NewPID("127.0.0.1:8080", "remote")
    29  	rootContext.RequestFuture(remote, &messages.Start{}, 5*time.Second).
    30  		Wait()
    31  
    32  	for i := 0; i < messageCount; i++ {
    33  		message := &messages.Ping{
    34  			Time: makeTimestamp(),
    35  		}
    36  		rootContext.Send(remote, message)
    37  		if i%1000 == 0 {
    38  			time.Sleep(500)
    39  		}
    40  	}
    41  	console.ReadLine()
    42  }