Photon Server API Documentation v5.0RC1

Public Member Functions | Properties | Events | List of all members
Photon.Common.LoadBalancer.LoadBalancer< TServer > Class Template Reference

Represents a collection of server instances which can be accessed randomly based on their current lod level. More...

Public Member Functions

 LoadBalancer ()
 Initializes a new instance of the LoadBalancer<TServer> class. Use default weights for each load level. More...
 
 LoadBalancer (string configFilePath)
 Initializes a new instance of the LoadBalancer<TServer> class. More...
 
 LoadBalancer (int[] loadLevelWeights)
 Initializes a new instance of the LoadBalancer<TServer> class. More...
 
 LoadBalancer (int[] loadLevelWeights, int seed, FeedbackLevel priorityUpThreshold=FeedbackLevel.Highest, FeedbackLevel priorityDownThreshold=FeedbackLevel.Highest)
 Initializes a new instance of the LoadBalancer<TServer> class. More...
 
bool TryAddServer (TServer server, FeedbackLevel loadLevel, byte priority=0)
 Attempts to add a server instance. More...
 
bool TryGetServer (out TServer server)
 Tries to get a free server instance. More...
 
bool TryGetServer (out TServer server, Func< TServer, bool > filter)
 Tries to get a free server instance. More...
 
bool TryRemoveServer (TServer server, byte priority=0)
 Tries to remove a server instance. More...
 
bool TryUpdateServer (TServer server, FeedbackLevel newLoadLevel, byte priority=0, ServerState state=ServerState.Normal)
 Tries to update a server instance. More...
 
IList< ServerStateData< TServer > > GetServerStates ()
 Get states of all stored servers regardless of their status (online/offline/oor) More...
 
void DumpState ()
 

Properties

FeedbackLevel AverageWorkload [get]
 Gets the average workload of all server instances. More...
 
FeedbackLevel AverageWorkloadForAvailableServers [get]
 we use this property only for tests More...
 
int AverageWorkloadPercentage [get]
 
bool HasAvailableServers [get]
 
int TotalWorkload [get]
 
int ServersInUseWeight [get]
 
int[] LoadLevelWeights [get]
 
FeedbackLevel PriorityDownThreshold [get, set]
 
FeedbackLevel PriorityUpThreshold [get, set]
 
float ReserveRatio [get, set]
 

Events

EventHandler ServerListUpdated
 

Detailed Description

Represents a collection of server instances which can be accessed randomly based on their current lod level.

Template Parameters
TServerThe type of the server instances.

Each server instance gets a weight assigned based on the current load level of that server. The TryGetServer method gets a random server based on this weight. A server with a higher weight will be returned more often than a server with a lower weight. The default values for this weights are the following:

LoadLevel.Lowest = 40 LoadLevel.Low = 30 LoadLevel.Normal = 20 LoadLevel.High = 10 LoadLevel.Highest = 0

If there is for example one server for eac load level, the server with load level lowest will be returned 50% of the times, the one with load level low 30% and so on.

Type Constraints
TServer :IComparable<TServer> 

Constructor & Destructor Documentation

◆ LoadBalancer() [1/4]

Initializes a new instance of the LoadBalancer<TServer> class. Use default weights for each load level.

◆ LoadBalancer() [2/4]

Photon.Common.LoadBalancer.LoadBalancer< TServer >.LoadBalancer ( string  configFilePath)
inline

Initializes a new instance of the LoadBalancer<TServer> class.

Parameters
configFilePathThe full path (absolute or relative) to a config file that specifies a Weight for each LoadLevel. The possible load levels and their values are defined int the FeedbackLevel enumeration. See the LoadBalancing.config for an example.

◆ LoadBalancer() [3/4]

Photon.Common.LoadBalancer.LoadBalancer< TServer >.LoadBalancer ( int[]  loadLevelWeights)
inline

Initializes a new instance of the LoadBalancer<TServer> class.

Parameters
loadLevelWeightsA list of weights which should be used for each available load level. This list must contain a value for each available load level and must be ordered by the load levels value. The possible load levels and their values are defined int the FeedbackLevel enumeration.

◆ LoadBalancer() [4/4]

