CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

85
Lecture 10 Transport Protocol for Networked Games 29 March 2010 1

description

 

Transcript of CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Page 1: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Lecture 10Transport Protocol

for Networked Games

29 March 2010

1

Page 2: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

TCP or UDP ?

2

Page 3: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Why use TCP?

• TCP provides reliable, in-order delivery

• TCP goes through most firewalls, UDP does not

• TCP manages connection for us

3

Page 4: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Why not to use TCP?

• TCP incurs higher latency

• Don’t always need reliability and in-order delivery

• High header overhead

4

Page 5: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

position = 10position = 13position = 15

X

Updated position not delivered to application until (outdated) lost packet

is received

5

Page 6: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

A’s position = 10B’s position = 13C’s position = 15

X

Some messages need not be delivered in sequence.

6

Page 7: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Gestures from someone far away need not be received reliably.

7

Page 8: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

46%of ShenZhou Online bandwidth is

occupied by TCP header

8

Page 9: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

enet.cubik.org

A library that provides reliability, sequencing,

connection managements over UDP

9

Page 10: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Delivery can be stream-oriented (like TCP) or message-oriented (like UDP)

10

Page 11: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Supports partial reliability

enet_packet_create (“abc”,4, ENET_PACKET_FLAG_RELIABLE)

11

Page 12: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Retransmission triggered by timeout-based on RTT

12

Page 13: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Data in queue are bundled into one packet if there is space

13

Page 14: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

enet.cubik.org

Portable, easy to use, but still, most firewalls block

UDP traffic

14

Page 15: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

• Uses TCP: WoW, Lineage I/II, Guild Wars, Ragnarok Online, Anarchy Online, Mabinogi

• Uses UDP: EverQuest, SW Galaxies, City of Heroes, Ultima Online, Asherons Call, FFXI

15

Page 16: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Need to study the use of TCP for networked

games

16

Page 17: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

How to provide reliability over UDP?

17

Page 18: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

How slow is TCP, really?

Which part of TCP is the root of slowness?

Can we fix TCP?

18

Page 19: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

A Quick Review of TCP

19

Page 20: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

s=100s=200s=300s=400 a=300

a=500

TCP Delayed ACK20

Page 21: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

TCP Spec: max 500ms delayMost implementation: 200ms

21

Page 22: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Why delay ACK?

• reduce num of ACKs

• in case receiver wants to send data within 200ms (in which case it can piggyback the ACK with data)

• give sender time to buffer more data for sending (avoid silly window syndrome)

22

Page 23: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

X

s=100s=200s=300s=400s=500

s=200

a=200

a=200a=200a=200

TCP Fast Retransmission23

Page 24: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Definition of Dup ACKs in 4.4BSD and Stevens: “pure ACK with no data”

24

Page 25: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

TCP Timeout + Exponential Back-off

X

X

RTO

2xRTO

25

Page 26: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Spurious Retransmission

RTO

26

Page 27: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

RTO estimation

Ei = 7Ei-1/8 + RTT/8Vi = 3Vi-1/4 + |RTT-Ei-1|/4RTO = max(Ei + 4Vi, 1s)

27

Page 28: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Linux’s RTO estimation

Ei = 7Ei-1/8 + RTT/8Vi = 3Vi-1/4 + |RTT-Ei-1|/4Wi = min(Vi, 50ms)RTO = max(200ms, Ei+Wi)

28

Page 29: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

delayed ACK

increase RTT

increase RTO

29

Page 30: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Congestion Control

30

Page 31: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Window Size

Time

Packet Loss

TCP Congestion Control

31

Page 32: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Congestion window resets to 2 after an idle

period (> RTO)

32

Page 33: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

What does real game traffic look like?

33

Page 34: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

low packet ratesmall packet size

34

Page 35: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

“Thin Streams”

35

Page 36: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

36

Page 37: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Max Application Delay

Max RTT

Avg RTT250ms

37

Page 38: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

38

Page 39: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

About 4 packets / sec

39

Page 40: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Average Payload: 100 Bytes

40

Page 41: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Loss Rate 1%

41

Page 42: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

But some experience 6 retransmissions

42

Page 43: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

ShenZhou Online

43

Page 44: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

44

Page 45: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

45

Page 46: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

46

Page 47: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

“Thin Streams”

47

Page 48: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Findings 1: Fast retransmission

rarely triggered

48

Page 49: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

In ShenZhou Online traces, fail to trigger fast retransmission

becauseinsufficient dup ACK (50%)interrupted by data (50%)

49

Page 50: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

50

Page 51: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

51

Page 52: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Findings 2:Delay due mostly to

timeout

52

Page 53: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

53

Page 54: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Findings 3:Congestion window

reset is frequent

54

Page 55: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

55

Page 56: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

12% - 18% of packetsfaces window reset

56

Page 57: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

think..think..think..click (tank attack here)click (missile launch there)click (charge soldiers)

The last command is delayed as congestion window = 2

57

Page 58: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

How to make TCP (or, transport protocol) go faster in these games?

58

Page 59: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

1. Remove exponential backoff

59

Page 60: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

TCP Timeout

X

X

TO

TO

60

Page 61: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

2. Make RTO Smaller

61

Page 62: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

make sure minimum RTO is not 1s

62

Page 63: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

spurious retransmissionis not disastrous

63

Page 64: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

3. Make Fast Retransmit Faster

64

Page 65: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

X

s=100s=200s=300s=400s=500

s=200

a=200

a=200a=200a=200

Retransmit after one duplicate ACK

65

Page 66: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

4. Retransmission Bundling

66

Page 67: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

X

Retransmit all unacknowledge data in queue

67

Page 68: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

5. Redundant Data Bundling

68

Page 69: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

a=300

a=500

Send any unacknowledged segment in queue as long as there is space. Lost data gets

recovered in the next transmission before retransmission.

X

69

Page 70: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

6. Turn off or reduce Delayed ACKs

70

Page 71: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Packet interarrival time on average > 200ms

(can’t combine two ACKs into one)

71

Page 72: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

7. Combine Thin Streams into Thicker

Stream

72

Page 73: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Server

Proxy

73

Page 74: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

TCP for Games

• remove exponential backoff

• reduce RTO

• make fast retransmit faster

• retransmit agressively

• don’t delay ACK

• combine into thick streams

74

Page 75: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Beyond TCP and UDP?

75

Page 76: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Ideal Transport Protocol for Games

• optional reliability

• optional order-of-delivery

• flexibility in organizing messages into different classes with different requirements

76

Page 77: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

SCTPStream Control Transport Protocol

77

Page 78: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Multi-streaming: multiple independent streams

78

Page 79: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

A stream can be either reliable or non-reliable

79

Page 80: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Data from multiple streams can be bundled into one packets

80

Page 81: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Message-oriented (like UDP)

81

Page 82: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Message can be flagged for unordered delivery

82

Page 83: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

Ideal Transport Protocol for Games

• optional reliability

• optional order-of-delivery

• flexibility in organizing messages into different classes with different requirements

83

Page 84: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

SCTP for Games?

84

Page 85: CS4344 09/10 Lecture 10: Transport Protocol for Networked Games

States of SCTP

• rumored to be in Vista

• available in FreeBSD 7 and Solaris 10

• lksctp project for Linux

85