Photon Server API
Classes | Public Member Functions | Properties | 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)
 Initializes a new instance of the LoadBalancer<TServer> class. More...
 
bool TryAddServer (TServer server, FeedbackLevel loadLevel)
 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, out FeedbackLevel loadLevel)
 Tries to get a free server instance. More...
 
bool TryRemoveServer (TServer server)
 Tries to remove a server instance. More...
 
bool TryUpdateServer (TServer server, FeedbackLevel newLoadLevel)
 Tries to update a server instance. More...
 
void DumpState ()
 

Properties

FeedbackLevel AverageWorkload [get]
 Gets the average workload of all server instances. More...
 
bool HasAvailableServers [get]
 
int TotalWorkload [get]
 
int TotalWeight [get]
 

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.

Constructor & Destructor Documentation

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

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.
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.
Photon.Common.LoadBalancer.LoadBalancer< TServer >.LoadBalancer ( int[]  loadLevelWeights,
int  seed 
)
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

void Photon.Common.LoadBalancer.LoadBalancer< TServer >.DumpState ( )
inline
bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryAddServer ( TServer  server,
FeedbackLevel  loadLevel 
)
inline

Attempts to add a server instance.

Parameters
serverThe server instance to add.
loadLevelThe current workload of the server instance.
Returns
True if the server instance was added successfully. If the server instance already exists, this method returns false.
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.
bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryGetServer ( out TServer  server,
out FeedbackLevel  loadLevel 
)
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.
bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryRemoveServer ( TServer  server)
inline

Tries to remove a server instance.

Parameters
serverThe server instance to remove.
Returns
True if the server instance was removed successfully. If the server instance does not exists, this method returns false.
bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.TryUpdateServer ( TServer  server,
FeedbackLevel  newLoadLevel 
)
inline

Tries to update a server instance.

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

Property Documentation

Gets the average workload of all server instances.

bool Photon.Common.LoadBalancer.LoadBalancer< TServer >.HasAvailableServers
get
int Photon.Common.LoadBalancer.LoadBalancer< TServer >.TotalWeight
get
int Photon.Common.LoadBalancer.LoadBalancer< TServer >.TotalWorkload
get