Lecture 6 Locks and CC
Lecture 6 Locks and CC
但又限制了系统的扩展性 (Scalability)
怎么办?
张晓东
美国俄亥俄州立大学
The Ohio State University
1
计算机系统本质是什么?
• 提供计算,通讯 和数据处理的通用基础设施(包括硬件和软件)
• 不再只是操作系统和 CPU 芯片
• 也不是为特殊应用专制的硬件或开发的软件
• 除操作系统以外的主流系统有:
• 存贮系统
• 数据管理系统
• 虚拟机系统
• 互联网系统
• 有大规模应用软件系统,如微信,云系统中的资源分享和调度系统 。。。
• 计算机系统的开发和应用具有很严格的基础性
• 很多系统上创新都是来源于对系统基本结构的深刻认识
• 系统资源管理和社会分配体制有共性
• 思考和分析问题不应只限于技术层面
• 所有的算法和解决方案都可以在社会和日常生活中找到
• 系统研究的最终目的
• “The proof of a system’s value is its existence.” Alan Perlis
Throughput drops after reaching peak
(MySQL)
Kernal_mutex in SQL is a
synchronization lock. This
is experiment selects
primary keys in 5 millions
rows each by using the
lock.
• Peak TX =154,236 (64 pros)
• After then TX drops 14%
• 7 times lower than the peak
(1024 processes)
Percona DB Performance 3
Latency increases as # threads increase to contend
locks
4 threads using
spinlock running on
Intel Xeon L5640 for a
write-read workload
compared with the
same workload in lock-
free style
4
System Performance: High Throughput and Low Latency
Throughput (parallelism)
7
Two Phase Locking (2PL)
• DBMS must lock a tuple before a transaction reads or writes to
it
• Two types of locks: shared lock (read) & exclusive lock (write)
• Phase 1: growing phase
• Transaction can obtain locks but cannot release locks
• Phase 2: Shrinking phase
• Transaction can release locks but cannot obtain locks
• Variants of 2PL (based on how to avoid deadlocks)
• 2PL - deadlock detection
• Aborts a transaction when deadlock happens
• 2PL - wait and die
• Old transaction can wait young transaction, not vice versa
• 2PL – wound wait
• Immediately aborts a transaction if its locking request is denied
8
Concurrency Control (CC)
• CC ensures correct results for concurrent
operations
• A basic component in OS, DS, multiprocessors, databases, PL,
…
• Ensures serializability of data accesses to the shared data
sets
• Get results fast for high throughput and scalability
rw cannot be ww or wr
14
OCC’s Problem: False Aborts
• False abort
• Some transactions aborted by OCC could have been
allowed to commit without causing an unserializable
schedule
T1: B = A + B; T2: A = A * 1.1;
Thread1 Thread2
BEGIN BEGIN
• No cycle is formed
• OCC only allows serialized execution R(A); rw R(A);
of T2, T1, but is not able to recognize R(B); W(A);
serialized execution of T1, T2.
• T1 is falsely aborted. W(B); Commit
• If it commits, it is serialized T1, T2. Abort
15
Issues and Challenges
• False aborts happen in high contention
environment
Ideal
Cycle • Retaining OCC’s merit of
high-performance in low
contention
Validation
Overhead
18
Basic Structure of BCC
• BCC is OCC based, retaining its merits
20
BCC Validation is Complex
23
System Efforts: Minimizing Various
Overheads
• Reducing inter-core communication
• Avoids centralized time clock
• Uses distributed vector clock
• Avoids keeping anti-dependency information
• Always allow read-only snapshot transactions commit
• Only needs to validate T2
• Makes history read-set as small as possible
• Makes history read-set cache friendly
• Lock-free operations on history read-set
24
Evaluation
• Experiment Setup
• 32-core, 128GB RAM Intel machine (4 sockets, 8 cores
per socket)
• Workloads: TPC-W, TPC-C, YCSB
• Goal
• Compare the throughput/latency achieved with
• BCC, OCC and 2PL(locks)
under workloads with various levels of contention
25
Comparable Performance in Low
Contention
• TPC-C (all-mix)
7.29% overhead
over OCC
26
Effectiveness in High Contention (2PL is
better than OCC)
• TPC-W (Cart-Buy mix)
3.68x Improvement
over OCC
27
Effectiveness in High Contention (2PL is
close to OCC)
• YCSB (16-tuples)
1.99x Improvement
over OCC
28
Effectiveness in High Contention (OCC is better
than 2PL)
• TPC-C (NewOrder-Payment mix)
35% Improvement
over OCC
29
Conclusions
• OCC’s simple validation only work well in low
contention
30
系统研究总结
计算机系统有严格的基础性
• 通过大量的编程和分析才能透彻地精通系统的内在关系
• 任何系统都是一个逐渐形成的生态环境
• 不要轻易去颠覆一个系统
系统研究的问题与社会和日常生活中的问题本质是一致的
• 商业中的 B2C => 我们系统系统中的 Master/Slave
• 商业中的 C2C => 我们系统中的 P2P
• 滴滴打车,专车,快车等是一个系统调度问题:
• 将闲置的汽车资源联在互联网上,然后调度,导航,分配它们来提升一个城市的出行效率