server | v3 switch to v4  

Photon Azure Starter Kit (PASK)

Important note: If you have never used Photon before stop here and use the standard Photon Server SDK! Run it on your local machine first.

Azure offers two types of hosting methods:

  1. Virtual Machines (VMs) and
  2. Cloud Services (or Web/Worker Roles)

If you are using plain Azure VMs (VMs) stop here and use the standard Photon Server SDK!

If you plan to use Photon Worker Roles you can use this PASK SDK and documentation as a starting point. It is quite a steep learning curve, but the reward is that your service supports autoscaling out of the box.

Introduction To PASK For Azure Worker Roles

This document explains how to setup Photon on Azure with PASK. Learn about Azure PaaS concepts and gain a better understanding of what to expect as a developer of Photon applications in the Azure environment.
The short story: if your application is based on Photon Lite or Photon Loadbalancing it should run out of the box. You can see PASK as an automation solution that bootstraps your application on each new server instance Azure instantiates for your service.

This document will cover:

Back To Top

Prerequisites

Back To Top

Not Covered In This Document


Back To Top

PASK In A Nutshell

To ease the introduction of what PASK is and to demystify "azure" & "worker role" - will begin explaining a couple of Azure concepts and processes:

The Azure worker role-instance is essentially a Windows server with an agent that starts (and monitors) a worker role-application (the managed application developed in visual studio).

When publishing (initial publishing) the worker role gets packaged and uploaded to Azure, the Azure fabric sets up a Windows server instance (worker role-instance) with several drives and starts the worker role-application:

  • C: Logs, ...
  • D: OS
  • E: (or F:) unpacked worker role package
Note: when publishing a second time, the drives change slightly - the worker role application will be in F: instead of E:. Files in C: usually survive the process (when Azure re-starts the instance on the same physical box which is usually the case).

The worker role-application (or photon-role) in PASK is a bootstrapper for Photon and its applications, where

  • C:\photon-logs: is used for logging and
  • E:\Photon\Deploy: is the directory containing the win64 Photon binaries and - resembling the structure known from {photon-sdk}\deploy .

Initially Photon and the applications (in a zip) were part of the Photon-role with the Azure publish process taking care of deployment. But having to upload all every time specially where often only the Photon application changes is cumbersome and slow. To speed up the publishing in PASK the Photon-role package is split up:

  • in three archives that get uploaded to the blob storage:
    • photonapps-.zip
    • photon-server.zip and
    • photon-bintools.zip
  • and the photon-role (worker role-application) - which on startup downloads the archives as part of bootstrapping process.

What does this mean for you as developer:

  • you can develop your Photon application exactly as you have done until know
  • you can access Azure features like blob/table storage from the Photon application (it will work even from your local box)
  • you won't be able to access the worker role-application specific API from within a Photon application. E.g. the RoleEnvironment, the service configuration update event.

Recommended further reading:

Back To Top

PASK Components

PASK located in {photon-sdk}/src-server/Azure consists of:

  • azure.build.prompter.cmd: an interactive batch file to build the zip-files containing Photon and the applications and upload them either to the local(dev) storage or the cloud(azure)
  • azure.build.proj: build file used by build prompter
  • AzureLite:
    • AzureDeploy: VS Cloud Service project - with CloudService Description and Configuration used to publish the AzureWorkerRole
    • AzureWorkerRole: specific Azure.Lite.WorkerRole (inherits from WorkerRoleBase)
    • AzureLite: Photon Application inherits from Lite
    • Config: Photon & Application configuration files
  • AzureLoadbalancing:
    • AzureDeploy: VS Cloud Service project - with CloudService Description and Configuration used to publish the AzureWorkerRole
    • AzureWorkerRole: specific Azure.Loadbalancing.WorkerRole (inherits from WorkerRoleBase)
    • AzureLoadbalancing: Photon Application inherits from Loadbalancing
    • Config: Photon & Application configuration files
  • AzureShared: WorkerRoleBase - core implementation of the Photon Role
  • Tools
    • AzureFileTransfer: used by build-prompter to upload zip files to the blob storage

