3. Photon in a Nutshell
• Photon is a Socket Server & Framework
– Target: Realtime, Multiplayer, Cross Platform Games
• 16k+ registered developers
– 800 new devs every months and rising
– AAA customers: u4ia, Codemasters, Nival, Glu, ...
– Indies: CMUNE, Kogama, Bigbite, 3Sprockets, ...
• Transparent pricing, empower Indies
4. U4ia (= euphoria)
• Industry Veterans (Dusty Welch, Chris Archer & team)
• Free-to-play, AAA, Hardcore, Browser Based Games
• „The middleware that gave us the least headache ...“,
Dan MacDonald, Lead Programmer
4
15. Type of Games
• Room based games (2-32 players)
– FPS, Racer, Casual Game
– Broadcast of Messages to all Players
– Framework: Lite, LiteLobby, Load Balancing
– U4ia: Offensive Combat, CMUNE: Überstrike,
Codemasters: F1 Online, Kogama, ...
• MMO games
– Hundreds of People per Map/World/Region
– Interest Management
– Framework: MMO
– Innogames: Kartuga, FOX: Family Guy Online, ...
18. Rules of Thumb: CCU is Usually Overestimated
• CCU * 10 = DAU
• DAU * 10 = MAU
• MAU * x = Downloads (how many play connected?)
• 100 CCU = 10,000 MAU
• 1,000 CCU = 100,000 MAU
• Real World Sample (Mobile):
– 4,000,000 downloads >> 3,000 CCU
19. Load Test: The Setup
• Scenario
– 25 rooms x 16 players = 400 CCU
– 2 x 50 bytes reliable / s, 10 x 50 bytes unreliable / s
• Server: Quad-Core, 8GB RAM, Win7 x64
– In: 4,500 msg/s (1,2 MB/s)
– Out: 65,000 msg/s (7.5 MB/s)
– CPU: ~30%
– NIC (100Mbit): 80% saturated
– Client RTT: ~40ms
20. Load Test: Traffic is the Cost Driver
• Traffic (400CCU, per month)
– Traffic = 8MB/s * 60 * 60 * 24 * 30 * 50% = ~10 TB
• Cost
– Server Cost (HW, OS & traffic): $400
– Cost per CCU ~= $400/400CCU = $1
– 400 CCU ~= 4,000 DAU ~= 40,000 MAU
– Cost per MAU ~= 1 Cent
21. Load Test: Realworld, our own Cloud
• Largest game has 13,000 CCUs
• 800,000 msg/s (req, resp, ev)
• 90 TB per month traffic
• 40 Servers
– US, Europe & Asia
• Our „perfect“ Box
– Single CPU, 4 Cores, 4GB RAM, 5TB traffic
• Eat your own dogfood (deploy, stability, ops)
22. API/SDK Options
• Plain APIs (full control)
– Operation: Request/Response
– Events: From the server
• Photon Unity Networking (PUN)
– API compatible to Unity Networking
– Using Plain APIs under the hood
– Get it in the Unity Asset Store
• Playmaker (via PUN)
– Using the PUN APIs
23. Photon Unity Networking (PUN)
• Unity Networking (UN) is very convenient, simple and
powerful
• It is the entry point for most Indies to start Networking
experiments
• BUT it has several major draw backs
! UN needs a Master Server to be hosted
! P2P leads to NAT/punch-through issues (especially in mobile
networks)
! Dropped hosts kill the games and so frustrate players
! UN will (probably) never run on the new Unity exports Flash / Chrome
NaCl
24. PUN Feature Coverage
Synchronization RPCs
2 Position, Rotation, Scale 2 From client to client
2 Serialization by script 2 By method name
2 Buffered Instantiation
2 Receiver selectable
- Animation
2 Buffered
Grouping and Scope
- Not supported by server Callbacks
- Events are ignored accordingly 2 Player joins, leaves
2 Connection states
Server Logic 2 Instantiation
2 MasterClient replaces Host
(Remark: Photon is just used as „relay“) Network Simulation
2 Lag, Jitter, Loss
- Bandwidth throtteling
25. Additional Features
Platform as a Service (PaaS) Dashboard
+ No server installs with the Cloud + See CCUs, Disconnects etc.
+ Transparent load balancing
Host Transition
Properties (Rooms and Players) + Remaining players select new
+ Key-Value collection for custom data MasterClient
(name, etc.)
Offline Mode
Runtime Scene GameObjects + Same logic for offline gaming
+ Can be instantiated with owner
“scene“
26. Counters to Track Down Issues
Overall:
A peers disconnects every 2h (average)
20k peers, 80msg/s per room, 800k msg/s
Specific Game:
A peers disconnects every 6-12min (average)
Dig further in ...
31. Running a local Cloud
• Register and get app ID (cloud.exitgames.com)
• Download Photon Server
• Unpack it
• Run “MyCloud”
32. PUN Nuts & Bolts
• Lobby
– Matchmaking
– Properties can be synced
• Rooms
– Exchange data in realtime (text, positions ...)
– Set and get properties of Players and Rooms
33. Quick Usage Intro
• ConnectUsingSettings()
– US, EU or Asia
• Get from the Lobby into a Room quickly
– CreateRoom(), JoinRoom()
• Setup a Monster for network sync
– Add prefab
– Add PhotonView
– Add script for update
34. Properties & using them for Matchmaking
• Properties are a key-value storage for custom data
– Attached to Players or Rooms
– Sample: Attach the played map to a room (map=„Island“)
• Properties can be synced to the Lobby
– Synced properties are defined on creation
– Sample: Sync the map key-value to the Lobby
• JoinRandomRoom() can filter rooms by properties
– Pass in Hashtable of key-value pairs
– Sample: Match rooms with a certain map
35. Tips & Tricks: Loading a Level
• Two main Problems:
– Long loading time causes a timeout (update thread is not called)
– Updates getting lost during load (scene updates ...), e.g. objects do
not exist yet
• Pause message queue and dispatch after load
– Creates a thread to keep connection alive
• Setting a prefix
– Detect quickly if message is for another level
36. Beyond PUN
• Operations, Responses and Events
• Calling operations
• Handling Events
• Event cache
37. Quality of Service (QoS)
• How to reduce messages
• How to read vital stats