Skip to content

rishi-tiwari023/disk-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Disk Scheduler

A comprehensive npm package implementing all basic OS disk scheduling algorithms for educational and practical purposes.

πŸš€ Features

This package provides implementations of the following disk scheduling algorithms:

  • FCFS (First Come First Serve) - Processes requests in the order they arrive
  • SSTF (Shortest Seek Time First) - Selects the request with minimum seek time
  • SCAN - Moves the disk arm in one direction until it reaches the end, then reverses
  • C-SCAN - Circular SCAN that returns to the beginning after reaching the end
  • LOOK - Similar to SCAN but stops at the last request in each direction
  • C-LOOK - Circular LOOK that returns to the first request after reaching the last

πŸ“¦ Installation

npm install disk-scheduler

🎯 Usage

Basic Usage

import { 
  fcfs, 
  sstf, 
  scan, 
  cscan, 
  look, 
  clook,
  DiskScheduler,
  SchedulingResult 
} from 'disk-scheduler';

// Create a disk scheduler instance
const scheduler = new DiskScheduler();

// Example: FCFS scheduling
const requests = [98, 183, 37, 122, 14, 124, 65, 67];
const initialHead = 53;
const totalCylinders = 200;

const result: SchedulingResult = scheduler.fcfs(requests, initialHead, totalCylinders);

console.log(`Total head movements: ${result.totalHeadMovements}`);
console.log(`Seek sequence: ${result.seekSequence.join(' -> ')}`);
console.log(`Average seek time: ${result.averageSeekTime}`);

All Algorithms

// FCFS - First Come First Serve
const fcfsResult = scheduler.fcfs(requests, initialHead, totalCylinders);

// SSTF - Shortest Seek Time First
const sstfResult = scheduler.sstf(requests, initialHead, totalCylinders);

// SCAN - with direction
const scanLeftResult = scheduler.scan(requests, initialHead, totalCylinders, 'left');
const scanRightResult = scheduler.scan(requests, initialHead, totalCylinders, 'right');

// C-SCAN - Circular SCAN
const cscanResult = scheduler.cscan(requests, initialHead, totalCylinders, 'right');

// LOOK - optimized SCAN
const lookResult = scheduler.look(requests, initialHead, totalCylinders, 'left');

// C-LOOK - Circular LOOK
const clookResult = scheduler.clook(requests, initialHead, totalCylinders, 'right');

Using Individual Functions

// You can also use individual algorithm functions directly
import { fcfs, sstf, scan, cscan, look, clook } from 'disk-scheduler';

const result = fcfs(requests, initialHead);
const scanResult = scan(requests, initialHead, totalCylinders, 'left');

πŸ“Š Algorithm Comparison

Algorithm Advantages Disadvantages Best Use Case
FCFS Simple, fair High seek time When simplicity is preferred
SSTF Lower average seek time Starvation possible Interactive systems
SCAN No starvation, good performance Uneven wait times General purpose
C-SCAN More uniform wait times Higher seek time than SCAN Real-time systems
LOOK Better than SCAN Similar to SCAN Modern systems
C-LOOK Best uniform wait times Complex implementation High-performance systems

πŸ“ Examples

Check out the comprehensive examples in the examples/ directory:

  • basic-usage.js - Complete usage examples for all algorithms
  • performance-benchmark.js - Performance testing and comparison suite
  • typescript-example.ts - TypeScript usage with full type safety
  • README.md - Detailed examples documentation
# Run basic examples
node examples/basic-usage.js

# Run performance benchmarks
node examples/performance-benchmark.js

# Compile and run TypeScript example
npx tsc examples/typescript-example.ts --target es2020 --module commonjs
node examples/typescript-example.js

πŸ§ͺ Testing

npm test

πŸ“ˆ Performance Metrics

Each algorithm returns a SchedulingResult object containing:

  • totalHeadMovements: Total number of cylinder movements
  • seekSequence: Array showing the order of cylinder access
  • averageSeekTime: Average time per seek operation
  • algorithm: Name of the algorithm used

πŸ”§ Development

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev

# Run tests
npm test

πŸ“š Educational Value

This package is designed for:

  • Students learning operating systems concepts
  • Developers implementing disk management systems
  • Researchers comparing algorithm performance
  • Educators demonstrating scheduling concepts

Learning Path

  1. Start with examples/basic-usage.js - Understand basic algorithm differences
  2. Run examples/performance-benchmark.js - See performance characteristics
  3. Study examples/typescript-example.ts - Learn proper TypeScript integration
  4. Experiment with different workloads - Modify examples with your own data

🀝 Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests for any improvements.

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ—“οΈ Development Progress

This package is being developed over a 7-day period with daily commits. See PROGRESS.md for detailed development timeline and milestones.

About

A comprehensive TypeScript package implementing all 6 major disk scheduling algorithms (FCFS, SSTF, SCAN, C-SCAN, LOOK, C-LOOK) with full type safety, performance benchmarks, and educational examples for operating systems learning.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors