Skip to content

Commit

Permalink
length check (#4062)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Dec 8, 2023
1 parent d0816dc commit 85ee08a
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions dashboard/src/lib/hooks/useClusterResourceLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,31 @@ export const useClusterResourceLimits = ({
useEffect(() => {
if (getClusterNodes.isSuccess) {
const data = getClusterNodes.data;
// this logic handles CPU and RAM independently - we might want to change this later
const maxCPU = data.reduce((acc, curr) => {
return Math.max(acc, curr.maxCPU);
}, 0);
const maxRAM = data.reduce((acc, curr) => {
return Math.max(acc, curr.maxRAM);
}, 0);
let maxMultiplier = SMALL_INSTANCE_UPPER_BOUND;
// if the instance type has more than 4 GB ram, we use 90% of the ram/cpu
// otherwise, we use 75%
if (maxRAM > 4) {
maxMultiplier = LARGE_INSTANCE_UPPER_BOUND;
if (data.length) {
// this logic handles CPU and RAM independently - we might want to change this later
const maxCPU = data.reduce((acc, curr) => {
return Math.max(acc, curr.maxCPU);
}, 0);
const maxRAM = data.reduce((acc, curr) => {
return Math.max(acc, curr.maxRAM);
}, 0);
let maxMultiplier = SMALL_INSTANCE_UPPER_BOUND;
// if the instance type has more than 4 GB ram, we use 90% of the ram/cpu
// otherwise, we use 75%
if (maxRAM > 4) {
maxMultiplier = LARGE_INSTANCE_UPPER_BOUND;
}
// round down to nearest 0.5 cores
const newMaxCPU = Math.floor(maxCPU * maxMultiplier * 2) / 2;
// round down to nearest 100 MB
const newMaxRAM =
Math.round((convert(maxRAM, "GiB").to("MB") * maxMultiplier) / 100) *
100;
setMaxCPU(newMaxCPU);
setMaxRAM(newMaxRAM);
setDefaultCPU(Number((newMaxCPU * DEFAULT_MULTIPLIER).toFixed(2)));
setDefaultRAM(Number((newMaxRAM * DEFAULT_MULTIPLIER).toFixed(0)));
}
// round down to nearest 0.5 cores
const newMaxCPU = Math.floor(maxCPU * maxMultiplier * 2) / 2;
// round down to nearest 100 MB
const newMaxRAM =
Math.round((convert(maxRAM, "GiB").to("MB") * maxMultiplier) / 100) *
100;
setMaxCPU(newMaxCPU);
setMaxRAM(newMaxRAM);
setDefaultCPU(Number((newMaxCPU * DEFAULT_MULTIPLIER).toFixed(2)));
setDefaultRAM(Number((newMaxRAM * DEFAULT_MULTIPLIER).toFixed(0)));
}
}, [getClusterNodes]);

Expand Down

0 comments on commit 85ee08a

Please sign in to comment.