56
NetGrove: New Tools for Network Optimization Tomas Vykruta Software Development Engineer XNA Publishing Platform Microsoft

NetGrove: New Tools for Network Optimization

  • Upload
    brian

  • View
    63

  • Download
    0

Embed Size (px)

DESCRIPTION

NetGrove: New Tools for Network Optimization. Tomas Vykruta Software Development Engineer XNA Publishing Platform Microsoft. Speed of Light Still Constant. Latency. Speed of light = 186,282 miles per second Seattle to L.A. 960 miles = 5 milliseconds Seattle to England - PowerPoint PPT Presentation

Citation preview

Page 1: NetGrove: New Tools for Network Optimization

NetGrove: New Tools for Network OptimizationTomas VykrutaSoftware Development EngineerXNA Publishing PlatformMicrosoft

Page 2: NetGrove: New Tools for Network Optimization

Speed of Light Still Constant

Page 3: NetGrove: New Tools for Network Optimization

Latency• Speed of light = 186,282 miles per second• Seattle to L.A.

• 960 miles = 5 milliseconds• Seattle to England

• 4,799 miles = 26 milliseconds• Speed of light in fiber or copper slows to 60%• Each router adds 5 to 50 ms• DSL or cable modem adds 10 ms

Page 4: NetGrove: New Tools for Network Optimization

Bandwidth on the Rise

Thanks, Bungie!

Page 5: NetGrove: New Tools for Network Optimization

Also on the Rise• Player expectations

• More players in a session together• More voice, video, and background

downloads• Network-using features in your game,

such as data-feeds and spectator modes

• Network-using features in the platform

• Other home devices consuming bandwidth

Page 6: NetGrove: New Tools for Network Optimization

Building a successful title• Optimizing game networking is still

very important!• Have a Plan:

1. Define max bandwidth goal2. Monitor bandwidth during development

**DO NOT LEAVE UNTIL SUBMISSION**

Page 7: NetGrove: New Tools for Network Optimization

Defining Maximum Bandwidth• Host = worst case scenario• Let’s target top 80% of users

• 80% have 175ms or better latency• And 176kb/s down, 226kb/s up or better

bandwidth• From “The Real World: Console Latency

and Bandwidth on Xbox LIVE” white paper on xds.xbox.com

• Subtract reservation (i.e. voice chat)• Divide remaining bandwidth by “max # of

players – 1”

Page 8: NetGrove: New Tools for Network Optimization

Bandwidth Calculation

HOST

CLIENT

CLIENT

CLIENT

CLIENT

56kbps

14kbps

14kbps

14kbps

14kbps

17kbps

17kbps

17kbps

17kbps

5 playergame

68kb

ps

Page 9: NetGrove: New Tools for Network Optimization

Max Bandwidth cont’d• Scenario: theoretical 16 player game with

30 kbps reservation for voice chat• Host is updating 15 players

• And receiving data from 15 players• Max Bandwidth = 9 kbps down, 13 kbps

up per client max

• Also simulate 175 ms latency for playtests• Monitor regularly!

Page 10: NetGrove: New Tools for Network Optimization

Max Bandwidth Worksheet Host Bandwidth 175 kbps   Host Bandwidth 226 kbps Reservation 30 kbps  Reservation 30 kbps Effective 145 kbps  Effective 196 kbps

Players Maximum Kbps Players Maximum kbps2 145.00 2 196.004 48.33 4 65.338 20.71 8 28.00

12 13.18 12 17.8216 9.67 16 13.0720 7.63 20 10.3224 6.30 24 8.5228 5.37 28 7.2632 4.68 32 6.3264 2.30 64 3.11

Page 11: NetGrove: New Tools for Network Optimization

Bandwidth Data 2007-2008Table 1: 2007 Latencies Table 2: 2007 BandwidthPercentage of Consoles with 

this Latency or LessRound Trip Latency Between 

Consoles (ms)

10% 3220% 4530% 5740% 7150% 84 (median)60% 10270% 13080% 17590% 25095% 32097% 38098% 43099% 54099.5% 64099.9% 770

Percentage of Consoles with this Bandwidth or Less

Downstream Bandwidth Between 

Consoles (kb/s)

Upstream Bandwidth Between Consoles (kb/s)

0.1% 20 240.5% 40 441% 64 642% 72 803% 80 885% 104 12010% 144 17620% 176 22430% 200 25640% 248 28050% 336 (median) 352 (median)60% 480 52870% 904 92080% 1760 222490% 5184 5544

Page 12: NetGrove: New Tools for Network Optimization

Latency and Bandwidth Data• 2008 bandwidth stats same as 2007• Median latency 84 ms• Only 10% of consoles are 32 ms or less• Worst case latency 500 ms• 336 kb/s median downstream bandwidth• 352 kb/s median upstream bandwidth• Typical packet loss 2%• Worst case packet loss 10%

Page 13: NetGrove: New Tools for Network Optimization

The Real World• From real-world title network reviews

