1.
Efficient Use of Main Memory and Parallelization:
- Not sufficient to merely increase memory and CPU cores.
- Essential to design databases that make efficient use of memory and distribute tasks across
multiple cores.
- Parallelization means breaking down tasks so they can be processed simultaneously, maximizing
CPU core utilization.
- Importance of memory allocation strategies to avoid wastage.
- Parallel processing helps in executing large data operations more efficiently.
- Effective task distribution ensures balanced workload across CPU cores.
2. Physical and Logical Design:
- Physical design involves optimizing hardware use (memory, CPU).
- Logical design involves structuring data efficiently, aligning with operational needs.
- Examples include organizing data to minimize retrieval times and reduce processing load.
- Physical design can include hardware-specific optimizations like NUMA (Non-Uniform Memory
Access).
- Logical design might involve indexing strategies to speed up data retrieval.
- Combining physical and logical improvements results in significant performance gains.
3. Existing Technologies and Their Limitations:
- In-memory and column-oriented databases are not new but were limited to specific applications.
- Many enterprise applications are optimized only in parts for parallel processing, not end-to-end.
- Hardware advancements like reduced memory costs and increased CPU cores make broader
application possible.
- Earlier limitations due to high memory costs and fewer CPU cores.
- Need for holistic optimization, not just isolated improvements in parts of the system.
- Integration challenges with legacy systems that weren't designed for modern hardware
efficiencies.
Understanding Memory Hierarchies
Introduction to Main Memory
- Program Structure:
- Divided into instructions (controls execution) and data (variables, components).
- Both parts need to be in main memory for the CPU to process them.
- Main Memory Characteristics:
- Made from DRAM, ideally provides constant access time.
- In reality, access times vary due to caching mechanisms.
- Memory Segmentation:
- Divides memory into manageable segments for efficient access.
- Each segment can be accessed randomly or sequentially, impacting performance.
- Latency Penalties:
- Higher latency for random access compared to sequential access.
- Optimization involves minimizing random access where possible.
Experiment with Memory Access
- Memory Access Patterns:
- Access time varies based on the stride (distance) between memory addresses.
- This experiment shows the impact of memory access patterns on performance.
- Stride Impact:
- Different strides show how access patterns affect performance.
- Smaller strides typically result in faster access due to better cache utilization.
- Access Time Variations:
- Demonstrates the importance of understanding and optimizing memory access patterns.
Memory Caches
- Cache Hierarchy:
- Includes several levels (L1, L2, L3), each with different speeds and sizes.
- L1 is the fastest but smallest; L3 is larger but slower.
- Cache Line:
- Memory is accessed in blocks called cache lines, not byte by byte.
- Efficient access patterns can reduce cache misses and improve performance.
- Cache Misses:
- Occur when required data is not in the cache, causing delays as data is fetched from slower
memory levels.
- Cache Levels:
- Multiple cache levels ensure data is progressively closer to the CPU.
- Each level has different sizes and speeds, balancing cost and performance.
- Cache Line Efficiency:
- Accessing data in cache lines improves speed.
- Efficient use of cache lines minimizes the number of cache misses.
Optimizing Data Access
- Data Locality:
- Keeping related data close together to reduce cache misses.
- Important for maintaining high performance in memory-intensive applications.
- Column-wise Data Representation:
- Efficient for analytical tasks, accessing only relevant columns.
- Reduces unnecessary data retrieval, improving cache efficiency.
- Sequential Memory Access:
- Leveraging CPU prefetching to speed up sequential data access.
- Prefetching loads subsequent data in advance, reducing wait times.
- Data Prefetching:
- CPUs can anticipate the need for data and load it in advance.
- This reduces waiting times for data retrieval, speeding up processing.
- Analytical vs. Transactional Workloads:
- Different data access patterns for different types of workloads.
- Optimizations need to consider specific workload characteristics.
CPU and Memory Architecture
- Memory Hierarchy:
- Data transmission from main memory to CPU involves multiple layers.
- Each layer (L1, L2, L3 caches) adds latency but reduces access time compared to main memory.
- Inclusive Caching:
- Higher-level caches include data from lower levels, ensuring frequently used data is quickly
accessible.
- Reduces the need to fetch data from slower main memory.
- Bandwidth and Latency:
- Bandwidth: Data transmission capacity of a channel, measured in bytes/second.
- Latency: Time delay between data request and start of transmission.
- Closer memory (e.g., L1 cache) has higher bandwidth and lower latency, enhancing performance.
- Memory Layers:
- Data moves through various layers (main memory, caches) to reach the CPU.
- Each layer improves access speed but adds complexity.
- Cache Sharing:
- Some caches are shared among multiple CPU cores.
- This can impact performance, especially in multi-core processing environments.
- Latency and Bandwidth:
- Key factors in determining data access speeds.
- Optimizing these aspects is crucial for high-performance computing.
Organization of the Memory Hierarchy
Cache Organization and Replacement Strategies
- Objective: Maximize cache hits, minimize cache misses.
- Locality of Reference:
- Spatial Locality: CPU accesses adjacent memory cells frequently.
- Temporal Locality: CPU likely accesses recently used items again soon.
- Cache Operation:
- Cache loads memory blocks, including requested items and their neighbors, to exploit spatial
locality.
- CPU searches the cache for requested memory items; cache misses incur additional overhead.
Cache Associativity
- Direct Mapped Cache:
- Each memory block maps to one specific cache line.
- Conflict misses occur when multiple blocks map to the same line and cannot coexist in the cache.
- N-Way Set Associative Cache:
- Each memory block maps to a set of N cache lines.
- The block can be placed in any line within its set, offering more flexibility.
- Fully Associative Cache:
- A memory block can be stored in any cache line.
- Provides maximum flexibility but increases cache lookup time as all lines need to be scanned.
Trade-offs
- Higher associativity increases cache hit rates but also increases cache lookup latency.
- Practical implementation often uses up to 8-way associative caches to balance performance and
latency.
Multi-core Cache Organization
- Uncore Cache:
- An additional cache level shared among all CPU cores.
- Adds indirection but allows optimizations for multi-core software.
Cache Replacement Policies
- Temporal Locality Exploitation:
- Replacement strategies aim to retain frequently accessed items.
- Replacement Policies:
- FIFO (First In, First Out): Replaces the oldest cache line.
- LIFO (Last In, First Out): Replaces the most recently added cache line.
- LRU (Least Recently Used): Replaces the cache line that has not been used for the longest time
(optimal strategy).
Trends in Memory Hierarchies
Performance Gap and Storage Technologies
- Latency Gap: The difference in latency between storage media and other computing system
components is increasing.
- Research and Development: Efforts focus on new storage technologies to bridge this gap.
Storage-Class Memory
- Characteristics:
- Non-volatile, low latency, solid-state (no mechanical parts), cost-effective, and energy-efficient.
Flash Memory
- Advantages: Non-volatility, fast random read access, low power consumption.
- Drawbacks: Requires erase before writing, slower write performance for random writes, limited
durability (10^4-10^5 writes).
- Wear Leveling: Technique to distribute write accesses evenly to prolong flash memory life.
Usage in Databases
- Insert-Only Databases: Match flash memory advantages by reducing random writes and eliminating
in-place updates.
- Flash Memory as Cache or Persistent Storage:
- Can act as an additional cache level, but limited durability is a concern.
- Adaptation required in DBMS to leverage flash memory's potential, considering read/write
asymmetry.
Phase Change Memory (PCM)
- Mechanism: Uses chalcogenide alloys with two stable phases (high and low electrical resistance).
- Advantages over Flash:
- In-place updates (no need to erase before writing).
- Higher write endurance.
- Potential: Likely to replace disks in in-memory databases due to better endurance and performance,
bridging the gap between main memory and flash.
1. Memory Allocation and Writing Back
Direct Interaction with Main Memory
- Programming Languages: In low-level languages like C and C++, every memory operation
(read/write) directly interacts with main memory. Unlike higher-level languages where memory
management is abstracted, these languages expose the programmer to the underlying memory
architecture.
Block-Oriented Approach
- Cache Lines: Memory is accessed in blocks or lines, typically 64 bytes in modern CPUs. Efficient
access patterns are crucial to avoid performance penalties from additional memory fetches.
2. Optimization Techniques
Alignment
- Purpose: Aligning data structures to cache line boundaries (or specific alignment values) ensures
that memory accesses are efficient, minimizing cache misses.
- Function: `posix_memalign()` is used in POSIX systems to allocate memory aligned to specific
boundaries, improving performance for large data structures.
Padding
- Struct Padding: Padding adds extra bytes to data structures to align them to cache line boundaries,
reducing the overhead of unaligned memory accesses.
- Example: The `val_t` structure in C is padded by the compiler to align its size to 12 bytes, even
though its logical size is 9 bytes. This alignment helps in efficient memory access by the CPU.
Blocking or Pointer Elimination
- Technique: Store fixed-size elements in memory consecutively and access them using offsets rather
than pointers. This reduces memory overhead and can improve access efficiency.
3. Sequential vs. Random Access
Sequential Access
- Benefits: Sequential memory access is optimized by the CPU and cache subsystems. This access
pattern minimizes cache misses and speeds up data retrieval.
- Database Optimization: Column-wise storage in databases enhances performance for queries that
access data sequentially, as opposed to row-wise storage.
Random Access
- Challenges: Random memory access can result in more frequent cache misses and increased
latency. Optimizing data structures to minimize random access can improve performance.
- Example: The CSB+ tree aligns keys to cache line boundaries to reduce cache misses, improving
search efficiency compared to traditional B+ trees.
4. Prefetching
Purpose
- Function: Prefetching anticipates future memory accesses and loads data into cache in advance,
reducing waiting times.
Incorrect Prefetching
- Issues: If prefetching is not handled correctly, it can lead to performance penalties. Incorrectly
prefetching data can result in stalls if the needed data is not available when the CPU expects it.
5. Performance Measuring
Granular Measurement
- Tools: Modern CPUs have performance counters for metrics such as CPU cycles, cache accesses, and
instruction counts. These metrics are crucial for optimizing data structures and algorithms.
6. Virtualization Impact
Effects on Performance
- Virtualization Overhead: Virtualization can introduce additional overhead, but its impact on in-
memory systems is often minimal. Virtualized systems can still effectively utilize CPU features like
caching and prefetching.
- Experiments:
- Access Latencies: Experiments show that access latencies for L1 and L2 caches are similar in
virtualized and non-virtualized environments. However, TLB (Translation Lookaside Buffer) misses can
be more pronounced in virtualized environments.
- Projectivity and Selectivity: Experiments in virtualized environments show that performance can
be comparable to physical systems, though some overhead for TLB misses is observed. The
performance impact depends on data access patterns and how well the system handles virtualization
overhead.
Parallel Data Processing Using Multi-Core and Across Servers
In the context of enterprise database systems, scaling and parallel data processing are crucial for
handling increasing workloads. As database sizes and user numbers grow, simply relying on faster
processors is no longer sufficient. Instead, modern systems need to leverage parallel processing to
manage these demands effectively. Here’s an in-depth look at the key concepts and techniques
involved:
1. Scalability and Parallel Processing
Scalability
- Definition: Scalability is the ability of a system to handle increased load by adding resources. For a
system to be considered scalable, it should be able to increase its capacity without requiring
significant changes to the application itself.
- Types:
- Linear Scalability: Ideal scenario where doubling the resources results in a proportional increase in
capacity or throughput. For example, doubling hardware should ideally double the processing
capacity.
Speed-Up and Amdahl’s Law
- Speed-Up: Measures the performance improvement of a parallel system compared to a sequential
one.
- Formula: \( \text{Speedup} = \frac{\text{time}(1, x)}{\text{time}(n, x)} \), where \(\text{time}(n,
x)\) is the time taken by a system with \( n \) processors to complete a task of size \( x \).
- Amdahl’s Law: Provides a theoretical limit on speed-up based on the proportion of the task that can
be parallelized.
- Formula: \( \text{Speedup} = \frac{1}{r_s + \frac{r_p}{n}} \), where \( r_s \) is the fraction of the
task that must be executed sequentially, \( r_p \) is the fraction that can be parallelized, and \( n \) is
the number of processors.
- In the case of an unlimited number of processors: \( \text{Speedup} = \frac{1}{r_s} = \frac{1}{1 -
r_p} \).
Technical Barriers to Scalability
- Startup Time: The time required to initiate parallel processes can dominate over the computation
time, especially if many processes are involved.
- Contention: Occurs when multiple processes compete for shared resources, leading to reduced
performance.
- Skew: The variability in processing times among parallel tasks can impact overall performance, as
the slowest task can delay the entire process.
2. Scaling Approaches
Scale-Up (Vertical Scaling)
- Definition: Increasing the capacity of a single machine by adding more resources like memory,
storage, or faster CPUs.
- Limitations: Eventually becomes cost-prohibitive and less effective as the size of the machine
increases.
Scale-Out (Horizontal Scaling)
- Definition: Adding more machines to a system to distribute the load. It is often more cost-effective
due to the availability of inexpensive commodity hardware and helps in achieving high availability.
- Considerations: Requires efficient distribution of workload and data across multiple servers.
3. Parallel System Architectures
Different hardware architectures support parallel processing in distinct ways:
Shared Memory
- Description: All processors have direct access to a common global memory. This can lead to
bottlenecks due to contention for memory access and requires efficient interconnection networks.
- Challenges: High contention and skew, where increasing parallelism can degrade performance due
to increased load on the network and caching issues.
Shared Disk
- Description: All processors have access to shared non-volatile storage, but each processor has its
own local memory. This setup reduces contention compared to shared memory but can suffer from
performance penalties if data is not available in local memory.
- Challenges: Performance issues arise if data needs to be fetched frequently from the shared disk.
Shared Nothing
- Description: Each processor has its own memory and storage, operating independently. This design
minimizes contention and traffic over interconnection networks by localizing data access.
- Advantages: Scales well with large numbers of processors and is more cost-effective with
commodity hardware.
4. Choosing Between Scale-Up and Scale-Out
- Enterprise Systems: Often prefer scale-up due to the higher reliability and performance of high-end
hardware.
- Large-scale Services: Companies like Google or Facebook opt for scale-out due to the cost-
effectiveness and scalability of commodity hardware. However, this approach can introduce
synchronization and consistency challenges.
5. Parallelization Techniques
Different levels of parallelization can be employed to optimize performance:
- Data Parallelism: Distributing data across processors to perform operations concurrently.
- Task Parallelism: Dividing tasks among processors where each processor performs a different
operation.