AzureLite - when deployed each worker role instance consists of

  • Azure.Lite.WorkerRole that bootstraps and monitors the PhotonServer
  • PhotonServer process hosting the Photon applications
    • AzureLite Application
    • Policy Application

AzureLoadbalancing - when deployed each workerrole instance consists of

  • Azure.Loadbalancing.WorkerRole that bootstraps and monitors the PhotonServer
  • PhotonServer process hosting the Photon applications
    • Master Application
    • GameServer Application
    • Policy Application

Back To Top

PASK And Azure Networking Features

In Azure worker role instances are always deployed as part of a cloud service and Azure designates only one IP per cloud service, the instances are behind a load balancer. Azure allows configuration of public-ports for the cloud service that are mapped in two ways to access the worker role instances:

  • load balanced - connections to the public port are load balanced across the instances (local port):
    • cloudservice:3000 (public port) -> instance1:3000 (local port)
    • cloudservice:3000 (public port) -> instance2:3000 (local port)
    • ...
  • port forwarding - instances can be accessed through specific ports by mapping a range of public ports to the instances (local port):
    • cloudservice:3001 (public port = 3000 + instanceindex) -> instance1:3000 (local port)
    • cloudservice:3002 (public port = 3000 + instanceindex) -> instance2:3000 (local port)
    • ...

Azure also supports a concept called custom probes which allows you to configure a port the load balancer probes to check the health of an instance - if an instance fails the load balancer probe it is taken out of rotation - no traffic is routed to that instance anymore.

PASK includes two different worker role projects AzureLite and AzureLoadbalancing, both support multiple instances:

AzureLite - is based on Lite which is designed as a single node service it has no multi-node support. AzureLite is configured to allow access to the single instances per port forwarding. It is basically like deploying Lite on Rackspace or Amazon multiple times only that instead of getting a unique IP for each instance you get a unique set of ports for each instance:

  • udp: 5055 + instanceindex (public port) -> 5055 (local port)
  • tcp: 4530 + instanceindex (public port) -> 4530 (local port)
  • websockets: 9090 + instanceindex (public port) -> 9090 (local port)
Note: that the first instance has index 0.

Policy requests are stateless and configured with load balancing on ports 843 and 943.

AzureLoadbalancing - is based on Loadbalancing and is a multi-node service per design - where clients first connect to the master to join or create a game and then are redirected to the instance hosting the game. Each worker role instance host one Photon instance with two applications Master and GameServer. The ports for the Master are configured as load-balanced ports and custom-probing where only one node is the active Master and positively answers to the probe (currently the rule that define which node is the master is "the node with instanceindex = 0"):

  • udp: 5055 (public port) -> 5055 (local port)
  • tcp: 4530 (public port) -> 4530 (local port)
  • websockets: 9090 (public port) -> 9090 (local port)
  • tcp: 4520 (public port) -> 4520 (local port)

with the custom probe on tcp: 666 (local port).

The service also allows accessing the MasterServers directly (port forwarding) mainly for testing purposes:

  • udp: 10400 + instanceindex -> 5055 (local port)
  • tcp: 10300 + instanceindex -> 4530 (local port)
  • websockets: 10500 + instanceindex -> 9090 (local port)

GameServers ports are configured per port forwarding only:

  • udp: 10400 + instanceindex -> 10400 (local port)
  • tcp: 10300 + instanceindex -> 10300 (local port)
  • websockets: 10500 + instanceindex -> 10500 (local port)

Back To Top

PASK And Logging

In the default {photon-sdk}/deploy structure the log locations are:

  • {photon-sdk}/deploy/log for the Applications
  • {photon-sdk}/deploy/bin_WinXX/log for Photon

In PASK the default log locations are:

  • C:\photon-logs\Applications for the Applications
  • C:\photon-logs\Photon for Photon
  • C:\photon-logs for WorkerRole
Note: To support Windows Azure Diagnostics for Photon and Application logs - the Workerrole is setup to monitor the log files in the Photon and Application directories logs. Changes to the file are piped to the Worker Role Trace Listener.

For further details see Configure Logging.

Back To Top

PASK And The Azure Emulator

