func Start(host string, options ...RemotingOption) { lis, err := net.Listen("tcp", host) if err != nil { log.Fatalf("failed to listen: %v", err) } config := defaultRemoteConfig() for _, option := range options { option(config) } host = lis.Addr().String() log.Printf("Host is %v", host) actor.ProcessRegistry.RegisterHostResolver(remoteHandler) actor.ProcessRegistry.Host = host props := actor. FromProducer(newEndpointManager(config)). WithMailbox(actor.NewBoundedMailbox(1000, 100000)) endpointManagerPID = actor.Spawn(props) s := grpc.NewServer(config.serverOptions...) messages.RegisterRemotingServer(s, &server{}) log.Printf("Starting GAM server on %v.", host) go s.Serve(lis) }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GC() remoting.Start("127.0.0.1:8080") props := actor. FromProducer(newRemoteActor()). WithMailbox(actor.NewBoundedMailbox(1000, 10000)) actor.SpawnNamed(props, "remote") console.ReadLine() }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) var wgStop sync.WaitGroup var wgStart sync.WaitGroup messageCount := 1000000 remoting.Start("127.0.0.1:8081") props := actor. FromProducer(newLocalActor(&wgStart, &wgStop, messageCount)). WithMailbox(actor.NewBoundedMailbox(1000, 10000)) pid := actor.Spawn(props) message := &messages.Ping{Sender: pid} remote := actor.NewPID("127.0.0.1:8080", "remote") remote.Tell(&messages.StartRemote{Sender: pid}) wgStart.Wait() start := time.Now() log.Println("Starting to send") for i := 0; i < messageCount; i++ { remote.Tell(message) } wgStop.Wait() elapsed := time.Since(start) log.Printf("Elapsed %s", elapsed) x := int(float32(messageCount*2) / (float32(elapsed) / float32(time.Second))) log.Printf("Msg per sec %v", x) // f, err := os.Create("memprofile") // if err != nil { // log.Fatal(err) // } // pprof.WriteHeapProfile(f) // f.Close() }