This document explains how computers utilize different resources like CPU RAM, disk, and network, including data access speeds, caching strategies, and memory management techniques such as swapping.
This document explores how computers utilize different resources including CPU, RAM, disk storage, and network connectivity. It covers data access speeds across storage hierarchies, caching strategies for performance optimization, and memory management techniques including swapping mechanisms.
Computers can be constrained by different resources such as CPU, disk, memory, or network. To boost system performance, it’s essential to eliminate bottlenecks and optimize how the computer uses its resources. This requires understanding how each component interacts with others and what the limitations are for each resource type.
When thinking about making things faster, understanding the different speeds of the parts involved is critical. Performance optimization depends on knowing where data resides and how quickly it can be accessed.
The time spent retrieving data depends entirely on where it’s located in the storage hierarchy. Different storage locations offer vastly different access speeds.
| Storage Location | Access Speed | Use Case |
|---|---|---|
| CPU Internal Memory (Registers) | Fastest | Currently executing function variables |
| RAM (Random Access Memory) | Very Fast | Running program data not in current function |
| Disk Storage | Slow | File-based data and persistent storage |
| Network Storage | Slowest | Remote data requiring transmission and connection |
When an application accesses data, the retrieval time varies based on location:
CPU Internal Memory: If the data is a variable currently being used in a function, it will be in the CPU’s internal memory, and the program will retrieve it extremely fast.
RAM Access: If the data is related to a running program but not the currently executing function, it will likely be in RAM, and the program will still access it quite fast.
Disk Access: If the data is in a file, the program will need to read it from disk, which is much slower than reading from RAM.
Network Access: Reading information over the network is the slowest option. This involves lower transmission speeds and requires establishing a connection to the other endpoint, adding to the total time needed to access the data.
If a process requires repeatedly reading data over the network, consider reading it once and storing it on disk, then reading from disk afterwards. This eliminates repeated network overhead.
If files are repeatedly read from disk, consider putting the same information directly into process memory to avoid loading from disk every time. This keeps frequently accessed data in faster storage.
A cache stores data in a form that’s faster to access than its original form. Caching is one of the most effective optimization strategies in computing.
Caches are implemented throughout IT infrastructure to improve performance:
| Cache Type | Purpose | Benefit |
|---|---|---|
| Web Proxy | Stores websites, images, videos accessed by users | Eliminates repeated downloads from the Internet |
| DNS Cache | Stores resolved domain name to IP address mappings | Avoids repeated queries to external DNS servers |
| Operating System Cache | Keeps frequently accessed file contents and libraries in RAM | Provides fast access even when not actively in use |
A web proxy is a form of cache that stores websites, images, or videos accessed often by users behind the proxy. This prevents the need to download from the Internet every time the same resource is requested.
DNS services usually implement a local cache for the websites they resolve, so they don’t need to query from the Internet every time someone asks for an IP address.
The operating system takes care of automatic caching by trying to keep as much information as possible in RAM for fast access. This includes the contents of files or libraries that are accessed often, even if they aren’t in use right now. These contents are said to be cached in memory.
If data is part of a program that’s currently running, it will be in RAM. However, RAM is limited. If enough programs run at the same time, the RAM will fill up and run out of space.
When RAM runs out, the operating system follows a specific process:
Initial Response: The OS will first remove from RAM anything that’s cached but not strictly necessary.
Swapping Mechanism: If there’s still not enough RAM after clearing caches, the operating system will put the parts of memory that aren’t currently in use onto the hard drive in a space called swap.
Reading and writing from disk is much slower than reading and writing from RAM. When swapped-out memory is requested by an application, it will take a while to load it back into RAM.
The swapping implementation varies across different operating systems, but the concept is always the same: information that’s not needed right now is removed from RAM and put onto the disk, while information that’s needed now is loaded into RAM.
Normal Operation: This is normal operation, and most of the time, swapping goes unnoticed. The system manages memory efficiently in the background.
Performance Degradation: If the available memory is significantly less than what the running applications need, the OS will have to keep swapping out data that’s not in use right now to move the currently needed data into RAM.
Since computers can switch between applications very quickly, the data currently in use can also change very quickly. The computer will start spending a lot of time writing to disk to make space in RAM and then reading from disk to put other things in RAM. This can be extremely slow.
When a machine is slow because it’s spending a lot of time swapping, there are three possible reasons and solutions:
| Reason | Solution | Action |
|---|---|---|
| Too many open applications | Close unnecessary applications | Close programs that aren’t currently needed |
| Insufficient RAM for workload | Hardware upgrade | Add more RAM to the computer |
| Memory leak in running program | Restart affected program | Identify and restart the program with the leak |
A memory leak means that memory which is no longer needed is not getting released. If a program is using a lot of memory and this usage stops when the program is restarted, it’s probably because of a memory leak. Memory leaks will be discussed in detail later in the course.
Important
Excessive swapping is a critical performance bottleneck. The system spends more time moving data between RAM and disk than actually processing data, severely degrading overall performance.
Note
Modern operating systems are designed to handle memory management automatically. However, understanding the swap mechanism helps diagnose performance issues when they occur.
Understanding how computers use resources is fundamental to troubleshooting performance issues. Data access speeds vary dramatically across the storage hierarchy, from lightning-fast CPU registers to slow network access. Caching strategies at multiple levels help bridge these speed gaps by storing frequently accessed data in faster storage. When RAM becomes insufficient, the operating system uses swap space on disk, but excessive swapping can severely degrade performance. The three main solutions to swapping issues are closing unnecessary applications, adding more RAM, or fixing memory leaks. Effective resource management requires balancing workload demands against available hardware capabilities while leveraging caching to optimize performance.