本文整理汇总了Golang中github.com/adrianco/spigo/collect.NewHist函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHist函数的具体用法?Golang NewHist怎么用?Golang NewHist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHist函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Start
// Start - all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message)
microindex := make(map[int]chan gotocol.Message)
dependencies := make(map[string]time.Time) // dependent services and time last updated
var parent chan gotocol.Message // remember how to talk back to creator
requestor := make(map[string]gotocol.Routetype) // remember where requests came from when responding
var name string // remember my name
eureka := make(map[string]chan gotocol.Message, 1) // service registry
hist := collect.NewHist("")
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
for {
select {
case msg := <-listener:
flow.Instrument(msg, name, hist)
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
parent = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = handlers.Inform(msg, name, listener)
case gotocol.NameDrop:
handlers.NameDrop(&dependencies, µservices, msg, name, listener, eureka)
case gotocol.Forget:
// forget a buddy
handlers.Forget(&dependencies, µservices, msg)
case gotocol.GetRequest:
// route the request on to microservices
handlers.GetRequest(msg, name, listener, &requestor, µservices, µindex)
case gotocol.GetResponse:
// return path from a request, send payload back up using saved span context - server send
handlers.GetResponse(msg, name, listener, &requestor)
case gotocol.Put:
// route the request on to a random dependency
handlers.Put(msg, name, listener, &requestor, µservices, µindex)
case gotocol.Goodbye:
for _, ch := range eureka { // tell name service I'm not going to be here
ch <- gotocol.Message{gotocol.Delete, nil, time.Now(), gotocol.NilContext, name}
}
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, name}.GoSend(parent)
return
}
case <-eurekaTicker.C: // check to see if any new dependencies have appeared
for dep, _ := range dependencies {
for _, ch := range eureka {
ch <- gotocol.Message{gotocol.GetRequest, listener, time.Now(), gotocol.NilContext, dep}
}
}
}
}
}
开发者ID:dberkholz,项目名称:spigo,代码行数:57,代码来源:zuul.go
示例2: shutdown
// Shutdown fsm and pirates
func shutdown() {
var msg gotocol.Message
hist := collect.NewHist("fsm")
// wait until the delay has finished
if archaius.Conf.RunDuration >= time.Millisecond {
time.Sleep(archaius.Conf.RunDuration)
}
log.Println("fsm: Shutdown")
for _, noodle := range noodles {
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext(), "beer volcano"}.GoSend(noodle)
}
for len(noodles) > 0 {
msg = <-listener
collect.Measure(hist, time.Since(msg.Sent))
if archaius.Conf.Msglog {
log.Printf("fsm: %v\n", msg)
}
switch msg.Imposition {
case gotocol.Goodbye:
delete(noodles, msg.Intention)
if archaius.Conf.Msglog {
log.Printf("fsm: Pirate population: %v \n", len(noodles))
}
}
}
collect.Save()
log.Println("fsm: Exit")
}
开发者ID:kmissoumi,项目名称:spigo,代码行数:29,代码来源:fsm.go
示例3: Start
// Start edda, to listen for logging data from services
func Start(name string) {
// use a waitgroup so whoever starts edda can tell the logs have been flushed
Wg.Add(1)
defer Wg.Done()
if Logchan == nil {
return
}
var msg gotocol.Message
microservices := make(map[string]bool, archaius.Conf.Dunbar)
edges := make(map[string]bool, archaius.Conf.Dunbar)
var ok bool
hist := collect.NewHist(name)
log.Println(name + ": starting")
if archaius.Conf.GraphmlFile != "" {
graphml.Setup(archaius.Conf.GraphmlFile)
}
if archaius.Conf.GraphjsonFile != "" {
graphjson.Enabled = true
graphjson.Setup(archaius.Conf.GraphjsonFile)
}
for {
msg, ok = <-Logchan
collect.Measure(hist, time.Since(msg.Sent))
if !ok {
break // channel was closed
}
if archaius.Conf.Msglog {
log.Printf("%v(backlog %v): %v\n", name, len(Logchan), msg)
}
switch msg.Imposition {
case gotocol.Inform:
edge := names.FilterEdge(msg.Intention)
if edges[edge] == false { // only log an edge once
edges[edge] = true
graphml.WriteEdge(edge)
graphjson.WriteEdge(edge, msg.Sent)
}
case gotocol.Put:
node := names.FilterNode(msg.Intention)
if microservices[node] == false { // only log a node once
microservices[node] = true
graphml.WriteNode(node + " " + names.Package(msg.Intention))
graphjson.WriteNode(node+" "+names.Package(msg.Intention), msg.Sent)
}
case gotocol.Forget: // forget the edge
graphjson.WriteForget(msg.Intention, msg.Sent)
case gotocol.Delete: // remove the node
if microservices[msg.Intention] == true { // only remove nodes that exist, and only log it once
microservices[msg.Intention] = false
graphjson.WriteDone(msg.Intention, msg.Sent)
}
}
}
log.Println(name + ": closing")
graphml.Close()
graphjson.Close()
}
开发者ID:ruo91,项目名称:spigo,代码行数:58,代码来源:edda.go
示例4: Start
// Start staash, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := archaius.Conf.Population // starting point for how many nodes to remember
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message, dunbar)
microindex := make(map[int]chan gotocol.Message, dunbar)
dependencies := make(map[string]time.Time, dunbar) // dependent services and time last updated
var parent chan gotocol.Message // remember how to talk back to creator
requestor := make(map[gotocol.TraceContextType]chan gotocol.Message) // remember where requests came from
var name string // remember my name
eureka := make(map[string]chan gotocol.Message, 1) // service registry
hist := collect.NewHist("")
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
for {
select {
case msg := <-listener:
annotation, span := flow.Instrument(msg, name, hist)
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
parent = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = gotocol.InformHandler(msg, name, listener)
case gotocol.NameDrop:
gotocol.NameDropHandler(&dependencies, µservices, msg, name, listener, eureka)
case gotocol.Forget:
// forget a buddy
gotocol.ForgetHandler(&dependencies, µservices, msg)
case gotocol.GetRequest:
// route the request on to microservices
requestor[msg.Ctx.Trace] = msg.ResponseChan
// Intention body indicates which service to route to or which key to get
// need to lookup service by type rather than randomly call one day
if len(microservices) > 0 {
if len(microindex) != len(microservices) {
// rebuild index
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// start a request to a random service
gotocol.Message{gotocol.GetRequest, listener, flow.AnnotateSend(annotation, span), span, msg.Intention}.GoSend(microindex[m])
}
case gotocol.GetResponse:
// return path from a request, send payload back up
if requestor[msg.Ctx.Trace] != nil {
gotocol.Message{gotocol.GetResponse, listener, flow.AnnotateSend(annotation, span), span, msg.Intention}.GoSend(requestor[msg.Ctx.Trace])
delete(requestor, msg.Ctx.Trace)
}
case gotocol.Put:
// route the request on to a random dependency
if len(microservices) > 0 {
if len(microindex) != len(microservices) {
// rebuild index
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// pass on request to a random service
gotocol.Message{gotocol.Put, listener, flow.AnnotateSend(annotation, span), span, msg.Intention}.GoSend(microindex[m])
}
case gotocol.Goodbye:
for _, ch := range eureka { // tell name service I'm not going to be here
ch <- gotocol.Message{gotocol.Delete, nil, time.Now(), gotocol.NilContext, name}
}
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, name}.GoSend(parent)
return
}
case <-eurekaTicker.C: // check to see if any new dependencies have appeared
for dep, _ := range dependencies {
for _, ch := range eureka {
ch <- gotocol.Message{gotocol.GetRequest, listener, time.Now(), gotocol.NilContext, dep}
}
}
}
}
}
开发者ID:adriancole,项目名称:spigo,代码行数:88,代码来源:staash.go
示例5: Start
// Start the pirate, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := 10 // starting point for how many buddies to remember
// remember the channel to talk to named buddies
buddies := make(map[string]chan gotocol.Message, dunbar)
// remember who sent GoldCoin and how much, to buy favors
benefactors := make(map[string]int, dunbar)
var booty int // current GoldCoin balance
var fsm chan gotocol.Message // remember how to talk back to creator
var name string // remember my name
var logger chan gotocol.Message // if set, send updates
var chatrate time.Duration
hist := collect.NewHist("")
chatTicker := time.NewTicker(time.Hour)
chatTicker.Stop()
for {
select {
case msg := <-listener:
collect.Measure(hist, time.Since(msg.Sent))
if archaius.Conf.Msglog {
log.Printf("%v: %v\n", name, msg)
}
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
fsm = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
// remember where to send updates
logger = gotocol.InformHandler(msg, name, listener)
case gotocol.NameDrop:
// don't remember too many buddies and don't talk to myself
buddy := msg.Intention // message body is buddy name
if len(buddies) < dunbar && buddy != name {
// remember how to talk to this buddy
buddies[buddy] = msg.ResponseChan // message channel is buddy's listener
if logger != nil {
// if it's setup, tell the logger I have a new buddy to talk to
logger <- gotocol.Message{gotocol.Inform, listener, time.Now(), gotocol.NilContext, name + " " + buddy}
}
}
case gotocol.Chat:
// setup the ticker to run at the specified rate
d, e := time.ParseDuration(msg.Intention)
if e == nil && d >= time.Millisecond && d <= time.Hour {
chatrate = d
chatTicker = time.NewTicker(chatrate)
// assume we got paid before we started chatting
rand.Seed(int64(booty))
}
case gotocol.GoldCoin:
var coin int
_, e := fmt.Sscanf(msg.Intention, "%d", &coin)
if e == nil && coin > 0 {
booty += coin
for name, ch := range buddies {
if ch == msg.ResponseChan {
benefactors[name] += coin
}
}
}
case gotocol.Goodbye:
if archaius.Conf.Msglog {
log.Printf("%v: Going away with %v gold coins, chatting every %v\n", name, booty, chatrate)
}
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, name}.GoSend(fsm)
return
}
case <-chatTicker.C:
if rand.Intn(100) < 50 { // 50% of the time
// use Namedrop to tell the last buddy about the first
var firstBuddyName string
var firstBuddyChan, lastBuddyChan chan gotocol.Message
if len(buddies) >= 2 {
for name, ch := range buddies {
if firstBuddyName == "" {
firstBuddyName = name
firstBuddyChan = ch
} else {
lastBuddyChan = ch
}
gotocol.Message{gotocol.NameDrop, firstBuddyChan, time.Now(), gotocol.NewTrace(), firstBuddyName}.GoSend(lastBuddyChan)
}
}
} else {
// send a buddy some money
if booty > 0 {
donation := rand.Intn(booty)
luckyNumber := rand.Intn(len(buddies))
if donation > 0 {
for _, ch := range buddies {
if luckyNumber == 0 {
gotocol.Message{gotocol.GoldCoin, listener, time.Now(), gotocol.NewTrace(), fmt.Sprintf("%d", donation)}.GoSend(ch)
booty -= donation
break
} else {
luckyNumber--
//.........这里部分代码省略.........
开发者ID:shuoy,项目名称:spigo,代码行数:101,代码来源:pirate.go
示例6: Start
// Start the denominator, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := 6 // starting point for how many nodes to remember
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message, dunbar)
microindex := make([]chan gotocol.Message, dunbar)
dependencies := make(map[string]time.Time, dunbar) // dependent services and time last updated
var parent chan gotocol.Message // remember how to talk back to creator
var name string // remember my name
hist := collect.NewHist("") // don't know name yet
eureka := make(map[string]chan gotocol.Message, 3*archaius.Conf.Regions) // service registry per zone and region
var chatrate time.Duration
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
chatTicker := time.NewTicker(time.Hour)
chatTicker.Stop()
for {
select {
case msg := <-listener:
collect.Measure(hist, time.Since(msg.Sent))
if archaius.Conf.Msglog {
log.Printf("%v: %v\n", name, msg)
}
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
parent = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = gotocol.InformHandler(msg, name, listener)
case gotocol.NameDrop:
gotocol.NameDropHandler(&dependencies, µservices, msg, name, listener, eureka)
case gotocol.Forget:
// forget a buddy
gotocol.ForgetHandler(&dependencies, µservices, msg)
case gotocol.Chat:
// setup the ticker to run at the specified rate
d, e := time.ParseDuration(msg.Intention)
if e == nil && d >= time.Millisecond && d <= time.Hour {
chatrate = d
chatTicker = time.NewTicker(chatrate)
}
case gotocol.GetResponse:
// return path from a request, terminate and log
flow.End(msg.Ctx)
case gotocol.Goodbye:
if archaius.Conf.Msglog {
log.Printf("%v: Going away, was chatting every %v\n", name, chatrate)
}
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, name}.GoSend(parent)
return
}
case <-eurekaTicker.C: // check to see if any new dependencies have appeared
for dep, _ := range dependencies {
for _, ch := range eureka {
ch <- gotocol.Message{gotocol.GetRequest, listener, time.Now(), gotocol.NilContext, dep}
}
}
case <-chatTicker.C:
if len(microservices) > 0 {
// build index if needed
if len(microindex) != len(microservices) {
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// start a request to a random member of this denominator
ctx := gotocol.NewTrace()
flow.Begin(ctx, name)
if rand.Intn(2) == 0 {
gotocol.Message{gotocol.GetRequest, listener, time.Now(), ctx, "why?"}.GoSend(microindex[m])
} else {
gotocol.Message{gotocol.Put, listener, time.Now(), ctx, "remember me"}.GoSend(microindex[m])
}
}
}
}
}
开发者ID:lastlegion,项目名称:spigo,代码行数:84,代码来源:denominator.go
示例7: Start
// Start store, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := 30 // starting point for how many nodes to remember
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message, dunbar)
dependencies := make(map[string]time.Time, dunbar) // dependent services and time last updated
store := make(map[string]string, 4) // key value store
store["why?"] = "because..."
var netflixoss, requestor chan gotocol.Message // remember creator and how to talk back to incoming requests
var name string // remember my name
eureka := make(map[string]chan gotocol.Message, 3) // service registry per zone
var chatrate time.Duration
hist := collect.NewHist("")
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
chatTicker := time.NewTicker(time.Hour)
chatTicker.Stop()
for {
select {
case msg := <-listener:
collect.Measure(hist, time.Since(msg.Sent))
if archaius.Conf.Msglog {
log.Printf("%v: %v\n", name, msg)
}
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
netflixoss = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = gotocol.InformHandler(msg, name, listener)
case gotocol.NameDrop: // cross zone = true
gotocol.NameDropHandler(&dependencies, µservices, msg, name, listener, eureka, true)
case gotocol.Forget:
// forget a buddy
gotocol.ForgetHandler(&dependencies, µservices, msg)
case gotocol.Chat:
// setup the ticker to run at the specified rate
d, e := time.ParseDuration(msg.Intention)
if e == nil && d >= time.Millisecond && d <= time.Hour {
chatrate = d
chatTicker = time.NewTicker(chatrate)
}
case gotocol.GetRequest:
// return any stored value for this key (Cassandra READ.ONE behavior)
gotocol.Message{gotocol.GetResponse, listener, time.Now(), msg.Ctx.NewSpan(), store[msg.Intention]}.GoSend(msg.ResponseChan)
case gotocol.GetResponse:
// return path from a request, send payload back up (not currently used)
if requestor != nil {
gotocol.Message{gotocol.GetResponse, listener, time.Now(), msg.Ctx.NewSpan(), msg.Intention}.GoSend(requestor)
}
case gotocol.Put:
requestor = msg.ResponseChan
// set a key value pair and replicate globally
var key, value string
fmt.Sscanf(msg.Intention, "%s%s", &key, &value)
if key != "" && value != "" {
store[key] = value
// duplicate the request on to all connected store nodes
if len(microservices) > 0 {
// replicate request
for _, c := range microservices {
gotocol.Message{gotocol.Replicate, listener, time.Now(), msg.Ctx.NewSpan(), msg.Intention}.GoSend(c)
}
}
}
case gotocol.Replicate:
// Replicate is only used between store nodes
// end point for a request
var key, value string
fmt.Sscanf(msg.Intention, "%s%s", &key, &value)
// log.Printf("store: %v:%v", key, value)
if key != "" && value != "" {
store[key] = value
}
// name looks like: netflixoss.us-east-1.zoneC.cassTurtle.store.cassTurtle11
myregion := names.Region(name)
//log.Printf("%v: %v\n", name, myregion)
// find if this was a cross region Replicate
for n, c := range microservices {
// find the name matching incoming request channel
if c == msg.ResponseChan {
if myregion != names.Region(n) {
// Replicate from out of region needs to be Replicated only to other zones in this Region
for nz, cz := range microservices {
if myregion == names.Region(nz) {
//log.Printf("%v rep to: %v\n", name, nz)
gotocol.Message{gotocol.Replicate, listener, time.Now(), msg.Ctx.NewSpan(), msg.Intention}.GoSend(cz)
}
}
}
}
}
case gotocol.Goodbye:
if archaius.Conf.Msglog {
log.Printf("%v: Going away, zone: %v\n", name, store["zone"])
}
//.........这里部分代码省略.........
开发者ID:shuoy,项目名称:spigo,代码行数:101,代码来源:store.go
示例8: Start
// Start priamCassandra, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := archaius.Conf.Population // starting point for how many nodes to remember
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message, dunbar)
// track the hash values owned by each node in the ring
var ring ByToken
dependencies := make(map[string]time.Time, dunbar) // dependent services and time last updated
store := make(map[string]string, 4) // key value store
store["why?"] = "because..."
var parent chan gotocol.Message // remember how to talk back to creator
var name string // remember my name
eureka := make(map[string]chan gotocol.Message, 3*archaius.Conf.Regions) // service registry per zone and region
hist := collect.NewHist("")
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
for {
select {
case msg := <-listener:
collect.Measure(hist, time.Since(msg.Sent))
if archaius.Conf.Msglog {
log.Printf("%v: %v\n", name, msg)
}
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
parent = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = gotocol.InformHandler(msg, name, listener)
case gotocol.NameDrop: // cross zone = true
gotocol.NameDropHandler(&dependencies, µservices, msg, name, listener, eureka, true)
case gotocol.Forget:
// forget a buddy
gotocol.ForgetHandler(&dependencies, µservices, msg)
case gotocol.Chat:
// Gossip setup notification of hash values for nodes, cass1:123,cass2:456
ring = RingConfig(msg.Intention)
case gotocol.GetRequest:
// see if the data is stored on this node
i := ring.Find(ringHash(msg.Intention))
//log.Printf("%v: %v %v\n", name, i, ringHash(msg.Intention))
span := msg.Ctx.NewSpan()
flow.Update(span, name)
if len(ring) == 0 || ring[i].name == name { // ring is setup so only respond if this is the right place
// return any stored value for this key (Cassandra READ.ONE behavior)
gotocol.Message{gotocol.GetResponse, listener, time.Now(), span, store[msg.Intention]}.GoSend(msg.ResponseChan)
} else {
// send the message to the right place, but don't change the ResponseChan
gotocol.Message{gotocol.GetRequest, msg.ResponseChan, time.Now(), span, msg.Intention}.GoSend(microservices[ring[i].name])
}
case gotocol.GetResponse:
// return path from a request, send payload back up, not used by priamCassandra currently
case gotocol.Put:
// set a key value pair and replicate globally
var key, value string
span := msg.Ctx.NewSpan()
flow.Update(span, name)
fmt.Sscanf(msg.Intention, "%s%s", &key, &value)
if key != "" && value != "" {
i := ring.Find(ringHash(key))
if len(ring) == 0 || ring[i].name == name { // ring is setup so only store if this is the right place
store[key] = value
} else {
// send the message to the right place, but don't change the ResponseChan
gotocol.Message{gotocol.Put, msg.ResponseChan, time.Now(), span, msg.Intention}.GoSend(microservices[ring[i].name])
}
// duplicate the request on to priamCassandra nodes in each zone and one in each region
for _, z := range names.OtherZones(name, archaius.Conf.ZoneNames) {
// replicate request
for n, c := range microservices {
if names.Region(n) == names.Region(name) && names.Zone(n) == z {
gotocol.Message{gotocol.Replicate, listener, time.Now(), span, msg.Intention}.GoSend(c)
break // only need to send it to one node in each zone, no tokens yet
}
}
}
for _, r := range names.OtherRegions(name, archaius.Conf.RegionNames[0:archaius.Conf.Regions]) {
for n, c := range microservices {
if names.Region(n) == r {
gotocol.Message{gotocol.Replicate, listener, time.Now(), span, msg.Intention}.GoSend(c)
break // only need to send it to one node in each region, no tokens yet
}
}
}
}
case gotocol.Replicate:
// Replicate is only used between priamCassandra nodes
// end point for a request
var key, value string
span := msg.Ctx.NewSpan()
flow.Update(span, name)
fmt.Sscanf(msg.Intention, "%s%s", &key, &value)
// log.Printf("priamCassandra: %v:%v", key, value)
if key != "" && value != "" {
i := ring.Find(ringHash(key))
if len(ring) == 0 || ring[i].name == name { // ring is setup so only store if this is the right place
//.........这里部分代码省略.........
开发者ID:shuoy,项目名称:spigo,代码行数:101,代码来源:priamCassandra.go
示例9: Start
// Start monolith, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := 30 // starting point for how many nodes to remember
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message, dunbar)
microindex := make([]chan gotocol.Message, dunbar)
dependencies := make(map[string]time.Time, dunbar) // dependent services and time last updated
var netflixoss, requestor chan gotocol.Message // remember creator and how to talk back to incoming requests
var name string // remember my name
eureka := make(map[string]chan gotocol.Message, 1) // service registry
var chatrate time.Duration
hist := collect.NewHist("")
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
chatTicker := time.NewTicker(time.Hour)
chatTicker.Stop()
for {
select {
case msg := <-listener:
collect.Measure(hist, time.Since(msg.Sent))
if archaius.Conf.Msglog {
log.Printf("%v: %v\n", name, msg)
}
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
netflixoss = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = gotocol.InformHandler(msg, name, listener)
case gotocol.NameDrop: // monolith talks cross zones, only difference from karyon
gotocol.NameDropHandler(&dependencies, µservices, msg, name, listener, eureka, true)
case gotocol.Forget:
// forget a buddy
gotocol.ForgetHandler(&dependencies, µservices, msg)
case gotocol.Chat:
// setup the ticker to run at the specified rate
d, e := time.ParseDuration(msg.Intention)
if e == nil && d >= time.Millisecond && d <= time.Hour {
chatrate = d
chatTicker = time.NewTicker(chatrate)
}
case gotocol.GetRequest:
// route the request on to microservices
requestor = msg.ResponseChan
// Intention body indicates which service to route to or which key to get
// need to lookup service by type rather than randomly call one day
if len(microservices) > 0 {
if len(microindex) != len(microservices) {
// rebuild index
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// start a request to a random service
gotocol.Message{gotocol.GetRequest, listener, time.Now(), msg.Intention}.GoSend(microindex[m])
}
case gotocol.GetResponse:
// return path from a request, send payload back up
if requestor != nil {
gotocol.Message{gotocol.GetResponse, listener, time.Now(), msg.Intention}.GoSend(requestor)
}
case gotocol.Put:
// route the request on to a random dependency
if len(microservices) > 0 {
if len(microindex) != len(microservices) {
// rebuild index
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// pass on request to a random service
gotocol.Message{gotocol.Put, listener, time.Now(), msg.Intention}.GoSend(microindex[m])
}
case gotocol.Goodbye:
if archaius.Conf.Msglog {
log.Printf("%v: Going away\n", name)
}
gotocol.Message{gotocol.Goodbye, nil, time.Now(), name}.GoSend(netflixoss)
return
}
case <-eurekaTicker.C: // check to see if any new dependencies have appeared
for dep, _ := range dependencies {
for _, ch := range eureka {
ch <- gotocol.Message{gotocol.GetRequest, listener, time.Now(), dep}
}
}
case <-chatTicker.C:
if len(microservices) > 0 {
if len(microservices) != len(microindex) {
// rebuild index
//.........这里部分代码省略.........
开发者ID:ruo91,项目名称:spigo,代码行数:101,代码来源:monolith.go
示例10: Start
// Start eureka discovery service and set name directly
func Start(listener chan gotocol.Message, name string) {
// use a waitgroup so whoever starts eureka can tell it's ready and when stopping that the logs have been flushed
Wg.Add(1)
defer Wg.Done()
var msg gotocol.Message
var ok bool
hist := collect.NewHist(name)
microservices := make(map[string]chan gotocol.Message, archaius.Conf.Dunbar)
eurekaservices := make(map[string]chan gotocol.Message, 2)
metadata := make(map[string]meta, archaius.Conf.Dunbar)
lastrequest := make(map[callback]time.Time) // remember time of last request for a service from this requestor
log.Println(name + ": starting")
for {
msg, ok = <-listener
collect.Measure(hist, time.Since(msg.Sent))
if !ok {
break // channel was closed
}
if archaius.Conf.Msglog {
log.Printf("%v(backlog %v): %v\n", name, len(listener), msg)
}
switch msg.Imposition {
// used to wire up connections to other eureka nodes only
case gotocol.NameDrop:
if msg.Intention != name { // don't talk to myself
eurekaservices[msg.Intention] = msg.ResponseChan
}
// for new nodes record the data, replicate and maybe pass on to be logged
case gotocol.Put:
if microservices[msg.Intention] == nil { // ignore duplicate requests
microservices[msg.Intention] = msg.ResponseChan
metadata[msg.Intention] = meta{true, msg.Sent}
// replicate request, everyone ends up with the same timestamp for state change of this service
for _, c := range eurekaservices {
gotocol.Message{gotocol.Replicate, msg.ResponseChan, msg.Sent, msg.Intention}.GoSend(c)
}
if edda.Logchan != nil {
edda.Logchan <- msg
}
}
case gotocol.Replicate:
if microservices[msg.Intention] == nil { // ignore multiple requests
microservices[msg.Intention] = msg.ResponseChan
metadata[msg.Intention] = meta{true, msg.Sent}
}
case gotocol.Inform:
// don't store edges in discovery but do log them
if edda.Logchan != nil {
edda.Logchan <- msg
}
case gotocol.GetRequest:
if msg.Intention == "" {
log.Fatal(name + ": empty GetRequest")
}
if microservices[msg.Intention] != nil { // matched a unique full name
gotocol.Message{gotocol.NameDrop, microservices[msg.Intention], time.Now(), msg.Intention}.GoSend(msg.ResponseChan)
break
}
for n, ch := range microservices { // respond with all the online names that match the service component
if names.Service(n) == msg.Intention {
// if there was an update for the looked up service since last check
// log.Printf("%v: matching %v with %v, last: %v metadata: %v\n", name, n, msg.Intention, lastrequest[callback{n, msg.ResponseChan}], metadata[n].registered)
if metadata[n].registered.After(lastrequest[callback{n, msg.ResponseChan}]) {
if metadata[n].online {
gotocol.Message{gotocol.NameDrop, ch, time.Now(), n}.GoSend(msg.ResponseChan)
} else {
log.Printf("%v:Forget %v\n", name, n)
gotocol.Message{gotocol.Forget, ch, time.Now(), n}.GoSend(msg.ResponseChan)
}
}
// remember for next time
lastrequest[callback{n, msg.ResponseChan}] = msg.Sent
}
}
case gotocol.Delete: // remove a node
if microservices[msg.Intention] != nil { // matched a unique full name
metadata[msg.Intention] = meta{false, time.Now()}
// replicate request
for _, c := range eurekaservices {
gotocol.Message{gotocol.Replicate, nil, time.Now(), msg.Intention}.GoSend(c)
}
if edda.Logchan != nil {
edda.Logchan <- msg
}
}
case gotocol.Goodbye:
gotocol.Message{gotocol.Goodbye, nil, time.Now(), name}.GoSend(msg.ResponseChan)
log.Println(name + ": closing")
return
}
}
}
开发者ID:ruo91,项目名称:spigo,代码行数:93,代码来源:eureka.go
示例11: Start
// Start the elb, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := archaius.Conf.Population
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message, dunbar)
microindex := make([]chan gotocol.Message, dunbar)
dependencies := make(map[string]time.Time, dunbar) // dependent services and time last updated
var parent chan gotocol.Message // remember how to talk back to creator
requestor := make(map[gotocol.TraceContextType]chan gotocol.Message) // remember where requests came from
var name string // remember my name
eureka := make(map[string]chan gotocol.Message, 3) // service registry per zone
var chatrate time.Duration
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
hist := collect.NewHist("")
chatTicker := time.NewTicker(time.Hour)
chatTicker.Stop()
for {
select {
case msg := <-listener:
collect.Measure(hist, time.Since(msg.Sent))
if archaius.Conf.Msglog {
log.Printf("%v: %v\n", name, msg)
}
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
parent = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = gotocol.InformHandler(msg, name, listener)
case gotocol.NameDrop: // cross zone = true
gotocol.NameDropHandler(&dependencies, µservices, msg, name, listener, eureka, true)
case gotocol.Forget:
// forget a buddy
gotocol.ForgetHandler(&dependencies, µservices, msg)
case gotocol.Chat:
// setup the ticker to run at the specified rate
d, e := time.ParseDuration(msg.Intention)
if e == nil && d >= time.Millisecond && d <= time.Hour {
chatrate = d
chatTicker = time.NewTicker(chatrate)
}
case gotocol.GetRequest:
// route the request on to microservices
requestor[msg.Ctx.Trace] = msg.ResponseChan
// Intention body indicates which service to route to or which key to get
// need to lookup service by type rather than randomly call one day
if len(microservices) > 0 {
if len(microindex) != len(microservices) {
// rebuild index
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// pass on request to a random service
span := msg.Ctx.NewSpan()
flow.Update(span, name)
gotocol.Message{gotocol.GetRequest, listener, time.Now(), span, msg.Intention}.GoSend(microindex[m])
}
case gotocol.GetResponse:
// return path from a request, send payload back up
if requestor[msg.Ctx.Trace] != nil {
span := msg.Ctx.NewSpan()
flow.Update(span, name)
gotocol.Message{gotocol.GetResponse, listener, time.Now(), span, msg.Intention}.GoSend(requestor[msg.Ctx.Trace])
delete(requestor, msg.Ctx.Trace)
}
case gotocol.Put:
// route the request on to a random dependency
if len(microservices) > 0 {
if len(microindex) != len(microservices) {
// rebuild index
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// pass on request to a random service
span := msg.Ctx.NewSpan()
flow.Update(span, name)
gotocol.Message{gotocol.Put, listener, time.Now(), span, msg.Intention}.GoSend(microindex[m])
}
case gotocol.Goodbye:
if archaius.Conf.Msglog {
log.Printf("%v: Going away, chatting every %v\n", name, chatrate)
}
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, name}.GoSend(parent)
return
}
case <-eurekaTicker.C: // check to see if any new dependencies have appeared
for dep, _ := range dependencies {
//.........这里部分代码省略.........
开发者ID:shuoy,项目名称:spigo,代码行数:101,代码来源:elb.go
示例12: Start
// Start store, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message)
dependencies := make(map[string]time.Time) // dependent services and time last updated
store := make(map[string]string, 4) // key value store
store["why?"] = "because..."
var netflixoss chan gotocol.Message // remember creator and how to talk back to incoming requests
var name string // remember my name
eureka := make(map[string]chan gotocol.Message, 3) // service registry per zone
hist := collect.NewHist("")
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
for {
select {
case msg := <-listener:
flow.Instrument(msg, name, hist)
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
netflixoss = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = handlers.Inform(msg, name, listener)
case gotocol.NameDrop: // cross zone = true
handlers.NameDrop(&dependencies, µservices, msg, name, listener, eureka, true)
case gotocol.Forget:
// forget a buddy
handlers.Forget(&dependencies, µservices, msg)
case gotocol.GetRequest:
// return any stored value for this key
outmsg := gotocol.Message{gotocol.GetResponse, listener, time.Now(), msg.Ctx, store[msg.Intention]}
flow.AnnotateSend(outmsg, name)
outmsg.GoSend(msg.ResponseChan)
case gotocol.GetResponse:
// return path from a request, send payload back up (not currently used)
case gotocol.Put:
// set a key value pair and replicate globally
var key, value string
fmt.Sscanf(msg.Intention, "%s%s", &key, &value)
if key != "" && value != "" {
store[key] = value
// duplicate the request on to all connected store nodes
if len(microservices) > 0 {
// replicate request
for _, c := range microservices {
outmsg := gotocol.Message{gotocol.Replicate, listener, time.Now(), msg.Ctx.NewParent(), msg.Intention}
flow.AnnotateSend(outmsg, name)
outmsg.GoSend(c)
}
}
}
case gotocol.Replicate:
// Replicate is only used between store nodes
// end point for a request
var key, value string
fmt.Sscanf(msg.Intention, "%s%s", &key, &value)
// log.Printf("store: %v:%v", key, value)
if key != "" && value != "" {
store[key] = value
}
// name looks like: netflixoss.us-east-1.zoneC.mysql.store.mysql1
myregion := names.Region(name)
//log.Printf("%v: %v\n", name, myregion)
// find if this was a cross region Replicate
for n, c := range microservices {
// find the name matching incoming request channel
if c == msg.ResponseChan {
if myregion != names.Region(n) {
// Replicate from out of region needs to be Replicated only to other zones in this Region
for nz, cz := range microservices {
if myregion == names.Region(nz) {
//log.Printf("%v rep to: %v\n", name, nz)
outmsg := gotocol.Message{gotocol.Replicate, listener, time.Now(), msg.Ctx.NewParent(), msg.Intention}
flow.AnnotateSend(outmsg, name)
outmsg.GoSend(cz)
}
}
}
}
}
case gotocol.Goodbye:
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, name}.GoSend(netflixoss)
return
}
case <-eurekaTicker.C: // check to see if any new dependencies have appeared
for dep, _ := range dependencies {
for _, ch := range eureka {
ch <- gotocol.Message{gotocol.GetRequest, listener, time.Now(), gotocol.NilContext, dep}
}
}
}
}
}
开发者ID:dberkholz,项目名称:spigo,代码行数:97,代码来源:store.go
示例13: Start
// Start the denominator, all configuration and state is sent via messages
func Start(listener chan gotocol.Message) {
dunbar := 6 // starting point for how many nodes to remember
// remember the channel to talk to microservices
microservices := make(map[string]chan gotocol.Message, dunbar)
microindex := make([]chan gotocol.Message, dunbar)
dependencies := make(map[string]time.Time, dunbar) // dependent services and time last updated
var parent chan gotocol.Message // remember how to talk back to creator
var name string // remember my name
hist := collect.NewHist("") // don't know name yet
eureka := make(map[string]chan gotocol.Message, 3*archaius.Conf.Regions) // service registry per zone and region
var chatrate time.Duration
ep, _ := time.ParseDuration(archaius.Conf.EurekaPoll)
eurekaTicker := time.NewTicker(ep)
chatTicker := time.NewTicker(time.Hour)
chatTicker.Stop()
w := 1 // counter for random messages
for {
select {
case msg := <-listener:
flow.Instrument(msg, name, hist)
switch msg.Imposition {
case gotocol.Hello:
if name == "" {
// if I don't have a name yet remember what I've been named
parent = msg.ResponseChan // remember how to talk to my namer
name = msg.Intention // message body is my name
hist = collect.NewHist(name)
}
case gotocol.Inform:
eureka[msg.Intention] = handlers.Inform(msg, name, listener)
case gotocol.NameDrop:
handlers.NameDrop(&dependencies, µservices, msg, name, listener, eureka)
case gotocol.Forget:
// forget a buddy
handlers.Forget(&dependencies, µservices, msg)
case gotocol.Chat:
// setup the ticker to run at the specified rate
d, e := time.ParseDuration(msg.Intention)
if e == nil && d >= time.Millisecond && d <= time.Hour {
chatrate = d
chatTicker = time.NewTicker(chatrate)
}
case gotocol.GetResponse:
// return path from a request, terminate and log
flow.End(msg.Ctx)
case gotocol.Goodbye:
if archaius.Conf.Msglog {
log.Printf("%v: Going away, was chatting every %v\n", name, chatrate)
}
gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, name}.GoSend(parent)
return
}
case <-eurekaTicker.C: // check to see if any new dependencies have appeared
for dep, _ := range dependencies {
for _, ch := range eureka {
ch <- gotocol.Message{gotocol.GetRequest, listener, time.Now(), gotocol.NilContext, dep}
}
}
case <-chatTicker.C:
if len(microservices) > 0 {
// build index if needed
if len(microindex) != len(microservices) {
i := 0
for _, ch := range microservices {
microindex[i] = ch
i++
}
}
m := rand.Intn(len(microservices))
// start a request to a random member of this denominator
ctx := gotocol.NewTrace()
now := time.Now()
var sm gotocol.Message
switch rand.Intn(3) {
case 0:
sm = gotocol.Message{gotocol.GetRequest, listener, now, ctx, "why?"}
case 1:
q := rand.Intn(w) // pick a random key that has already been put
sm = gotocol.Message{gotocol.GetRequest, listener, now, ctx, fmt.Sprintf("Why%v%v", q, q*q)}
case 2:
sm = gotocol.Message{gotocol.Put, listener, now, ctx, fmt.Sprintf("Why%v%v me", w, w*w)}
w++ // put a new key each time
}
flow.AnnotateSend(sm, name) // service send logs creation time for this flow
sm.GoSend(microindex[m])
}
}
}
}
开发者ID:dberkholz,项目名称:spigo,代码行数:90,代码来源:denominator.go
|
请发表评论