Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsqlookupd: enhance performance of /nodes #1099

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion nsqlookupd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,23 @@ func (s *httpServer) doNodes(w http.ResponseWriter, req *http.Request, ps httpro
producers := s.ctx.nsqlookupd.DB.FindProducers("client", "", "").FilterByActive(
s.ctx.nsqlookupd.opts.InactiveProducerTimeout, 0)
nodes := make([]*node, len(producers))
topicProducersMap := make(map[string]Producers)
for i, p := range producers {
topics := s.ctx.nsqlookupd.DB.LookupRegistrations(p.peerInfo.id).Filter("topic", "*", "").Keys()

// for each topic find the producer that matches this peer
// to add tombstone information
tombstones := make([]bool, len(topics))
for j, t := range topics {
topicProducers := s.ctx.nsqlookupd.DB.FindProducers("topic", t, "")
if _, exists := topicProducersMap[t]; !exists {
topicProducersMap[t] = s.ctx.nsqlookupd.DB.FindProducers("topic", t, "")
}

topicProducers := topicProducersMap[t]
for _, tp := range topicProducers {
if tp.peerInfo == p.peerInfo {
tombstones[j] = tp.IsTombstoned(s.ctx.nsqlookupd.opts.TombstoneLifetime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that adding a break just after this line is an easy way to make this slightly faster

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL.

break
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions nsqlookupd/registration_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,21 @@ func (r *RegistrationDB) FindProducers(category string, key string, subkey strin
return ProducerMap2Slice(r.registrationMap[k])
}

results := make(map[string]*Producer)
results := make(map[string]struct{})
var retProducers Producers
for k, producers := range r.registrationMap {
if !k.IsMatch(category, key, subkey) {
continue
}
for _, producer := range producers {
_, found := results[producer.peerInfo.id]
if found == false {
results[producer.peerInfo.id] = producer
results[producer.peerInfo.id] = struct{}{}
retProducers = append(retProducers, producer)
}
}
}
return ProducerMap2Slice(results)
return retProducers
}

func (r *RegistrationDB) LookupRegistrations(id string) Registrations {
Expand Down