psantacl commented on code in PR #935:
URL: https://github.com/apache/yunikorn-core/pull/935#discussion_r1710019947


##########
pkg/common/resources/resources.go:
##########
@@ -455,6 +455,74 @@ func (r *Resource) fitIn(smaller *Resource, skipUndef 
bool) bool {
        return true
 }
 
+// Denominator Resources can be either guaranteed Resources or fairmax 
Resources.
+// If the quanity is explicitly 0 or negative, we will check usage.  If usage 
>= 0, the share will be set to 1.0.  Otherwise, it will be set 0.0.
+func getShareFairForDenominator(resourceType string, allocated Quantity, 
denominatorResources *Resource) (float64, bool) {
+       if denominatorResources == nil {
+               return 0.0, false
+       }
+
+       denominator, ok := denominatorResources.Resources[resourceType]
+
+       switch {
+       case ok && denominator <= 0:
+               if denominator < 0 {
+                       log.Log(log.Resources).Debug("denominator is negative. 
will not compute share",
+                               zap.String("resource key", resourceType),
+                               zap.Int64("resource quantity", 
int64(denominator)))
+               }
+
+               if allocated <= 0 {
+                       //explicit 0 or negative value with NO usage
+                       return float64(0.0), true
+
+               } else {
+                       //explicit 0 or negative value with usage
+                       return float64(1.0), true
+
+               }
+       case denominator > 0:
+               return (float64(allocated) / float64(denominator)), true
+
+       default:
+               //no denominator. ie. no guarantee or fairmax for resourceType
+               return 0.0, false
+       }
+}
+
+// For a given queue, produce a ratio which represents it's current 'fair' 
share usage.
+// Iterate over all of the allocated resource types.  For each, compute the 
ratio, ultimately returning the max ratio encountered.
+// The numerator will be the allocated usage.
+// If guarantees are present, they will be used for the denominator, otherwise 
we will fallback to the 'maxfair' capacity of the cluster.
+func getFairShare(allocated, guaranteed, fair *Resource) float64 {
+       if allocated == nil || len(allocated.Resources) == 0 {
+               return float64(0)

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to