Networking - the Azure emulator (Azure SDK 2.2)

  • has limited support for load balancing on tcp
  • does NOT support load balancing on udp
  • does NOT support custom probes
  • does NOT support port forwarding

Directories - to support multiple instances of a worker role on one machine PASK in the emulator:

  • creates instance specific directories, e.g. c:\photon-logs\instance_1, c:\photon-logs\instance_2, see details here.
  • and attaches Photon to instance specific network addresses - replacing 0.0.0.0 with 127.255.0.{instanceindex} - allowing to start multiple instances of Photon on one machine

Back To Top

Quickstart

Note: the Workerrole started in the emulator creates two directories:
  • C:\photon-logs: where the root is hardcoded to C:\
  • C:\photon-azure: where the root depends on the workerrole environment Path.GetPathRoot(Environment.CurrentDirectory) for most it should be C:\
Note: for details on the emulator generated dir structures see here for details on the dir structure generated on the workerrole instance see here and here.

Back To Top

Setting Up PASK On The Azure Emulator

1) Start the storage emulator:

Photon Server PASK: storage emulator

2) Start the Azure build prompter:

Photon Server PASK: Azure Build Prompter

3) Enter 0 to select local environment

Photon Server PASK: select environment

4) Enter 0 to select AzureLite

Photon Server PASK: select Application

5) Enter 1 and 3 to build the zip files photonapps-azurelite.zip, photon-server.zip and photon-bintools.zip:

Photon Server PASK: build prompt

Photon Server PASK: after build

6) Enter 2, 4 and 5 to upload the zip files to the storage emulator:

Photon Server PASK: storage Simulator

7) With CloudXplorer it is very easy to browse the Azure blobstorage in an explorer like UI:

Photon Server PASK: CloudXplorer

Photon Server PASK: CloudXplorer

Photon Server PASK: CloudXplorer

8) Next we will start Visual Studio in elevated modus (elevated is required for the interaction between VS and the Azure compute emulator):

Photon Server PASK: Visual Studio

9) And open the AzureLite.sln

Photon Server PASK:Visual Studio AzureLite.sln

10) To start the worker role in the emulator press F5 or right-mouse-select the Azure.Lite.Deploy project and Start new instance:

Photon Server PASK: start worker role

Photon Server PASK: starting Windows Azure Debugging Environment

11) Now open the Windows Azure emulator system tray and select Show Compute Emulator UI

Photon Server PASK: Windows Azure Simulator

Photon Server PASK: Windows Azure Simulator

12) Notice that in each C:\photon-logs and C:\photon-azure a sub-dir instance_0 was created this is to support starting multiple instances - each instance creates its own sub-dir.

Photon Server PASK: Photon Azure

The dir C:\photon-logs\Instance_X contains the following logs:

  • Photon.Azure.Lite.WorkerRole.LiteWorkerRole.log - should log Working every 10 seconds.
  • Applications\AzureLite.log
  • Applications\Policy.log
  • Photon\PhotonCLR.log
  • Photon\Photon-DefaultX-{YYYYMMDD}.log
Note: on Azure Instance_X will be stripped from the path

Photon Server PASK: Photon Azure

The dir C:\photon-azure\Instance_X:

  • Photon\Upload - containing the zip files previously uploaded to the storage.
  • Photon\Deploy - unpacked zip files (a subset of photon-sdk/deploy).
Note: on Azure photon-azure\Instance_X will be stripped from the path, and the root will be either E:\\ or F:\\ see Connect (RDP) to new instance and view logs

Back To Top

Create An Azure Storage Account

1) The first step to deploy Photon on the cloud is to setup a storage account - for this you go to azure portal, login, on the menu left select STORAGE and click on CREATE A STORAGE ACCOUNT:

Photon Server PASK: Azure Portal create storage

2) Type in the name of account and select a region:

Photon Server PASK: Azure Portal create storage

Photon Server PASK: Azure Portal create storage

3) Once the storage account is created select MANAGE KEYS

Photon Server PASK: Azure Portal manage storage keys

4) And copy the the SECONDARY ACCESS KEY

Photon Server PASK: Azure Portal scondary access key

5) Back in Visual Studio open the ServiceConfiguration.Cloud.cscfg:

