Browse Source

change logic to determine max resource limits (#3708)

Feroze Mohideen 2 years ago
parent
commit
3dfc881251

+ 19 - 7
dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceContainer.tsx

@@ -50,7 +50,7 @@ const ServiceContainer: React.FC<ServiceProps> = ({
     // round to 100
     Math.round(
       convert(AWS_INSTANCE_LIMITS["t3"]["medium"]["RAM"], "GiB").to("MB") *
-      UPPER_BOUND / 100 
+      UPPER_BOUND / 100
     ) * 100
   ); //default is set to a t3 medium
   const context = useContext(Context);
@@ -137,12 +137,24 @@ const ServiceContainer: React.FC<ServiceProps> = ({
               }
             });
 
-            setMaxCPU(Math.fround(largestInstanceType.vCPUs * UPPER_BOUND));
-            setMaxRAM(
-              Math.round(
-                convert(largestInstanceType.RAM, "GiB").to("MB") * UPPER_BOUND / 100
-              ) * 100
-            );
+            // if the instance type has more than 4 GB ram, we use 90% of the ram/cpu
+            // otherwise, we use 75%
+            if (largestInstanceType.RAM > 4) {
+              // round down to nearest 0.5 cores
+              setMaxCPU(Math.floor(largestInstanceType.vCPUs * 0.9 * 2) / 2);
+              setMaxRAM(
+                Math.round(
+                  convert(largestInstanceType.RAM, "GiB").to("MB") * 0.9 / 100
+                ) * 100
+              );
+            } else {
+              setMaxCPU(Math.floor(largestInstanceType.vCPUs * UPPER_BOUND * 2) / 2);
+              setMaxRAM(
+                Math.round(
+                  convert(largestInstanceType.RAM, "GiB").to("MB") * UPPER_BOUND / 100
+                ) * 100
+              );
+            }
           }
         })
         .catch((error) => { });