Skip to main content

Centralized vs Ricart-Agrawala algorithm

Short answer

Centralized: coordinator grants CS; 3 messages per entry, single point of failure. Ricart-Agrawala: fully distributed, 2(N-1) messages, uses timestamps, any process crash blocks all. Centralized is simpler, scalable until coordinator saturates; RA has no bottleneck but high overhead for large N. Example: centralized: P1 requests, coordinator grants; P2 queued. RA: P1 and P2 request, P1 wins by timestamp.

Describe non-token based centralized and Ricart Agrawala algorithm with example and compare them.

Centralized algorithm (non-token based)

One process is elected coordinator. It keeps a queue of requests.

  1. A process wanting the critical section (CS) sends REQUEST to the coordinator.
  2. If the CS is free, the coordinator sends GRANT (OK); otherwise it queues the request (or sends no reply).
  3. The process enters the CS and, when done, sends RELEASE.
  4. The coordinator removes the next request from its queue and grants it.

Example: P1 asks; coordinator C grants. P2 asks; C queues it. P1 releases; C grants to P2.

 P1 --REQ--> C --OK--> P1 (in CS)
 P2 --REQ--> C (queued)
 P1 --REL--> C --OK--> P2

Messages per entry: 3 (request, grant, release).

Ricart-Agrawala algorithm

Fully distributed, uses Lamport timestamps. To enter the CS, a process multicasts REQUEST(timestamp, id) to all N−1 others and enters when it has received REPLY from all. A receiver replies immediately if it is not interested in the CS or its own request has a larger timestamp; it defers the reply if it is in the CS or has a smaller timestamp request. On exit, deferred replies are sent.

Example: P1 (timestamp 4) and P2 (timestamp 5) request together; P1 wins since 4 < 5; P2 gets its reply after P1 finishes. Messages per entry: 2(N−1).

Comparison

PointCentralizedRicart-Agrawala
ControlOne coordinatorFully distributed
Messages per entry32(N−1)
Delay before entry2 message times2 message times (one round trip)
Synchronisation delay2 (release then grant)1
Single point of failureYes: coordinator crashYes: any process crash blocks everyone
BottleneckCoordinatorNone, but every node loaded
FairnessQueue order (FIFO)Timestamp order
Clock neededNoYes, logical clocks
SimplicitySimpleMore complex
ScalabilityGood until coordinator saturatesPoor as N grows

✓ Answer checked by Claude Opus 5.5 (high effort)

All Distributed System chapter 6 questions →