Multi thread game server

Post on 16-May-2015

3924 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

Transcript

Multi Thread Game ServerMulti Thread Game Server

ContentsContents

● Summary & Simple TestSummary & Simple Test

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

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

SummarySummary

[Concurrent Programming with Threads]Rajkumar Buyya

SummarySummary

Simple TestSimple Test

User.hUser.h

The GoalThe Goal

Single ThreadSingle Thread

50%

Core ACore A Core BCore B

2 Threads2 Threads

100%

Core ACore A Core BCore B

4 Threads4 Threads

100%

Core A Core B

Core ACore A Core BCore B

8 Threads8 Threads

Core ACore A Core BCore B

ResultResult

1 thread 2 threads 4 threads 10 threads0

1000

2000

3000

4000

5000

6000

Thread Programming ModelsThread Programming Models

[ A Thread Pipe Line ]

Thread Programming ModelsThread Programming Models

[ The Peer Model ]

Thread Programming ModelsThread Programming Models

[ The Boss and Worker ]

Worker ThreadsWorker Threads

Worker ThreadsWorker Threads

Worker A

Worker B

Worker C

[User]

경쟁 상태경쟁 상태

Worker B

Worker C

Worker A

Time Worker

Enemy Thread

[User]

10000000 Updating10000000 Updating

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

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

● 인벤 꼬임 인벤 꼬임

● 경험치 이상 경험치 이상

● ......

SynchronizationSynchronization

Worker A

Worker B

Worker C

SynchronizationSynchronization

Dead LockDead Lock

Worker Enemy Thread

Dead LockDead Lock

Worker A Worker B

보너스보너스

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

● Half DeadlockHalf Deadlock

ChaosChaos

Worker A Enemy Thread

Worker B Time Worker

SynchronizationSynchronization

Worker A

Worker B

Worker C

Enemy Thread

Time Worker

SynchronizationSynchronization

50%

70%

70%

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

SynchronizationSynchronization

50%

70%

70%

?

?

Avoiding DeadlockAvoiding Deadlock

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

Deadlock DetectorDeadlock Detector

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

ChaosChaos

Worker A Enemy Thread

Worker B Time Worker

Logic ThreadLogic Thread

Logic Thread A

Logic Thread B

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

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

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

경쟁 상태경쟁 상태

User

Worker

Worker

Worker

Thread

Timer

무관심 상태무관심 상태

User

Worker

Thread

Timer

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

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

RoomZonePlayer

RoomRoomThreadThread CoreRoom

Room

Room

Zone

Zone

Zone

Player

Player

Player

RunnableRunnable+run()+run()

Updatable+update()

run()

update()update()update()

x N

개념개념

Room

Zone

Player

User

Room

User

Zone

Player

NPC

Enemy

Projectile

Script

Thread Safe

Thread Safe

t1

t2

t3

t4

Core A

Core B

time

33 66 99 132 165 1980

t1

t2

t3

t4

Core A

Core B

time

33 66 99 132 165 1980

t1

t2

t3

t4

Core A

Core B

time

33 66 99 132 165 1980

Action->AniAction->Ani

Action->TriggerAction->Trigger

RoomThreadRoomThread

t1

t2

Core A

Core B

time

33 66 99 132 165 1980

Core A

Core B

t1

t2

t3

t4

time

33 66 99 132 165 1980

Core A

Core B

Core A

Core B

ㅇㅇㅇㅇ??

1 thread 2 threads 4 threads 10 threads0

1000

2000

3000

4000

5000

6000

Room

Zone

User

Player

Network

RoomRoomThreadThread

WorkerWorkerThreadThread

Core A

Core B

GameLogicGameLogic

Logic

Worker

recvBuf

Logic1

Wor

ker

Pakc

et

Logic2

Logic3

User::StateUser::State

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

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

Woker

Queue Logic

끝끝

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

top related