Why Parallel Databases
A parallel database system uses many processors and disks working at the same time to speed up processing of very large databases (terabytes) and to serve thousands of transactions per second. Two measures judge the system:
- Speedup: running the same job on n times the hardware and finishing n times faster. Speedup = time on the small system / time on the large system.
- Scaleup: handling a job n times bigger in the same time on n times the hardware. Scaleup = time of small job on small system / time of big job on big system. Ideal values are n (linear speedup) and 1 (linear scaleup).
For example, a job that takes 100 s on one node and 30 s on four nodes has a speedup of 100 / 30 = 3.33; a job four times larger that takes 110 s on four nodes has a scaleup of 100 / 110 = 0.909. Factors that reduce them are start-up cost, interference (processors waiting for shared resources) and skew (uneven work).
Architectures
- Shared memory: all processors share one memory and all disks; communication is fast, but it does not scale beyond a few dozen processors because of memory contention.
- Shared disk: each processor has its own memory but all share the disks; it is fault tolerant, though the disk subsystem can become a bottleneck.
- Shared nothing: every node has its own processor, memory and disk, and nodes communicate over a network; it scales to thousands of nodes and is the basis of most modern systems, but data must be partitioned carefully.
- Hierarchical: a combination, such as shared-nothing nodes each built as a shared-memory multiprocessor.
I/O Parallelism
I/O parallelism reduces the time to read data by partitioning a relation across several disks. With D disks:
- Round-robin: the i-th tuple goes to disk i mod D; the load is even and it is good for full scans, but poor for point or range queries.
- Hash partitioning: a hash function on a key chooses the disk; it is good for scans and for point queries on the key, but it can be skewed.
- Range partitioning: key ranges are given by a partition vector (for example below 10, 10 to 19, 20 and above); it is good for point and range queries on the key, but may cause skew.
Definition: Speedup. The ratio of the time a job takes on a small system to the time the same job takes on a system with more resources.
Table 3.1: Partitioning techniques
| Technique | Good for | Weakness |
|---|---|---|
| Round-robin | Full scans, even load | Point and range queries |
| Hash | Scans and point queries | Skew, no range queries |
| Range | Point and range queries | Skew from uneven keys |
Example 3.1: Partitioning twelve tuples over three disks
Problem: Twelve tuples with keys 5, 17, 23, 8, 42, 11, 30, 3, 19, 26, 14 and 9 are placed on 3 disks. Find the number of tuples on each disk with round-robin, with hash partitioning (key mod 3) and with range partitioning (below 10, 10 to 19, 20 and above).
Solution:
- Round-robin gives every disk 12 / 3 = 4 tuples.
- Hash (key mod 3): disk 0 gets 42, 30, 3 and 9; disk 1 gets 19; disk 2 gets 5, 17, 23, 8, 11, 26 and 14. The counts are 4, 1 and 7.
- Range: below 10 are 5, 8, 3 and 9; from 10 to 19 are 17, 11, 19 and 14; 20 and above are 23, 42, 30 and 26. The counts are 4, 4 and 4.
Result: Round-robin and range give 4, 4, 4; the hash scheme is skewed with 4, 1 and 7.
keys = [5, 17, 23, 8, 42, 11, 30, 3, 19, 26, 14, 9]
D = 3
idx = range(len(keys))
rr = [sum(1 for i in idx if i % D == d) for d in range(D)]
hs = [sum(1 for k in keys if k % D == d) for d in range(D)]
def disk(k):
return 0 if k < 10 else 1 if k < 20 else 2
rg = [sum(1 for k in keys if disk(k) == d) for d in range(D)]
print("Round-robin:", rr)
print("Hash :", hs)
print("Range :", rg)
print("Speedup:", round(100 / 30, 2))
print("Scaleup:", round(100 / 110, 3))
Output
Round-robin: [4, 4, 4]
Hash : [4, 1, 7]
Range : [4, 4, 4]
Speedup: 3.33
Scaleup: 0.909
Common mistakes
- Expecting linear speedup; start-up cost, interference and skew reduce it.
- Using hash partitioning for range queries.
- Choosing a partition vector that puts most tuples on one disk.
- Using shared memory for hundreds of processors.
Key takeaways
- Speedup is about the same job on more hardware; scaleup is about a bigger job on more hardware.
- Architectures: shared memory, shared disk, shared nothing and hierarchical.
- Partitioning: round-robin, hash and range.
- Skew reduces the benefit of parallelism.
Practice questions
- Which parallel architecture scales best?
- What is range partitioning?
- Name two reasons for sub-linear speedup.
Answers to the practice questions
- Shared nothing.
- Placing tuples on disks according to ranges of the key given by a partition vector.
- Start-up cost and interference (also skew).
Sources
- Official BCA syllabus Advanced Database Systems, course code 25BCA406DS04, Unit III
