Jump to content
Sign in to follow this  
blckeagls

[Guide + Script] Load Balancing Headless Clients

Recommended Posts

Hello All, 

 

Was working on this for a while and figured it would be beneficial for others.

 

My use: offloading database queries and load balancing across multiple headless clients.  Also allow the server to process database queries when headless clients are not online

 

The idea is to use the Server as a communications broker between clients and headless clients.

 

Script: Performs publicVariableClient to an available headless client..  If one is not available, sends the it to the server. (Script has to be ran from the server, owner command only works on the server)



SendToHeadlessClient = {
private ["_var","_owner"];
// The variable to be passed
_var = _this; 
 
 
//Initializing owner variable
_owner = []; 
 
//Checks if there are any headless clients
if (count (entities "HeadlessClient_F") == 0) then { 
 
// If no headless clients send to server
publicVariableServer _var; 
 
} else {
 
// Gets a list of headless client ClientIDs
{
//Is an active headless client
if (_x in allPlayers) then { 
 
//Creates array of clientIDs
_owner = _owner + [owner _x];  
 
};
} forEach (entities "HeadlessClient_F"); 
 
//If active headless clients are online send to headlessclient, else send to server
if (count _owner > 0) then { 
 
//Choose a headless client at random and sends
(_owner call BIS_fnc_selectRandom) publicVariableClient _var; 
 
} else {
 
//Send to server
publicVariableServer _var; 
 
};
};
};


 

Example:

 

Server Code:



"PlayerSendToServer_AddBuilding" addPublicVariableEventHandler {
//Recieves Request from Player
SendToDatabase_AddBuilding = _this select 1;
 
//Calls function to send to a headless client if available, else send back to server
"SendToDatabase_AddBuilding" call SendToHeadlessClient;
};
 
"SendToDatabase_AddBuilding" addPublicVariableEventHandler { 
//Processes Request from Player
(_this select 1) call BuildingObjectInsertIntoDatabase;
};


 

HeadlessClient(s) Code:



"SendToDatabase_AddBuilding" addPublicVariableEventHandler { 
//Processes Request from Player
(_this select 1) call BuildingObjectInsertIntoDatabase;
};


 

Client Code:



_object = "I_Truck_02_medical_F" createVehicle [16699.800781,13586.956055,15.927668];
_object setPosWorld [16699.800781,13586.956055,15.927668];
_direction = random 360;
_object setDir _direction;
 
//Sends request to server to be processed
PlayerSendToServer_AddBuilding = [_object,player];
publicVariableServer "PlayerSendToServer_AddBuilding";


Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×