Photon Server PASK: Visual Studio Open Service Configuration

6) Set the value of Photon.Azure.StorageAccountName to and set the value of Photon.Azure.StorageAccountKey by pasting the SECONDARY ACCESS KEY copied in 4).

Photon Server PASK: Visual Studio set Azure storage account name and key

7) Once the changes to ServiceConfiguration.Cloud.cscfg are saved - go to the azure.build.prompt.cmd start and enter 1 to select the Azure/Cloud deploy environment

Photon Server PASK: Select Environment

8) Enter 2, 4 and 5 to upload the zip files photonapps-azurelite.zip, photon-server.zip and photon-bintools.zip:

Photon Server PASK: Build Prompt

9) To check zip files are uploaded setup the Azure storage account - setting the Secret Key to the SECONDARY ACCESS KEY copied in 4):

Photon Server PASK: CloudXplorer

Photon Server PASK: CloudXplorer Windows Azure Account

Photon Server PASK: CloudXplorer

Back To Top

Setup Management Certificate

To allow Visual Studio to publish to the cloud we need to setup a management certificate.

1) Open a Visual Studio Command Prompt, change directory to {photon-sdk/src/src-server/azure} and copy/paste and run the following to create the PhotonAzureStarterKitDemo.cer file and install in the Personal Certificate Store "My" of your PC:

makecert -sky exchange -r -n "CN=Photon Azure Starter Kit Demo" -pe -a sha1 -len 2048 -ss My "PhotonAzureStarterKitDemo.cer"

2) (Optionally) You can check the certificate details starting certmgr.msc, navigate to Personal/Certificates and double click on the certificate:

Photon Server PASK: start certmgr.msc

Photon Server PASK: Certificate Thumbprint

3) Next we'll upload the certificate through the azure portal. On the menu left select SETTINGS and click on UPLOAD, in the Upload management certificate-Dialog select BROWSE YOUR COMPUTER

Photon Server PASK: Azure Portal Upload management certificate

4) Navigate to {photon-sdk/src/src-server/azure} and select PhotonAzureStarterKitDemo.cer

Photon Server PASK: Azure Portal Upload management certificate

Photon Server PASK: Azure Portal Upload management certificate

Photon Server PASK: Azure Portal Upload management certificate

Photon Server PASK: Azure Portal Upload management certificate

5) Once the certificate is uploaded select the SUBSCRIPTION ID and copy it - we will need it to setup publishing in Visual Studio - make sure you copy the complete id!

Photon Server PASK: Azure Portal Subscription ID

Note: the THUMBPRINT of the certificate displayed in the portal should be the same you saw in 2).

Back To Top

Publish To Azure

Once the azure storage and management certificate are setup we can publish our service.

1) In Visual Studio right-mouse-select the Azure.Lite.Deploy project and select Publish... from the context menu.

Photon Server PASK: Azure Portal publish

2) In Choose your subscription select

Photon Server PASK: Azure Portal publish

3) Click New

Photon Server PASK: Azure Portal publish settings

4) In Create or select existing certificate - select the certificate we just created Photon Azure Starter Kit Demo - you can check it is the expected Thumbprint.

Photon Server PASK: Azure Portal publish certificate

5) Paste the SUBSCRIPTION ID copied in the last step(5) of setting up the management certificate and set a name for the credentials, e.g. Photon Azure Starter Kit Demo (but can be anything else for you to remember later what account (subscription) the credentials refer to).

Photon Server PASK: Azure Portal Subscription ID and Name

Photon Server PASK: Azure Portal Authentication

Photon Server PASK: Azure Portal Authentication

Photon Server PASK: Azure Portal select subscription

6) Next we will create the cloud service name (choose an appropriate name for it) and select the region (best would be you select the same the storage was created in).

Photon Server PASK: Windows Azure cloud service

7) Next in Settings enable Remote Desktop

Photon Server PASK: Windows Azure publish settings

8) Set the username / password you will use to login to your instances on the cloud

Photon Server PASK: Windows Azure Remote Desktop Configuration

9) In the Publish Summary click on the disc icon to save your settings