• Best case = 4 kbps per client in AAA FPS title

• Worst case = 370 kbps+ for the host in a 4 player game of a different AAA title!

Page 14: NetGrove: New Tools for Network Optimization

From a real network review• “Stopped moving” message sent every frame• Many invisible objects simulated• Entire animation state sent (100 bytes+)• Uncompressed data• Position + Orientation + LookAt sent each frame =

12 + 36 + 36 bytes = 84 bytes• Host not coalescing data• NPCs simulated like players• Many more…• End result after optimizations = 5 kbps per client!

Page 15: NetGrove: New Tools for Network Optimization

Run-time Bandwidth Monitoring• Fps, Memory Usage, why not peak

bandwidth?• Display on screen, always present• Visual alert to indicate packet loss

Page 16: NetGrove: New Tools for Network Optimization

Tools• Instrumentation in game code• Subjective playtest experience• Packet sniffing

• Tried and true• Black box and low barrier to entry• Many sophisticated sniffers available

Page 17: NetGrove: New Tools for Network Optimization

Network Monitor 3.2• Process Tracking to identify rogue applications• New engine for improved capture rate in high-

speed networks• Find conversations to view TCP streams, HTTP

flows etc. • Extensive parsers for over 300 protocols! • Network Monitor API: Create your own

applications that capture, parse, and analyze network traffic

Page 18: NetGrove: New Tools for Network Optimization

Network Monitor 3.2

Page 19: NetGrove: New Tools for Network Optimization

Quick NetMon Tour• Conversations• Find frame (CTRL+F)• Display and capture filters

• Declarative language with Intellisense• Color filters• Ex: XSP (by itself) filters down to Xbox LIVE

traffic• NMCAP for command-line captures

Page 20: NetGrove: New Tools for Network Optimization

NetMon Protocols• Extensive script-based protocol

parser language• Documented in NetMon\Help\ParserLanguage.doc

• Create your own!• Trade with your friends! • Sure would be nice if the LIVE

protocol…

Page 21: NetGrove: New Tools for Network Optimization

LIVE Secure Packet Parsing• Xbox 360 SDK and Games for Windows – LIVE SDK

both provide a NetMon Parser• XSP.NPL

• Automatically installs with XDK• Encrypted data is still encrypted

• XNET_STARTUP_DISABLE_PEER_ENCRYPTION to send unencrypted data while debugging

• XSP parser + NetMon filtering + no encryption =

see what’s actually happening on the wire

Page 22: NetGrove: New Tools for Network Optimization

DISABLING ENCRYPTION• XNET_STARTUP_BYPASS_SECURITY added in

November 2008• Disables encryption, view unencrypted XSP

data in NetGrove and NetMon• Flag must be enabled on all consoles

• Silently disabled on RETAIL hardware• Stop using XNET_STARTUP_BYPASS_SECURITY

• Disables authentication and XSP completely

Page 23: NetGrove: New Tools for Network Optimization

LIVE Server Traffic

Traffic to LIVE Statistics / Profile Server

Traffic to LIVE Presence Server

Page 24: NetGrove: New Tools for Network Optimization

PIX – System MonitorPIX providescounters for LIVE servertraffic Traffic to LIVE Statistics

Server

Page 25: NetGrove: New Tools for Network Optimization

So What Do You Do with This?• Debug pathological network conditions

• Excessive or unexpected LIVE traffic (TCR)• Mapping LIVE API calls to actual network traffic

• Optimize and tune?• Not really• No great analysis features• Easy to lose serious problems in the weeds

Page 26: NetGrove: New Tools for Network Optimization

Enter the NetGrove• Ships in the XDK as of March 2008

• Coming soon for Games for Windows – LIVE

• Uses capture files from NetMon 2.0+• Sophisticated analysis of capture files• Flexible and functional GUI• Warning system

Page 27: NetGrove: New Tools for Network Optimization

NetGrove Key Features• Interactive network topology view• Packet traffic view• Enhanced packet information display• Graphical analysis of packet statistics• Text-based output and command-line

usage

Page 28: NetGrove: New Tools for Network Optimization

NetGrove Window

Page 29: NetGrove: New Tools for Network Optimization

Network Topology View

Page 30: NetGrove: New Tools for Network Optimization

Packet Traffic View

Page 31: NetGrove: New Tools for Network Optimization

Packet Information

Page 32: NetGrove: New Tools for Network Optimization

Graphical Analysis of Packet Statistics

Page 33: NetGrove: New Tools for Network Optimization

Warnings Window

Page 34: NetGrove: New Tools for Network Optimization

Text-based output

Page 35: NetGrove: New Tools for Network Optimization

But wait, there’s more!• Includes built-in tutorial and sample

capture file

Page 36: NetGrove: New Tools for Network Optimization

So What Do You Do with This?• Seriously!• First• Some• Discussion• About• Network• Optimization• (An aside in many parts)

Page 37: NetGrove: New Tools for Network Optimization

The Story of Goldilocks• The Goldilocks principle of packet size