Photon.Common.LoadBalancer.LoadBalancer< TServer >.LoadBalancer ( int[]  loadLevelWeights,
int  seed,
FeedbackLevel  priorityUpThreshold = FeedbackLevel.Highest,
FeedbackLevel  priorityDownThreshold = FeedbackLevel.Highest 
)
inline

Initializes a new instance of the LoadBalancer<TServer> class.

This overload is used for unit testing to provide a fixed seed for the random number generator.

Member Function Documentation

◆ DumpState()

void Photon.Common.LoadBalancer.LoadBalancer< TServer >.DumpState ( )
inline

◆ GetServerStates()

IList<ServerStateData<TServer> > Photon.Common.LoadBalancer.LoadBalancer< TServer >.GetServerStates ( )
inline

Get states of all stored servers regardless of their status (online/offline/oor)

Returns

◆ TryAddServer()

bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryAddServer ( TServer  server,
FeedbackLevel  loadLevel,
byte  priority = 0 
)
inline

Attempts to add a server instance.

Parameters
serverThe server instance to add.
loadLevelThe current workload of the server instance.
priorityPriority of server
Returns
True if the server instance was added successfully. If the server instance already exists, this method returns false.

◆ TryGetServer() [1/2]

bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryGetServer ( out TServer  server)
inline

Tries to get a free server instance.

Parameters
serverWhen this method returns, contains an available server instance or null if no available server instances exists.
Returns
True if a server instance with enough remaining workload is found; otherwise false.

◆ TryGetServer() [2/2]

bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryGetServer ( out TServer  server,
Func< TServer, bool >  filter 
)
inline

Tries to get a free server instance.

Parameters
serverWhen this method returns, contains the server instance with the fewest workload or null if no server instances exists.
loadLevelWhen this method returns, contains an available server instance or null if no available server instances exists.
Returns
True if a server instance with enough remaining workload is found; otherwise false.

◆ TryRemoveServer()

bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryRemoveServer ( TServer  server,
byte  priority = 0 
)
inline

Tries to remove a server instance.

Parameters
serverThe server instance to remove.
priorityServer priority
Returns
True if the server instance was removed successfully. If the server instance does not exist, this method returns false.

◆ TryUpdateServer()

bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryUpdateServer ( TServer  server,
FeedbackLevel  newLoadLevel,
byte  priority = 0,
ServerState  state = ServerState.Normal 
)
inline

Tries to update a server instance.

Parameters
serverThe server to update.
newLoadLevelThe current workload of the server instance.
priorityServer priority
Returns
True if the server instance was updated successfully. If the server instance does not exist, this method returns false.

Property Documentation

◆ AverageWorkload

Gets the average workload of all server instances.

◆ AverageWorkloadForAvailableServers

FeedbackLevel Photon.Common.LoadBalancer.LoadBalancer< TServer >.AverageWorkloadForAvailableServers
get

we use this property only for tests

◆ AverageWorkloadPercentage

int Photon.Common.LoadBalancer.LoadBalancer< TServer >.AverageWorkloadPercentage
get

◆ HasAvailableServers

bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.HasAvailableServers
get

◆ LoadLevelWeights

int [] Photon.Common.LoadBalancer.LoadBalancer< TServer >.LoadLevelWeights
get

◆ PriorityDownThreshold

FeedbackLevel Photon.Common.LoadBalancer.LoadBalancer< TServer >.PriorityDownThreshold
getset

◆ PriorityUpThreshold

FeedbackLevel Photon.Common.LoadBalancer.LoadBalancer< TServer >.PriorityUpThreshold
getset

◆ ReserveRatio

float Photon.Common.LoadBalancer.LoadBalancer< TServer >.ReserveRatio
getset

◆ ServersInUseWeight

int Photon.Common.LoadBalancer.LoadBalancer< TServer >.ServersInUseWeight
get

◆ TotalWorkload

int Photon.Common.LoadBalancer.LoadBalancer< TServer >.TotalWorkload
get

Event Documentation

◆ ServerListUpdated

EventHandler Photon.Common.LoadBalancer.LoadBalancer< TServer >.ServerListUpdated