Photon Server PASK: Windows Azure Publish Summary

10) And click on Publish

Photon Server PASK: Windows Azure Publish Summary Staging

11) You'll notice the ServiceConfiguration now contains settings for RemoteAccess and in the Windows Azure Activity log you can monitor the progress on publishing:

Photon Server PASK: Windows Azure Activity Log

12) When Azure creates new instances they go through a couple of stages - when the instance gets to stage "unknown" it will appear in the Server Explorer (click on the now active link)

Photon Server PASK: Windows Azure Activity Log

13) Right-mouse-select on the instance will already allow you to create an rdp connection ...

Photon Server PASK: Windows Azure Remote Desktop

14) The rdp-connection will only work once it gets to state "Busy"

Photon Server PASK: Windows Azure Remote Desktop

Photon Server PASK: Windows Azure Remote Desktop

Photon Server PASK: Windows Azure Remote Desktop

15) The instance shouldn't stay long in state "Busy"

Photon Server PASK: Windows Azure Remote Desktop Deploy complete

Photon Server PASK: Windows Azure Remote Desktop Instance running

Note: if it does something went wrong and you'll have to rdp to the instance and check the logs.

Back To Top

Connect (RDP) To New Instance And View Logs

The easiest way to start the rdp-connection is through the Server Explorer in Visual Studio:

Photon Server PASK:Windows Azure Remote Desktop Visual Studio

1) Log into the new created instance:

Photon Server PASK: Windows Azure Remote Desktop

Photon Server PASK: Windows Azure Remote Desktop accept unknown publisher

Photon Server PASK: Windows Azure Remote Desktop credentials

Photon Server PASK: Windows Azure Remote Desktop accept certificate

2) Baretail can be found in E:\Photon\Upload\bin_Tools which can be used to view the Photon logs.

Photon Server PASK: Windows Azure bartail

the directory structure on the new created instance

Photon Server PASK: Windows Azure Direction bartail

is similar to the one described in the Azure emulator

  • C:\photon-logs: for all the logs: ...LiteWorkerrole.log, Photon\*.log and Applications\*.log .
  • E:\Photon\Upload: contains the zip files previously uploaded to the storage.
  • E:\Photon\Deploy: contains the unpacked zip files (an extract from {photon-sdk/deploy}).
Note: as explained in PASK in a Nutshell instead of E: the root will sometimes be F:.

Back To Top

Simple Connectivity Test

To find out the public IP of the new created...

1) Go to the section cloud services of the Azure portal

Photon Server PASK: Windows Azure Portal connectivity test

2) Go to the cloud service dashboard (click on ) and select STAGING and copy PUBLIC VIRTUAL IP ADDRESS (VIP):

Photon Server PASK: Windows Azure Portal dashboard

3) Open a Command prompt window and telnet 943

Photon Server PASK: Windows Azure Portal connectivity test telnet

4) On the remote instance open C:\photon\logs\Photon-Default-YYYYMMDD.log, the last line should show a connection timeout:

Photon Server PASK: Windows Azure Portal connectivity test log

Back To Top

Configuration

All files contained in AzureLite\Config (in Visual Studio see Solution Items\Config) are packed into the photonapps-azurelite.zip file. The bootstrap procedure first unpacks **photon-server.zip - so any configuration file there is overwritten by files contained in Config.

Note: correspondingly for AzureLoadbalancing AzureLoadbalancing\Config is packed in photonapps-azureloadbalancing.zip.

IMPORTANT: to allow multi-instance support in the emulator PASK has to update the PhotonServer.config in a dynamic way (e.g. replacing 0.0.0.0 with 12.255.0.{instanceindex}) this happens after the zip-files are unpacked and before Photon is started in OnPhotonInstalled(). The configuration of the Loadbalancing application is also has adjusted dynamically to the different environments (local-emulator and cloud) see AzureLoadbalancing.OnPhotonInstalled().

Back To Top

Logging

