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

Use a min heap to store top K scoring nodes for placement metrics #4564

Merged
merged 8 commits into from
Aug 31, 2018

Conversation

preetapan
Copy link
Contributor

@preetapan preetapan commented Aug 8, 2018

This PR changes the placement metrics map which used to store all scored nodes, to only storing the top K nodes per scorer.

Also includes changes to the CLI, score metrics are shown in the following format

Node                                  binpack              node-affinity       Final Score
d9b254c9-55b3-946a-3e12-aaa6341f2add  0.15540130306341324  1                   0.5777006515317066
4c7f57f3-5f17-4503-f04d-53e5a8f1f5bd  0.08062597951123213  1                   0.540312989755616
fe02a3ac-1192-cf67-f24e-4168005d86b1  0.08062597951123213  0.3333333333333333  0.20697965642228272

@@ -0,0 +1,63 @@
package lib
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to figure out if there's a better package for this. Adding it to the lib package at the top level caused an import cycle because this heap is used in the structs package, and other code in the existing lib package uses the structs package.

Copy link
Contributor

Choose a reason for hiding this comment

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

lib/kheap?

Copy link
Contributor

Choose a reason for hiding this comment

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

May want to repackage the other one to be lib/delayheap

if len(metrics.ScoreMetaData) > 0 {
for scorer, scoreMeta := range metrics.ScoreMetaData {
for _, nodeScore := range scoreMeta {
out += fmt.Sprintf("%s* Scorer %q, Node %q = %f\n", prefix, scorer, nodeScore.NodeID, nodeScore.Score)
Copy link
Member

Choose a reason for hiding this comment

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

From the demo it would be nice if this output was tabular. Sorting by the normalized score first then lexicographical by node id. Example:

node                                 | binpack  | node-affinity | normalized |
4ebde21b-daa9-f264-16dd-b6ba88efdd58 | 0.080626 | 1.000000      | 0.540313   |
5f2db925-69d4-e677-d3a9-b166155153c6 | 0.080626 | 1.000000      | 0.540313   |
14ebcc35-34d0-1812-14c9-b4397d603723 | 0.080626 | 0.333333      | 0.206980   |

}

// NodeScoreMeta is used to serialize node scoring metadata
// displayed in the CLI during verbose mode
Copy link
Contributor

Choose a reason for hiding this comment

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

Mark scores as deprecated here and in the website/api docs/changelog

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do we mark fields in json responses as deprecated?

@@ -0,0 +1,63 @@
package lib
Copy link
Contributor

Choose a reason for hiding this comment

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

lib/kheap?

@@ -0,0 +1,63 @@
package lib
Copy link
Contributor

Choose a reason for hiding this comment

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

May want to repackage the other one to be lib/delayheap

nomad/structs/structs.go Show resolved Hide resolved
if a.topScores == nil {
a.topScores = make(map[string]*lib.ScoreHeap)
}
scorerHeap, ok := a.topScores[name]
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not believe this is the API we want. It is possible to not have all the sub scores for a the top k normalized scores.

// scoring nodes in descending order
for scoreHeap.Len() > 0 {
item := heap.Pop(scoreHeap).(*lib.HeapItem)
scoreMeta[i] = &NodeScoreMeta{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth just adding a GetItems() and GetItemsReverse() method to the library?

scheduler/generic_sched.go Show resolved Hide resolved
Preetha Appan added 3 commits August 17, 2018 05:38
Scoring metadata is now aggregated by scorer type to make it easier
to parse when reading it in the CLI.
Copy link
Contributor

@dadgar dadgar left a comment

Choose a reason for hiding this comment

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

LGTM but small changes requested

func (a *AllocMetric) ScoreNode(node *Node, name string, score float64) {
if a.Scores == nil {
a.Scores = make(map[string]float64)
if a.nodeScoreMeta == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this have to be a.nodeScoreMeta == nil || a.nodeScoreMeta.NodeID != node.ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reset it to nil once I have the final score from the normalized scorer. But I went ahead and made this change because its safer to do it this way (since it works even if the norm scorer doesn't get invoked).

// The map is populated by popping elements from a heap of top K scores
// maintained per scorer
func (a *AllocMetric) PopulateScoreMetaData() {
if a.topScores != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

if a.topScores == nil { return }
Less nesting is easier to read

@preetapan preetapan merged commit cc56c54 into f-affinities-spread Aug 31, 2018
@preetapan preetapan mentioned this pull request Sep 4, 2018
@preetapan preetapan deleted the f-score-heap branch September 4, 2018 22:37
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants