implementation of raid calculator with levels 0, 1, 5, 6, and 10

need to add descriptions yet
This commit is contained in:
Rob Weber 2024-07-28 20:25:09 +00:00
parent 76a19d218d
commit 37cfd0a105
7 changed files with 247 additions and 7 deletions

View file

@ -0,0 +1,12 @@
import { Database } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'RAID Calculator',
path: '/raid-calculator',
description: 'Calculate storage capacity and fault tolerance of an array based on the number of disks, size, and RAID type',
keywords: ['raid', 'calculator'],
component: () => import('./raid-calculator.vue'),
icon: Database,
createdAt: new Date('2024-07-27'),
});

View file

@ -0,0 +1,15 @@
import { test, expect } from '@playwright/test';
test.describe('Tool - RAID Calculator', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/raid-calculator');
});
test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('RAID Calculator - IT Tools');
});
test('', async ({ page }) => {
});
});

View file

@ -0,0 +1,6 @@
import { expect, describe, it } from 'vitest';
// import { } from './raid-calculator.service';
//
// describe('raid-calculator', () => {
//
// })

View file

@ -0,0 +1,94 @@
export { raidCalculations };
const raidCalculations = {
raid_0: {
about: 'RAID 0 splits data evenly across 2 or more disks with redunancy or fault tolerance. More info: <a href="https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_0">Wikipedia</a>',
requirements: 'RAID 0 requires at least 1 disk',
validate: function(num, size){
return num > 1
},
capacity: function(num, size, unit){
// total disks * size
return (num * size) * unit;
},
speed: function(num, size, unit){
return `${num}x read and ${num}x write speed gain`;
},
fault: function(num, size, unit){
return "None";
}
},
raid_1: {
about: 'RAID 1 consists of an exact copy of the data across two or moe disks. The array will operate as long as at least one drive is operational. More info: <a href="https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_1">Wikipedia</a>',
requirements: 'RAID 1 requires at least 1 disk',
validate: function(num, size){
return num > 1
},
capacity: function(num, size, unit){
// total size is size of a single drive
return size * unit;
},
speed: function(num, size, unit){
// potential for all drives read at once
return `Potential ${num}x read and no write speed gain`;
},
fault: function(num, size, unit){
// FT = total - 1
return `${num -1} drive failures`;
}
},
raid_5: {
about: 'This is RAID 5',
requirements: 'RAID 5 requires at least 3 disks',
validate: function(num, size){
return num >= 3
},
capacity: function(num, size, unit){
// (N-1) * S (one drive for parity)
return ((num - 1) * size) * unit;
},
speed: function(num, size, unit){
return `${num - 1}x read speed gain and write speed penalty (due to parity calculations)`;
},
fault: function(num, size, unit){
// always 1 failure
return "1 drive failure";
}
},
raid_6: {
about: 'This is RAID 6',
requirements: 'RAID 6 requires at least 4 disks',
validate: function(num, size){
return num >= 4
},
capacity: function(num, size, unit){
// (N-2) * S (2 parity)
return ((num - 2) * size) * unit;
},
speed: function(num, size, unit){
return `${num - 2}x read speed gain and write speed penalty (due to parity calculations)`;
},
fault: function(num, size, unit){
// always 2 drive failures
return "2 drive failures";
}
},
raid_10: {
about: 'RAID 10 is generally recognized as a stripe of mirrors (RAID 1 + RAID 2). Each set of drives is mirrored and striped together so that each drive in the set is fault tolerant within the group. More info: <a href="https://en.wikipedia.org/wiki/Nested_RAID_levels#RAID_10_(RAID_1+0)">Wikipedia</a>',
requirements: 'RAID 10 requires an even number of at least 4 disks',
validate: function(num, size){
return num >= 4 && num % 2 == 0
},
capacity: function(num, size, unit){
// Total disks (stripe)/2 (mirror)
return ((num * size) / 2) * unit;
},
speed: function(num, size, unit){
return `${num - 2}x read speed gain and write speed penalty (due to parity calculations)`;
},
fault: function(num, size, unit){
// always 2 drive failures
return "At least 1 drive failure per mirrored set";
}
}
}

View file

@ -0,0 +1,107 @@
<script setup lang="ts">
import { isNotThrowing } from '@/utils/boolean';
import { raidCalculations } from './raid-calculator.service';
const diskTotal = ref(2);
const diskSize = ref(100);
const diskUnit = ref(Math.pow(10, 9));
const raidType = ref('raid_0');
const raidInfo = computed(() => raidCalculations[raidType.value].about);
const raidRequirements = computed(() => raidCalculations[raidType.value].requirements);
const inputsValid = computed(() => validateSetup());
const calculatedCapacity = computed(() => {
// make sure values exist
if(diskTotal.value === undefined || diskSize.value === undefined)
{
return '';
}
return formatBytes(raidCalculations[raidType.value].capacity(diskTotal.value, diskSize.value, diskUnit.value));
});
const calculatedFaultTolerance = computed(() => {
// make sure values exist
if(diskTotal.value === undefined || diskSize.value === undefined)
{
return '';
}
return raidCalculations[raidType.value].fault(diskTotal.value, diskSize.value, diskUnit.value);
});
function validateSetup(){
// validate the selected RAID type against parameters
return raidCalculations[raidType.value].validate(diskTotal.value, diskSize.value);
}
// similar to the utility function but uses base 10 instead of base 2
function formatBytes(bytes: number, decimals = 2) {
if (bytes === 0) {
return '0 Bytes';
}
const k = Math.pow(10, 3);
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${Number.parseFloat((bytes / k ** i).toFixed(decimals))} ${sizes[i]}`;
}
</script>
<template>
<div>
<c-card>
<n-form-item label="Number of disks" label-placement="left" label-width="150" mb-2>
<n-input-number v-model:value="diskTotal" max="10000" min="2" placeholder="Number of disks (ex: 2)" w-full />
</n-form-item>
<n-form-item label="Disk size" label-placement="left" label-width="150" mb-2>
<n-input-number v-model:value="diskSize" max="10000" min="1" placeholder="Disk size (ex: 100)" w-full />
<div flex items-baseline gap-2>
<c-select
v-model:value="diskUnit"
min-w-130px
:options="[
{ label: 'MB', value: Math.pow(10, 6) },
{ label: 'GB', value: Math.pow(10, 9) },
{ label: 'TB', value: Math.pow(10, 12) },
{ label: 'PB', value: Math.pow(10, 15) },
]"
/>
</div>
</n-form-item>
<n-form-item label="RAID Type" label-placement="left" label-width="150" mb-2>
<c-select
v-model:value="raidType"
w-full
:options="[
{ label: 'RAID 0 (stripe)', value: 'raid_0' },
{ label: 'RAID 1 (mirror)', value: 'raid_1' },
{ label: 'RAID 5 (parity)', value: 'raid_5' },
{ label: 'RAID 6 (double parity)', value: 'raid_6' },
{ label: 'RAID 10 (mirror + stripe)', value: 'raid_10' },
]"
/>
</n-form-item>
<p class="raidError" v-if="!inputsValid">{{ raidRequirements }}</p>
<p v-else v-html="raidInfo"></p>
</c-card>
<c-card title="Results">
<n-statistic label="Capacity" mb-2 v-if="inputsValid">
{{ calculatedCapacity }}
</n-statistic>
<n-statistic label="Fault Tolerance" mb-2 v-if="inputsValid">
{{ calculatedFaultTolerance }}
</n-statistic>
</c-card>
</div>
</template>
<style lang="less" scoped>
.raidError {
color: rgb(208, 48, 80)
}
</style>