In this section we will cover how logging is configured for the different components of PASK. In a nutshell the way logging configuration is setup

  • PASK logging is based on log4net
  • PASK logging locations are meant to follow a standard - similar to what Photon does only adapted to the Azure environment.
  • the Photon log location (UnmanagedLogPath) in PASK is configured to C:\photon-logs\Photon in PhotonServer.config and shouldn't be changed the multi-instance support of the emulator is hardcoded to replace that string.
  • Applications log location is configured using log4net properties in the .config, which are set in the application using environment variables set by Photon, e.g.:
    • Photon:UnmanagedlogDirectory = Application.UnmanagedLogPath is set in the application, which is set to C:\photon-logs\Photon during the Application setup.
    • in the .config the property is used to define the location relative to the unmanagedLogPath %property{Photon:UnmanagedLogDirectory}..\Applications\%property{LogFileName}.log

Photon Server PASK: Azure Lite Solution

Back To Top

1) AzureLite Log4net

Photon Server PASK: Azure Lite log4net.config

Uses the application set property Photon:UnmanagedLogDirectory to define the location for the log files. See the class AzureLiteApplication.cs in the Azure.Lite project; it uses the Application.UnmanagedLogPath which is an environment variable set by the PhotonServer, see bin_Win64 below:

Back To Top

2) Bin_Win32_xp

Is only used for emulator on win32 machines and configuration is identical to bin_Win64.

Back To Top

3) Bin_Win64

Photon Server PASK: Photon Server Config

The setting LogFileLocation defines the location of the PhotonServer logfiles and is an Environment variable passed to the PhotonApplications as Application.UnmanagedLogPath. It is set to C:\photon-logs\Photon.

Back To Top

4) Policy Log4net

Photon Server PASK: Policy log4net.config

Uses the application set property Photon:UnmanagedLogDirectory to define the location for the logfiles. For more details see the section "AzureLite log4net".

Back To Top

5) Azure.Lite Log4net

Is only used when Azure.Lite is started in Photon locally not using the Azure emulator.

Back To Top

6) Azure.Lite.WorkerRole Log4net

Uses the application set property Photon:ApplicationLogPath to define the location for the logfiles. The Azure.Lite.Workerrole sets it to the WorkerRolebase.Logpath:

Back To Top

Ports (ServiceDefinition)

The ports for the Azure cloud service are defined in the ServiceDefinition.csdef file. We use two types of port definitions

  1. InstanceInputEndpoints: dynamically define a range of ports for each new instance. In our case the first instance will be reached per udp on port 5055, the second instance on 5056, the third on 5057, ... (for those new to Azure - an Azure service only has one IP-Address - access to specific instances is done per port mapping).
  2. InputEndpoints: define ports that are load balanced by the Azure load balancer. In our case we use them for policy requests, where it doesn't matter which instances serves the request.

Photon Server PASK: Ports Service Defintion

Back To Top

Workerrole Behavior (ServiceConfiguration)

Photon Server PASK: Worker role behavior service configuration

  • Photon.Azure.StorageContainer: name of container in Azure storage hosting the zip files containing the Photon and application binaries the workerrole installs on each instance.
  • Photon.Azure.StorageAccountName Azure storage account name.
  • Photon.Azure.StorageAccountKey: Azure storage account key.
  • Photon.Azure.PhotonServerZip: name of zip containing the Photon server binaries (note: it also contains the policy application binaries).
  • Photon.Azure.PhotonBinToolsZip: name of zip-file containing the Photon bintools.
  • Photon.Azure.PhotonApplicationsZip: name of the zip-file containing the AzureLite binaries and all the configuration files contained in {photon-sdk}/src-server/Azure/AzureLite/Config (in Visual Studio see Solution Items/Config)
  • Photon.Azure.UseWin64inEmulator: can be set to true if development machine is win64.
  • Photon.Azure.PhotonRestartsMax: number of times the workerrole restarts Photon before it fails, default is 0.
  • Photon.Azure.SetBusyIfFailedOnStart: defines behavior when the workerrole fails during startup - recommended during development is true, which prevents Azure from restarting the instance - on error the instance will be only marked busy.
  • Photon.Azure.SetBusyIfFailedOnRun: defines behavior when the workerrole fails during runtime - recommended during development is true, which prevents Azure from restarting the instance - on error the instance will be only marked busy.

Back To Top

