DEV Community

Cover image for CPU Bound vs I/O Bound
Bharath Muppa for Entangled Cognition

Posted on • Updated on

CPU Bound vs I/O Bound

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

  1. you need a chef(s) πŸ‘¨β€πŸ³
  2. Warehouse for food Storage🏭

1. Hire a Chef (Buy CPU)

The chef is the one who is responsible for all your recipes.

Giffy

  • 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).

Big Bang Theory

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

2. Establish a Delivery system.

  • πŸ’½ 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.

  1. 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.

  2. 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

Analogy Reality
Restaurant Whole Computer
Chef Processor
4 handed Chef Quad-core Processor
Recipes Threads
Deliver system All other than processor
Special Shrimp Chef GPU or FPGA or TPU

Overview of processing units

Without Analogy, in simple terms.

CPU Bound

We can say a program/language is CPU Bound if it has to

  1. process more Data CPU
  2. processing audio or video GPU
  3. Processing vector instructions (VPU)

Example application: Photo Editors, Gaming, Video Editors

IO Bound

We can say a program/language is IO Bound if it has to do

  1. file reading/writing
  2. Do a Network call or responds to more network calls

Example application: Chat applications, Feeds, Bank applications

NOTE
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.

Now entering into an Opinionated Zone⚑

Giphy
Lets put our knowledge into a matrix while choosing a language if you are asked to build an application.

Note

  • 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.
Application Language
Chat app Node
Data-Intensive Java, c#
Photoshop Java, c#
Web Scrapping Python, Node

Reference

Discussion (0)