Before Understanding what is CPU Bound and IO Bound, I would like to touch the basic understanding of how CPU and IO work, then slowly dwell into the above concepts.
There is a simple analogy to understand in a better way.
Let's assume you want to start a Huge Restaurant(computer).
There are primarily 2 Requirements
- you need a chef(s) 👨🍳
- Warehouse for food Storage🏭
The chef is the one who is responsible for all your recipes.
- Depending on your requirements, you have to hire a chef(CPU). If you spend more 🤑 you will get a master chef and he can add more recipes to the menu, cooks fast, reduce cost with his experience.
- Let's say your city is famous for Shrimps, So you have to hire a chef who is specialized in making different shrimps (GPU).
Tasks of CPU
1. Fetch instructions from memory
2. Decode into binary instructions
3. Execute action and move to next step
4. Write output to memory
- 💽 As we need to store all the groceries and food items required for recipes beforehand, we need warehouses (can be RAM, HardDisk, USB, Flash Drive)
- 🚚 We also need a transport system to transport data (PCIe express, SATA, Data Bus).
- you also need to establish a connection with dealers at the market to get fresh food/shrimps at a low price. (Network calls, Mounted Drives)
Ok, you are good to start a Restaurant now.
Let's think of 2 scenarios.
Your Restaurant becomes famous and getting more orders, so you need a chef to chop some millions of vegetables for a thousand orders. If your chef is slow you can't deliver what customers want on time, so you need a fast chef to chop all the vegetables required and prepare the recipe.
Your chef needs a thousand food items and millions of groceries to prepare food. This is not the concern of the chef, this is the responsibility of all others it might be warehouse storage, market guys and transport persons.
I think it is quite a simple scenario. If yes you already understand what is CPU bound and IO Bound.
If you didn't really understand the anaology..no need to worry, we can simplify it by Demystifying the analogy
|4 handed Chef||Quad-core Processor|
|Deliver system||All other than processor|
|Special Shrimp Chef||GPU or FPGA or TPU|
Without Analogy, in simple terms.
We can say a program/language is CPU Bound if it has to
Example application: Photo Editors, Gaming, Video Editors
We can say a program/language is IO Bound if it has to do
- file reading/writing
- Do a Network call or responds to more network calls
Example application: Chat applications, Feeds, Bank applications
It doesn't mean if an application is CPU bound, then it should not do any IO Operations and viceversa
Now everyone is on the same page and hopefully understood core concepts.
- I am considering out of the box architecture of corresponding languages. As every language has a possibility to use thread pools, multi processes, multi-threads.
- I want to exclude c and c++ because of their power and also theirs difficulty in creating the application for beginners.
|Web Scrapping||Python, Node|
- Credits for this analogy should be given to (David Xiang)[https://twitter.com/davex_tech] and his book Software Developer Life: Career, Learning, Coding, Daily Life, Stories
- Introduction to threading