How to display top K nodes w.r.t CPU usage?

63 Views Asked by At

I have an API service that returns the cpu count of each node in the cluster. My task is to return the top K nodes with cpu count.

How do I resolve this in an efficient way while building a cli tool?

Here is what I have thought of:

  1. Fetch, sort, return top k
  2. Maintain a heap, when the query comes, return the first k elements from heap.

I do not think both the methods are efficient as the first one will be slow and the second one will have intricacies involved with memory usage. What algorithm/method should I use?

0

There are 0 best solutions below