0% found this document useful (0 votes)
21 views29 pages

Lecture 6 Locks and CC

The document discusses the challenges of using locks in concurrent computing, highlighting their impact on scalability and system performance. It introduces Balanced Concurrency Control (BCC) as a solution to reduce false aborts and improve throughput and latency in high contention environments. The effectiveness of BCC is demonstrated through comparisons with Optimistic Concurrency Control (OCC) and Two-Phase Locking (2PL) in various workloads.

Uploaded by

Jin Wang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views29 pages

Lecture 6 Locks and CC

The document discusses the challenges of using locks in concurrent computing, highlighting their impact on scalability and system performance. It introduces Balanced Concurrency Control (BCC) as a solution to reduce false aborts and improve throughput and latency in high contention environments. The effectiveness of BCC is demonstrated through comparisons with Optimistic Concurrency Control (OCC) and Two-Phase Locking (2PL) in various workloads.

Uploaded by

Jin Wang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

锁 (Locks): 保证了并发控制 (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

ACM Queue, June 2013

4
System Performance: High Throughput and Low Latency

Optimal Point Latency (locality)

Throughput (parallelism)

Number of Concurrent Processes


Two Major Issues of Lock Usage
• Ways of acquiring locks
• Minimizing network bandwidth
• Minimizing overhead of waiting for locks
• Maintaining a constant # of remote memory accesses per
lock acquisition

• Locks in concurrency control


• Minimizing or eliminating unnecessary usage of locks
• Minimizing execution and access latency inside critical
section
• Minimizing the size of the data structure to be locked
• Maximizing scalability subject to serialized execution
6
Distributed locks in production systems

For each lock acquisition in a distributed system


1. Entering the queue waiting for the lock (a remote access)
2. Local spin to wait without consuming network bandwidth
3. The process is informed for its turn (a remote access)
4. Acquiring the lock entering the critical section (a remote
access)

• Constant number of remote accesses per lock acquisition


• Network contention is minimized

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

• Optimistic Concurrency Control (OCC, Kung and


Johnson, 1981) has been used in several production
systems 9
OCC: How It Works
• OCC executes a transaction in three phases:
• Phase 1: concurrent local processing
• Reads tuples into a read set
• Buffers writes into a write set
• Phase 2: Validation in critical section
• Validates whether serializability is guaranteed:
Has any tuple in the read set been modified?
• Phase 3: Commit the results in critical section or
abort
• Aborts: aborts the transaction if validation fails
• Commits: installs the write set and commits the
transaction
10
OCC: An Example
Tuple A in T1’s read set has
been changed by T2, thus Thread1 Thread2
T1: B = A + B; T2: A = A * 1.1; T2’s read set remains
T1 must be aborted.
unchanged, thus T2 is
allowed to commit
BEGIN BEGIN
T1’s read set: A B A
R(A); R(A); T2’s read set:
(100) (100) (100)
B R(B); W(A); A
T1’s write T2’s write set:
set: (200) W(B); (110)
Commit
Validation
Thread-local Thread-local
Validation
Abort
memory memory
Time
Database ID Value
storage
A 110
100
B 100 11
OCC’s Advantages
• Simple validation, which achieves high
throughput and scalability at low Operates in private workspace; rare
inter-thread synchronization
contention (optimistic)
• Phase 1: Read
• Reads data into a read set Needs synchronization, but
usually very short at low
• Buffers writes into a write set contention
• Phase 2: Validation
• Validates whether serializability is guaranteed:
Has any tuple in the read set been modified?
• Phase 3: Write
• Aborts: aborts the transaction if validation is failed
• Commits: installs the write set and commits the transaction12
Serializability Theorem
• The serializability theorem [Bernstein et al.
1987]
• A transaction schedule is serializable iff its data
dependency graph contains no cycles
• Three types of data dependencies:
T1 wr T2 : T2 reads a tuple that was earlier written by
T1 T ww T
1 2
rw
T1 T2 : T2 writes a tuple that was earlier written by
T1
: T1 reads a tuple that was later written by T2
13
OCC: Serializable Scope
• OCC ensures serializability by breaking the
incoming RW edge of the earliest
committed transaction in a possible cycle
T2 will be Aborted by OCC and thus avoids
cycle

rw cannot be ww or wr

T3 The first committed txn in


the cycle

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

• False aborts increase latency and decrease


throughput

• Detecting cycles eliminates false aborts, but non-


affordable

• Can we reduce false aborts in high contention?


16
Reducing false aborts to increase Throughput and reduce Latency

Optimal Point Latency (false aborts)

Throughput (false aborts)

Number of Concurrent Processes


BCC: Balanced Concurrency
Control
# false
aborts OCC • Reducing false aborts
with a more precise
validation method in
Our efforts high contention
BCC

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

• If OCC validation fails, BCC validation checks


again
wr/ww/rw rw
T1 T1 T2 T3
T2
T3 commits earlier than T2
rw
T1 must commit after T2 starts
T3

20
BCC Validation is Complex

• Goal: capture all essential patterns at the


right time
T1 T2 T1 T2 T1 T2 T1 T2
Begin Begin Begin Begin Begin Begin Begin Begin
W(A) R(B) W(A) R(B) R(A) R(B) Snapshot W(A)
wr ww rw rw
Commit Commit Commit Commit
R(A) W(A) W(A) R(A)
Commit Commit Commit
Commit

Created at the time when T2 commits Created at the time


when T1 commits
21
BCC’s Implementation
• Baseline system: Silo (SOSP’13)
• Silo is a shared in-memory OCC database
• It avoids any centralized bottleneck in the design
• Challenges: How to minimize validation
overhead
• Extra information bookkeeping
• Maintains each transaction’s read set
• Maintains anti-dependency information for validating T 1
• Inter-core synchronization

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

• BCC makes a critical step on validation

• The effectiveness of BCC is achieved by


• The correctness and tipping point of its validation
• Low overhead implementation of the validation
• Retaining all the merits of OCC

30
系统研究总结

计算机系统有严格的基础性
• 通过大量的编程和分析才能透彻地精通系统的内在关系
• 任何系统都是一个逐渐形成的生态环境
• 不要轻易去颠覆一个系统


系统研究的问题与社会和日常生活中的问题本质是一致的
• 商业中的 B2C => 我们系统系统中的 Master/Slave
• 商业中的 C2C => 我们系统中的 P2P
• 滴滴打车,专车,快车等是一个系统调度问题:
• 将闲置的汽车资源联在互联网上,然后调度,导航,分配它们来提升一个城市的出行效率

You might also like