DEV Community

Cover image for I couldn't find a fun way to learn CPU scheduling so I built one
Arham_Q
Arham_Q

Posted on

I couldn't find a fun way to learn CPU scheduling so I built one

What Happens When You Don't Find a Perfect Tool for Learning!
Start with the exact moment you got frustrated, the lecture, the textbook diagram that made no sense, or whatever it was. Personal and specific beats generic every time.

The issue
Every CS student has felt this way. Your teacher draws a Gantt chart on the board and talks about FCFS and Round Robin. You nod along as if you understand. You open your textbook, and all you see are more static diagrams.
I wanted something that I could do. Something that really showed me what was going on step by step. I looked around and couldn't find anything that didn't look like it was made in 2003.
I made it myself.

The thought
What if algorithms could battle each other? Algo Wars is a game-like CPU scheduling simulator where you can put two algorithms against each other and watch them compete in real time.

What broke first, the Gantt chart
The first version of mine loaded the Gantt chart in a static way. The whole thing just showed up at once, which ruined the point. You couldn't see the scheduling happen; you could only see the end result.
So I completely changed it. Changed the output to JSON and sent it to the chart one block at a time. It came to life all of a sudden. You could see the CPU choose which process to run next.
That one change made the whole thing seem real.

The last boss is MLQ
The Gantt chart was like a mid-level enemy, and multilevel queue scheduling was the final boss. There are multiple queues, each with its own priority and running a different algorithm at the same time. They all work together without getting in each other's way.
It took the longest to get that logic right. The best :(ย part of the whole build.

A peek at the piece of Code
This code show the star feature, How the two algorithms run side by side and compare the efficiency
This code show the star feature, How the two algorithms run side by side and compare the efficiency

Try it yourself
The repo is open. Feedback, bug reports, pull requests, all welcome.
Visit https://github.com/Arham-Qureshi/Algo-wars/
live: https://algo-wars-rust.vercel.app/

Top comments (0)