Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

There is a performance problem in lb/consul.updater, cpu 100% #4

Open
tobeabme opened this issue Mar 27, 2019 · 2 comments
Open

There is a performance problem in lb/consul.updater, cpu 100% #4

tobeabme opened this issue Mar 27, 2019 · 2 comments

Comments

@tobeabme
Copy link

tobeabme commented Mar 27, 2019

2.54mins runtime.lock
runtime.chanrecv
runtime.selectnbrecv
code.qschou.com/peduli/go_service_passport/vendor/github.com/olivere/grpc/lb/consul.(*Resolver).updater
-----------+-------------------------------------------------------
53.54s runtime.unlock
runtime.chanrecv
runtime.selectnbrecv
code.qschou.com/peduli/go_service_passport/vendor/github.com/olivere/grpc/lb/consul.(*Resolver).updater

profile001.pdf

@tobeabme
Copy link
Author

tobeabme commented Mar 27, 2019

there are the problem code

func (r *Resolver) updater(instances []string, lastIndex uint64) {
	var err error
	var oldInstances = instances
	var newInstances []string

	// TODO Cache the updates for a while, so that we don't overwhelm Consul.
	for {
		select {
		case <-r.quitc:
			break
		default:
			newInstances, lastIndex, err = r.getInstances(lastIndex)
			if err != nil {
				log.Printf("grpc/lb/consul: error retrieving instances from Consul: %v", err)
				continue
			}
			updates := r.makeUpdates(oldInstances, newInstances)
			if len(updates) > 0 {
				r.updatesc <- updates
			}
			oldInstances = newInstances
		}
	}
}

@olivere
Copy link
Owner

olivere commented Mar 27, 2019

I see. I'm not sure if it's worth fixing the issue as the way gRPC does resolving/balancing is now at a very different level as it used to be at the time I was writing this library. See #1 for a hint. There are alternatives like https://github.com/ekomobile/grpc-consul-resolver that seem to register Consul as a resolver and use the newer LB mechanism.

Looking at this issue, we could of course add a simple cache to updater or use Consul watches to stop polling for changes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants