How Computer Uses Resources

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.


Understanding Computer Resource Constraints

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.


Data Access Speed Hierarchy

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 Performance Comparison

Storage LocationAccess SpeedUse Case
CPU Internal Memory (Registers)FastestCurrently executing function variables
RAM (Random Access Memory)Very FastRunning program data not in current function
Disk StorageSlowFile-based data and persistent storage
Network StorageSlowestRemote data requiring transmission and connection

Data Retrieval Scenarios

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.


Optimization Strategies for Data Access

Reducing Network Access

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.

Reducing Disk Access

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.

Cache Implementation

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.


Common Caching Examples in IT

Caches are implemented throughout IT infrastructure to improve performance:

Cache TypePurposeBenefit
Web ProxyStores websites, images, videos accessed by usersEliminates repeated downloads from the Internet
DNS CacheStores resolved domain name to IP address mappingsAvoids repeated queries to external DNS servers
Operating System CacheKeeps frequently accessed file contents and libraries in RAMProvides fast access even when not actively in use

Web Proxy Caching

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 Service Caching

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.

Operating System Caching

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.


Memory Management and Limitations

RAM Limitations

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.

Handling Memory Exhaustion

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.


Understanding Swap Memory

Swap Space Fundamentals

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 vs. Excessive Swapping

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.


Troubleshooting Excessive Swapping

When a machine is slow because it’s spending a lot of time swapping, there are three possible reasons and solutions:

Solutions for Swapping Issues

ReasonSolutionAction
Too many open applicationsClose unnecessary applicationsClose programs that aren’t currently needed
Insufficient RAM for workloadHardware upgradeAdd more RAM to the computer
Memory leak in running programRestart affected programIdentify and restart the program with the leak

Memory Leak Identification

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.


Conclusion

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.


FAQ