X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6f15deea24d3544e08ba6c5681d2a2a11de40971..eb5b8638a308f7954f83a6a6659ae97d4f4e082d:/services/workbench2/src/views/instance-types-panel/instance-types-panel.tsx

diff --git a/services/workbench2/src/views/instance-types-panel/instance-types-panel.tsx b/services/workbench2/src/views/instance-types-panel/instance-types-panel.tsx
index 22617d8c86..2f240c8228 100644
--- a/services/workbench2/src/views/instance-types-panel/instance-types-panel.tsx
+++ b/services/workbench2/src/views/instance-types-panel/instance-types-panel.tsx
@@ -77,8 +77,9 @@ export const InstanceTypesPanel = withStyles(styles)(connect(mapStateToProps)(
                         }
                     }).map((instanceKey) => {
                         const instanceType = instances[instanceKey];
-                        const diskRequest = instanceType.IncludedScratch;
-                        const ramRequest = instanceType.RAM - config.Containers.ReserveExtraRAM;
+                        const maxDiskRequest = instanceType.IncludedScratch;
+                        const keepBufferOverhead = calculateKeepBufferOverhead(instanceType.VCPUs);
+                        const maxRamRequest = discountRamByPercent(instanceType.RAM - config.Containers.ReserveExtraRAM - keepBufferOverhead);
 
                         return <Grid data-cy={instanceKey} className={classes.instanceType} item sm={6} xs={12} key={instanceKey}>
                             <Card>
@@ -90,16 +91,16 @@ export const InstanceTypesPanel = withStyles(styles)(connect(mapStateToProps)(
                                         <DetailsAttribute label="Provider type" value={instanceType.ProviderType} />
                                     </Grid>
                                     <Grid item xs={12}>
-                                        <DetailsAttribute label="Price" value={instanceType.Price} />
+                                        <DetailsAttribute label="Price" value={formatCost(instanceType.Price)} />
                                     </Grid>
                                     <Grid item xs={12}>
                                         <DetailsAttribute label="Cores" value={instanceType.VCPUs} />
                                     </Grid>
                                     <Grid item xs={12}>
-                                        <DetailsAttribute label="Max RAM request" value={`${formatCWLResourceSize(ramRequest)} (${formatFileSize(ramRequest)})`} />
+                                        <DetailsAttribute label="Max RAM request" value={`${formatCWLResourceSize(maxRamRequest)} (${formatFileSize(maxRamRequest)})`} />
                                     </Grid>
                                     <Grid item xs={12}>
-                                        <DetailsAttribute label="Max disk request" value={`${formatCWLResourceSize(diskRequest)} (${formatFileSize(diskRequest)})`} />
+                                        <DetailsAttribute label="Max disk request" value={`${formatCWLResourceSize(maxDiskRequest)} (${formatFileSize(maxDiskRequest)})`} />
                                     </Grid>
                                     <Grid item xs={12}>
                                         <DetailsAttribute label="Preemptible" value={instanceType.Preemptible.toString()} />
@@ -129,3 +130,19 @@ export const InstanceTypesPanel = withStyles(styles)(connect(mapStateToProps)(
         </Grid>;
     }
 ));
+
+export const calculateKeepBufferOverhead = (coreCount: number): number => {
+    // TODO replace with exported server config
+    const buffersPerVCPU = 1;
+
+    // Returns 220 MiB + 64MiB+10% per buffer
+    return (220 << 20) + (buffersPerVCPU * coreCount * (1 << 26) * (11/10))
+};
+
+export const discountRamByPercent = (requestedRamBytes: number): number => {
+    // TODO replace this with exported server config or remove when no longer
+    // used by server in ram calculation
+    const discountPercent = 5;
+
+    return requestedRamBytes * 100 / (100-discountPercent);
+};
