72
Multi Thread Game Server Multi Thread Game Server

Multi thread game server

Embed Size (px)

Citation preview

Page 1: Multi thread game server

Multi Thread Game ServerMulti Thread Game Server

Page 2: Multi thread game server

ContentsContents

● Summary & Simple TestSummary & Simple Test

● 게임 서버 구조 사례게임 서버 구조 사례

● 문제점 및 개선 방안문제점 및 개선 방안

Page 3: Multi thread game server

SummarySummary

[Concurrent Programming with Threads]Rajkumar Buyya

Page 4: Multi thread game server

SummarySummary

Page 5: Multi thread game server

Simple TestSimple Test

Page 6: Multi thread game server

User.hUser.h

Page 7: Multi thread game server

The GoalThe Goal

Page 8: Multi thread game server

Single ThreadSingle Thread

50%

Core ACore A Core BCore B

Page 9: Multi thread game server

2 Threads2 Threads

100%

Core ACore A Core BCore B

Page 10: Multi thread game server

4 Threads4 Threads

100%

Core A Core B

Core ACore A Core BCore B

Page 11: Multi thread game server

8 Threads8 Threads

Core ACore A Core BCore B

Page 12: Multi thread game server

ResultResult

1 thread 2 threads 4 threads 10 threads0

1000

2000

3000

4000

5000

6000

Page 13: Multi thread game server

Thread Programming ModelsThread Programming Models

[ A Thread Pipe Line ]

Page 14: Multi thread game server

Thread Programming ModelsThread Programming Models

[ The Peer Model ]

Page 15: Multi thread game server

Thread Programming ModelsThread Programming Models

[ The Boss and Worker ]

Page 16: Multi thread game server

Worker ThreadsWorker Threads

Page 17: Multi thread game server

Worker ThreadsWorker Threads

Worker A

Worker B

Worker C

[User]

Page 18: Multi thread game server

경쟁 상태경쟁 상태

Worker B

Worker C

Worker A

Time Worker

Enemy Thread

[User]

Page 19: Multi thread game server

10000000 Updating10000000 Updating

Page 20: Multi thread game server

경쟁 상태의 문제점경쟁 상태의 문제점

● Crash (ntdll?)Crash (ntdll?)● 드랍 아템 다수가 획득 드랍 아템 다수가 획득

● 인벤 꼬임 인벤 꼬임

● 경험치 이상 경험치 이상

● ......

Page 21: Multi thread game server

SynchronizationSynchronization

Worker A

Worker B

Worker C

Page 22: Multi thread game server

SynchronizationSynchronization

Page 23: Multi thread game server

Dead LockDead Lock

Worker Enemy Thread

Page 24: Multi thread game server

Dead LockDead Lock

Worker A Worker B

Page 25: Multi thread game server

보너스보너스

● Self Deadlock (← single threadSelf Deadlock (← single thread에서도에서도))

● Half DeadlockHalf Deadlock

Page 26: Multi thread game server

ChaosChaos

Worker A Enemy Thread

Worker B Time Worker

Page 27: Multi thread game server

SynchronizationSynchronization

Worker A

Worker B

Worker C

Enemy Thread

Time Worker

Page 28: Multi thread game server

SynchronizationSynchronization

50%

70%

70%

Page 29: Multi thread game server

SynchronizationSynchronization

1 thread 2 threads 4 threads 10 threads 20 threads 100 threads0

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

with lockno lock

Page 30: Multi thread game server

SynchronizationSynchronization

50%

70%

70%

?

?

Page 31: Multi thread game server

Avoiding DeadlockAvoiding Deadlock

● Mutual ExclusionMutual Exclusion● Hold and LockHold and Lock● No PreemptionNo Preemption● Circular WaitCircular Wait

Page 32: Multi thread game server

Deadlock DetectorDeadlock Detector

●http://www.softwareverify.com/cpp-thread.php

Page 33: Multi thread game server

ChaosChaos

Worker A Enemy Thread

Worker B Time Worker

Page 34: Multi thread game server

Logic ThreadLogic Thread

Logic Thread A

Logic Thread B

Page 35: Multi thread game server

Impenetrable FortressImpenetrable Fortress[ m|pen tr bl]ɪ ɪ ə

Page 36: Multi thread game server

http://ohyecloudy.com (오종빈)

Page 37: Multi thread game server
Page 38: Multi thread game server

Impenetable FortressImpenetable Fortress[ m|pen tr bl]ɪ ɪ ə

Page 39: Multi thread game server
Page 40: Multi thread game server
Page 41: Multi thread game server

경쟁 상태경쟁 상태

User

Worker

Worker

Worker

Thread

Timer

Page 42: Multi thread game server

무관심 상태무관심 상태

User

Worker

Thread

Timer

Page 43: Multi thread game server

Impenetrable FortressImpenetrable Fortress[ m|pen tr bl]ɪ ɪ ə

Page 44: Multi thread game server
Page 45: Multi thread game server
Page 46: Multi thread game server

http://ohyecloudy.com (오종빈)

Page 47: Multi thread game server

RoomZonePlayer

RoomRoomThreadThread CoreRoom

Room

Room

Zone

Zone

Zone

Player

Player

Player

RunnableRunnable+run()+run()

Updatable+update()

run()

update()update()update()

x N

Page 48: Multi thread game server

개념개념

Room

Zone

Player

User

Page 49: Multi thread game server

Room

User

Zone

Player

NPC

Enemy

Projectile

Script

Thread Safe

Page 50: Multi thread game server

Thread Safe

Page 51: Multi thread game server

t1

t2

t3

t4

Core A

Core B

time

33 66 99 132 165 1980

Page 52: Multi thread game server

t1

t2

t3

t4

Core A

Core B

time

33 66 99 132 165 1980

Page 53: Multi thread game server

t1

t2

t3

t4

Core A

Core B

time

33 66 99 132 165 1980

Page 54: Multi thread game server
Page 55: Multi thread game server
Page 56: Multi thread game server

Action->AniAction->Ani

Page 57: Multi thread game server

Action->TriggerAction->Trigger

Page 58: Multi thread game server

RoomThreadRoomThread

Page 59: Multi thread game server

t1

t2

Core A

Core B

time

33 66 99 132 165 1980

Core A

Core B

Page 60: Multi thread game server

t1

t2

t3

t4

time

33 66 99 132 165 1980

Core A

Core B

Core A

Core B

Page 61: Multi thread game server

ㅇㅇㅇㅇ??

1 thread 2 threads 4 threads 10 threads0

1000

2000

3000

4000

5000

6000

Page 62: Multi thread game server

Room

Zone

User

Player

Network

RoomRoomThreadThread

WorkerWorkerThreadThread

Core A

Core B

GameLogicGameLogic

Page 63: Multi thread game server
Page 64: Multi thread game server

Logic

Worker

recvBuf

Page 65: Multi thread game server

Logic1

Wor

ker

Pakc

et

Logic2

Logic3

Page 66: Multi thread game server

User::StateUser::State

Page 67: Multi thread game server

http://javawork.egloos.com 01/21/2011

Page 68: Multi thread game server

http://javawork.egloos.com 01/21/2011

Page 69: Multi thread game server

Woker

Queue Logic

Page 70: Multi thread game server
Page 71: Multi thread game server
Page 72: Multi thread game server

끝끝

http://javawork.egloos.com 01/21/2011