disk-scheduler
v1.0.0
Published
A comprehensive npm package implementing all basic OS disk scheduling algorithms including FCFS, SSTF, SCAN, C-SCAN, LOOK, and C-LOOK
Maintainers
Readme
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 algorithmsperformance-benchmark.js- Performance testing and comparison suitetypescript-example.ts- TypeScript usage with full type safetyREADME.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 movementsseekSequence: Array showing the order of cylinder accessaverageSeekTime: Average time per seek operationalgorithm: 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
- Start with
examples/basic-usage.js- Understand basic algorithm differences - Run
examples/performance-benchmark.js- See performance characteristics - Study
examples/typescript-example.ts- Learn proper TypeScript integration - 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.
