github.com/annchain/OG@v0.0.9/debug/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/annchain/OG/arefactor/common/mylog"
     6  	"github.com/annchain/OG/debug/dep"
     7  	"github.com/annchain/OG/engine"
     8  	"github.com/annchain/OG/message"
     9  	"github.com/annchain/OG/ogcore/communication"
    10  	"github.com/annchain/OG/plugin/og"
    11  	"github.com/sirupsen/logrus"
    12  	"net/http"
    13  	_ "net/http/pprof"
    14  	"sync"
    15  	"time"
    16  )
    17  
    18  func something() {
    19  	mylog.LogInit(logrus.InfoLevel)
    20  	len := 2
    21  	plugins := make([]*og.OgPlugin, len)
    22  	chans := make([]chan *message.GeneralMessageEvent, len)
    23  	communicators := make([]*dep.LocalGeneralPeerCommunicator, len)
    24  
    25  	engines := make([]*engine.Engine, len)
    26  
    27  	for i := 0; i < len; i++ {
    28  		chans[i] = make(chan *message.GeneralMessageEvent)
    29  	}
    30  
    31  	for i := 0; i < len; i++ {
    32  		communicators[i] = dep.NewLocalGeneralPeerCommunicator(i, chans[i], chans)
    33  	}
    34  
    35  	for i := 0; i < len; i++ {
    36  		plugins[i] = og.NewOgPlugin()
    37  		plugins[i].SetOutgoing(communicators[i])
    38  	}
    39  
    40  	// init general processor
    41  	for i := 0; i < len; i++ {
    42  		eng := engine.Engine{
    43  			Config:       engine.EngineConfig{},
    44  			PeerOutgoing: communicators[i],
    45  			PeerIncoming: communicators[i],
    46  		}
    47  		eng.InitDefault()
    48  		eng.RegisterPlugin(plugins[i])
    49  		engines[i] = &eng
    50  		eng.Start()
    51  	}
    52  
    53  	logrus.Info("Started")
    54  
    55  	plugins[0].OgPartner.SendMessagePing(communication.OgPeer{Id: 1})
    56  
    57  	var lastValue uint = 0
    58  	for i := 0; i < 60; i++ {
    59  		v := engines[0].GetBenchmarks()["mps"].(uint)
    60  		if lastValue == 0 {
    61  			lastValue = v
    62  		} else {
    63  			logrus.WithField("mps", v-lastValue).Info("performance")
    64  		}
    65  		lastValue = v
    66  		time.Sleep(time.Second)
    67  	}
    68  }
    69  
    70  func main() {
    71  	// we need a webserver to get the pprof webserver
    72  	go func() {
    73  		logrus.Info(http.ListenAndServe("localhost:6060", nil))
    74  	}()
    75  	fmt.Println("hello world")
    76  	var wg sync.WaitGroup
    77  	wg.Add(1)
    78  	something()
    79  	wg.Wait()
    80  }