• 50 < Payload Size < 1264• Coalesce!

• The Goldilocks principle of frequency• This frequency is JUST RIGHT: 15–20

packets/s• Varies slightly by game type

Page 38: NetGrove: New Tools for Network Optimization

Other Naïve Optimizations• Avoid XSP padding!

• This includes using port 1000 • Avoid struct padding!

• VDP always, UDP rarely, TCP almost never

• Don’t send packets you don’t need to send• For example, don’t send muted voice

Page 39: NetGrove: New Tools for Network Optimization

Slightly More Complex Choices• Do not lock send rate to framerate• Use peer-to-peer networking when

feasible• Don’t need authoritative server• Can’t rely on one server to take high CPU

and network bandwidth load• Definitely send voice peer-to-peer

Page 40: NetGrove: New Tools for Network Optimization

Voice and Video• Always use peer-to-peer networking• Don’t send muted voice• Partition traffic by

• Proximity to player• Team channel• “Importance” rating

Page 41: NetGrove: New Tools for Network Optimization

Compressing Data• Quantize data• Pack Booleans as bit flags• Use polar coordinates (2 parameters) rather

than 3D position (3 parameters)• Use random number seed to send

simulation state• Do not send strings!• For larger chunks, use lossless compression

Page 42: NetGrove: New Tools for Network Optimization

Modern Implementations• Delta compression• Client-side prediction• Lag correction and interpolation• Contextual bandwidth scaling• Separate guaranteed and non-

guaranteed data

Page 43: NetGrove: New Tools for Network Optimization

Sequential Packet Delivery• Use with great caution• Separate guaranteed and non-guaranteed

data into different packets and queues• Can cause serious lag even under ideal

network conditions when a packet is dropped

• Also applies to in-house reliable packet delivery protocols

Page 44: NetGrove: New Tools for Network Optimization

HOST

Sequential Packet Delivery

CLIENT

PACKET 0PACKET 1PACKET 2PACKET 3PACKET 4PACKET 5

STALL

DROPPED

PACKET 1TIMEOUT

REQUESTRESEND PACKET 1

PACKET 1 (R)

GAME

Page 45: NetGrove: New Tools for Network Optimization

Setup Diagram`

Development PCRunning NetMon

Hub

`

GFWL client

*Series of Tubes

*

Page 46: NetGrove: New Tools for Network Optimization

Living With Latency• Embrace quantum uncertainty

• You can never know where an object is• Only where it used to be• ... and how fast it was moving

• The current state is a probability field• Is the cat alive or dead?

• Each player has their own parallel universe• Our goal is to keep the universes similar

• No red pill

Page 47: NetGrove: New Tools for Network Optimization

Prediction Relativity• Remember the parallel universes• Send information relative to the

recipient• “Fired toward position (x, y, z)”

• What if players are in different places?• “Shot at Shawn, missed 10° to the

left”• Robust even if player positions differ

Page 48: NetGrove: New Tools for Network Optimization

Prediction Paradox• Larger packets = less bandwidth• Position + velocity + controller input• More data makes prediction work

better• Allows lower packet send rate• Fewer packet headers

Page 49: NetGrove: New Tools for Network Optimization

Setup• Download and install NetMon 3.2• Run NetMon as Administrator• Enable P-Mode• Use a hub! Switches and routers do

not work.

Page 50: NetGrove: New Tools for Network Optimization

Profiling Your Title• Start with a 2 player capture, then

gradually add more players• Capture with voice and/or video

enabled• Capture lobby, eliminate redundant

traffic• Capture gameplay when all players

are standing still, look for redundant packets

• Capture worst-case scenario (heavy battle)

Page 51: NetGrove: New Tools for Network Optimization

Automated Monitoring• If you already have an automated

nightly runtime “monkey” test• NetGrove.exe -report Results.txt

mygame.cap• Generates detailed report (text

format):

Outbound Inbound Voice Out Voice InSystem name pkt/s kbit/s pkt/s kbit/s kbit/s kbit/s-------------------------------------- ----- ------ ----- ------ --------- --------192.168.1.3 31.3 32.7 36.9 66.6 0.0 0.0192.168.1.2 37.0 66.7 31.3 32.7 0.0 0.0

Page 52: NetGrove: New Tools for Network Optimization

NetGrove in Action

Page 53: NetGrove: New Tools for Network Optimization

Real World Fail Case• Title is ready for final cert• Was only tested with ideal network

conditions throughout development• Tested with 100 ms+ latency for first

time• Terrible lag causing random deaths,

bad user experience• Too late to fix = negative reviews

Page 54: NetGrove: New Tools for Network Optimization

Common Pitfalls• Common pitfalls from real title reviews

• Idle network chatter• Uncompressed data• Unused data• Complex state• High update frequency

(10–15 Hz is sufficient)• Network simulating invisible objects• Lack of prediction• Bugs

Page 56: NetGrove: New Tools for Network Optimization

© 2009 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

http://www.xna.com