AzureLoadbalancing

Building And Deploying

The build and publish process for AzureLoadbalancing is exactly the same as with AzureLite. Follow the steps described in Quickstart replacing AzureLite with AzureLoadbalancing.

Back To Top

Selfconfiguring Connectivity

Each worker role instance hosts a Master and a GameServer application. The service auto configures itself in the following way:

  • the Workerrole creates a Nodes.txt containing a line for each instance with: nodeid (= instanceindex + 1), IP address and a "Y" to mark itself.
    • in the emulator
    • on instance 0 it would be:
      • 1 127.255.0.0 Y
      • 2 127.255.0.1 N
    • on instance 1 it would be:
      • 2 127.255.0.1 Y
      • 1 127.255.0.0 N
    • in the cloud (azure)
    • on instance 0 you will have something like (ip addresses will vary):
      • 1 10.76.146.49 Y
      • 2 10.76.138.82 N
    • on instance 1 it would be:
      • 2 10.76.138.82 y
      • 1 10.76.146.49 N
  • the Master Application reads the node.txt and follows changes of the environment
  • the Master Application with the nodeid=1 is defined as the active Master:
    • in Application.OnSetup() this instance initializes the custom probe for the load balancer. Clients connecting to the public ports 5055, 4530 and 9090 are connected to this instance.
    • GameServers connecting to their local Master are redirected to the active Master
Note: the active Master currently is fixed to nodeid=1 (which is the equivalent to instanceindex=0). In a future release we plan to add a failover feature through a flexible leader election which would allow any node to take the role of active Master.

Back To Top

Sample Logs Explained (from Azure)

Bellow you can see an excerpt of the Applications\Master.log for nodeId=2 (lines 3 and 4), it shows the local gameserver being rejected (lines 14-17).

On nodeid=1 the active master (lines 3,4 and 11) you'll see it registering correctly (lines 31-34):

Back To Top

OnPhotonInstalled()

As mentioned in Configuration the Azure.Loadbalancing.Workerrole sets up the GameServer in Photon.Azure.Loadbalancing.dll.config:

  • MasterIPAddress: defines the IP Address the GameServer uses to connect to the Master
  • PublicIPAddress: IP Address the GameServer uses to register on the Master (clients connect on that IP Address) - when this setting is empty the GameServer auto detects its public IP Address.
  • RelayPortTcp, RelayPortUdp, RelayPortWebSocket: configure Azure port forwarding support - the GameServer usually registers the ports configured in GamingTcpPort, GamingUdpPort and GamingWebSocketPort to the Master - when the RelayXXX ports are set (!= 0) the GameServer registers with RelayXXX + {instanceindex}.

As you can see from the following code because currently the emulator doesn't support port forwarding the RelayXXX* settings are set to **0. The GameServer in the cloud is configured to connect to its local Master Application (MasterIP set to 127.0.0.1) and it registers with an auto detected PublicIp address. As explained earlier in the emulator each instance of the worker role attaches a Photon process to a instance specific IP address (127.255.0.{instanceindex}). On the application level each GameServer connects to its CurrentInstanceAddress and reports its CurrentInstanceAddress. Note: this means that currently only local connectivity is supported when running in the emulator.

var filepath = Path.Combine(this.PhotonDeployPath, @"AzureLoadbalancing\bin\Photon.Azure.Loadbalancing.dll.config");

if (RoleEnvironment.IsEmulated)
{
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='MasterIPAddress']/value", this.CurrentInstanceAddress);
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='PublicIPAddress']/value", this.CurrentInstanceAddress);
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='RelayPortTcp']/value", "0");
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='RelayPortUdp']/value", "0");
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='RelayPortWebSocket']/value", "0");

}
else
{
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='MasterIPAddress']/value", "127.0.0.1");
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='PublicIPAddress']/value", "");
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='RelayPortTcp']/value", "10300");
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='RelayPortUdp']/value", "10400");
    SetPublicIpInConfigFiles(filepath, "//Photon.LoadBalancing.GameServer.GameServerSettings/setting[@name='RelayPortWebSocket']/value", "10500");
}

기술문서 TOP으로 돌아가기