2.1.2 Thinking Ahead Flashcards
1
Q
What is thinking ahead
A
- Requires us to take a step back and consider what the solution may look like, what it would entail, what conditions it would work under and how it will work with other wider systems
- Allows us to consider how solution might be built and make implementation decisions the problem would be broken down
2
Q
How do you identify different inputs and outputs
A
- To fully understand the problem it must be broken down into smaller problems usimg top-down design techniques
- allows a modular solution
- For each module, the identification of the inputs and outputs will be the first stage in developing a solution
3
Q
What are the important considerations to make when deciding the inputs and outputs
A
- Data Type -Ensure correct data is passed to the module
- Structure of the data - Will it be primitive data or data structure. String/list
- Validation - particular format/ acceptable range
- Number of Arguments - Does it require multiple parameters to be sent to it
- Where would the input come from/ output go -Will the data input be automatic or entered manually. Stored in database/ simple text file.
- Are there preconditions - Something need to happen in order to solve
4
Q
When handling user input what has to be done
A
- Validation will need to be coded into the module to ensure the data is in the correct format for the program to process
- This is to be prevent incorrect data entering the system
- Bugs may occur if invalid data is inputted. Allow hackers to bypass security
- Bigger problem is modules are daisy chained (out of 1 is input of another)
5
Q
How do you use cache
A
- When requesting data the request will go via the cache.
- The cache is smaller and faster than the original data source and will hold a subset of the original data.
- If the requested data is in cache then the copy in cache is returned - cache hit
- However, if the data isn’t in cache it must be copied from the original data source into cache and then returned to the user - cache miss
- A cache miss is very slow even slower than going directly to the data source
6
Q
What is a hit ratio/ hit percentage
A
- The number of times a cache is hit or missed will determine its overall performance
- This can be measured by comparing the number of hits vs the misses, known as the hit rate/hit ratio which is expressed as a percentage
7
Q
What is Cache management - reading
A
- When a cache miss occurs, an algorithm will be required to decide which if any data entry should be ejected from the cache to make way for new data
- The choice of algorithm directly impacts efficiency of the cache and how fast a cache can be managed.
8
Q
What are different algorithms that can be used to decide which data entry is taken out of cache
A
- Clairvoyant Algorithm
- Least Recently Used Algorithm
- Using a counter
9
Q
What is the Clairvoyant Algorithm
A
- Will swap out entries that aren’t going to be used for the longest amount of time
- This requires information about the future use of cache, it is not realistically implementable in general purpose computers
- At any given point, this algorithm will always make the right choice for a swap to ensure the hit rate is as high as possible
- This can be approximated by using analysis of the past use of cache
- Performance of any caching algorithm can be measured by comparing the hit rate to the clairvoyant algorithm
10
Q
What is the Least Recently Used Algorithm
A
- Will swap out the least recently used page or entry
- This uses historic information rather than predicting the future
- 1 Way to implement LRU is to use a linked list
- Front of list = recently used and back = not recently used
11
Q
How is the counter used as a caching algorithm
A
- For every access to cache assigns the value of the counter to the entry and increments it by 1
- That way the entry with the lowest counter would be removed
12
Q
What are the 2 ways of cache writing management
A
- When dealing with making changes to the underlying data source of a cache there are 2 main strategies
- One is to update both the cache and the data source at once (known as write through)
- The other is to initially update the cache and only update the underlying data source when its data is ejected from cache (write back)
13
Q
What is Write Through
A
- This method will update both the cache and the data source at the same time
- This is simple to implement, however all data writes will be slow as it has to be written to both
- This is particularly problematic if there is a large number of write occurs
- Simple to implement however data writing is slow.
14
Q
What is Write Back
A
- This method will initially update the cache and only update the underlying data source when the data is ejected from the cache
- Write back will perform better if the hit rate is high, however, it is more complex to implement
- Every cache entry is given a dirty flag.
- When an entry is first added to cache the dirty flag is false. When an update occurs the flag is set to true
- When the entry is ejected, the flag is checked and the original data source is updated. Entry ejected with flag set to true will need to be saved to the backing store.
15
Q
What are the 3 types of caching
A
- CPU cache
- Disk caching
- Web caching