Concurrency Flashcards

(24 cards)

1
Q

What is concurrence?

A

Multiple processes or threads manipulate the same data at the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a trasaction?

A

An interaction between a client and a server (it involves request/response)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are concurrency problems avoided?

A

By ensuring isolation, each transaction is treated as the only operation being performed. The problem arises when multiple transactions try to interact with each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is offline concurrency

A

It focuses on controlling the sequence and interaction of transactions over time (situations where there’s more than one simple transaction at a time)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Concurrency problems to avoid:

A

1- Lost updates: User A is editing a piece of data, B starts editing the same data and finishes their edit, User A finishes and submits the data, overwriting user B’s changes

2- inconsistent Readings: a transaction reads data that is in the middle of being updated by another transaction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the excution contexts

A

1- Interaction contexts
2- Processing contexts
3- DB access context

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain Interaction Contexts

A

-Request: from outside the system, processed to compute a response, processing is done in the server while client is on hold ex: visiting a website)

-Session: a series of client/server interactions over time, commonly request/response between login and logout (using the website)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain processing context:

A

-Process: a heavyweight excution context that isolates data (has its own memory and resources)

-Thread: a lightweight excution context that runs within a process (share memory therefore concurrency problems)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain DB Access context:

A

Transaction: coordinates requests accessing the same data to avoid concurrency issues

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do we avoid concurrency problems?

A

Isolation (coordinating access between transactions)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is concurrency control?

A

A mechanism used to control access to shared data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the measures of concurrency control

A

1- Optimistic
2- Pessimistic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain the difference between pessimistic control and optimistic control

Scenario: 2 users simultaneously edit a file

A

Optimistic locking: when two users edit the same file, the system allows both of them to edit, and only at the end does it check if they had made conflicting changes. If there’s conflict, one of the user’s changes is rejected

Pessimistic: when two users edit the file, the system locks the file for one user, the second will need to wait until it’s unlocked before they make changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When do we use pessimistic locking and when do we use optimistic locking

A

Go for optimistic when conflicts are rare/consequences not critical,
got for pessimistic when there’s a big risk of conflict or critical consequences

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When do inconsistent readings happen?

A

When data is read while another process is modifying it at the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do we prevent inconsistent readings?

A

By using a pessimistic lock which enforces strict locking rules:
-Multiple users can read simultaneously (shared lock)
-Only one user can write at a time (exclusive lock)
-If a write lock is active, no one else can read or write
-Writers must wait if readers are holding locks, ensuring data consistency

17
Q

What’s a deadlock?

A

A situation where multiple users block each other by holding locks on resources the other needs, no one can proceed, creating a circular wait (user A locks File 1 and needs file 2. user 2 locks file 2 and needs file 1)

18
Q

Ways to prevent deadlocks

A

-System detects a deadlock and selects a victim to forcefully release their locks
-Locks with expiry time
-Users acquire all necessary locks at the start of the session
-Locks are always obtained in a fixed order

19
Q

Define transactions

A

Main concurrency tool in enterprise applications with bounded sequence of actions, start and endpoint (transactions with a short span, usually one request, are more efficient)

20
Q

Transaction Properties

A

ACID:
Atomicity: All or nothing
Consistency: Transactions between consistent states
Isolation: Ensures transactions don’t interfere with each other
Durability: Consistent transactions persist even after failures

21
Q

Define system transactions

A

SQL commands to open and close transactions

22
Q

Define business transactions

A

They are at a higher level than system transactions, example: online banking

23
Q

How to avoid concurrency problems in business transactions?

A

-Atomicity and persistence: apply changes when the user agrees, and keep track of the changes
-Consistency: Application is responsible for implementing and maintaining business rules
-Isolation: Each session operates independently

24
Q

Explain offline concurrency control

A

When transactions span multiple requests, concurrency problems must be managed
-Optimistic offline lock: Optimistic pattern for business transaction
-Pessimistic Offline Lock: Prevents conflict but is more complex to implement and has less response capacity