Simple cache architecture

31
Simple Cache Architecture [email protected]

description

 

Transcript of Simple cache architecture

Page 1: Simple cache architecture

Simple Cache Architecture

[email protected]

Page 2: Simple cache architecture

What is Cache?

Page 3: Simple cache architecture

Cache == Speed

Page 4: Simple cache architecture

Disk Accessing is too late

Page 5: Simple cache architecture

Operation Time is too long

Page 6: Simple cache architecture

Client

Business Object

Memory

Disk

Client Client Client

Page 7: Simple cache architecture

Client

Business Object

Distributed Cache

DB

Client Client Client

Page 8: Simple cache architecture

Connect via Business Object

Page 9: Simple cache architecture

Don’t Connect Client between DB directly

Page 10: Simple cache architecture

Distributed Cache

Page 11: Simple cache architecture

Consistent Hashing

Page 12: Simple cache architecture

Proxy

Server

Server

Server

Server

Server

User Request

K = 10000 N = 5

Origin

Page 13: Simple cache architecture

Proxy

Server

Server

Server

Server

Server

User Request

K = 10000 N = 4

FAIL : Redistribution about 2000 Users

Page 14: Simple cache architecture

Proxy

Server

Server

Server

Server

Server

User Request

K = 10000 N = 5

RECOVER: Redistribution about 2500 Users

Page 15: Simple cache architecture

A

Add A,B,C Server

Page 16: Simple cache architecture

A

B

Add A,B,C Server

Page 17: Simple cache architecture

A

B

C

Add A,B,C Server

Page 18: Simple cache architecture

A

B

C

1

Add Item 1

Page 19: Simple cache architecture

A

B

C

1

2

Add Item 2

Page 20: Simple cache architecture

A

B

C

1

2

3

4

5

Add Item 3,4,5

Page 21: Simple cache architecture

A

B

C 2

3

4

5

Fail!! B Server

Page 22: Simple cache architecture

A

B

C

1

2

3

4

5

Add Item 1 Again -> Allocated C Server

Page 23: Simple cache architecture

A

B

C

1

2

3

4

5

1

Recover B Server -> Add Item 1

Page 24: Simple cache architecture

A

B

C

Real Implementation

A+1

A+2

A+3 B+1

B+2

C+1

C+2

A+4

C+3

B+3

Page 25: Simple cache architecture

Mistake

Page 26: Simple cache architecture

A

DB Cache

B

Normal Step

1. A:DB:W 2. A:Cache:W 3. B:DB:W 4. B:Cache:W

Page 27: Simple cache architecture

A

DB Cache

B

Race Condition Step

1. A:DB:W 3. B:Cache:W 2. B:DB:W 4. A:Cache:W

Page 28: Simple cache architecture

Solution?

Page 29: Simple cache architecture

Global Lock?

Page 30: Simple cache architecture

CAS?

Page 31: Simple cache architecture

Thank You!