Skip to content

Commit

Permalink
Improved Distribution Mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
MrThanasiz committed Nov 20, 2019
1 parent 13364f0 commit b23c7d3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions LoadBalancer/ResponseProcessorLB.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

serverInstancePath = "..\ServerInstance\\"
serverPath = "servers.txt"
clientsPerServer = 5 #should be set to atleast 2

def sendData(data, module):
data = data.encode()
Expand All @@ -27,15 +28,20 @@ def commandRouter(self, dataEnc, module):

def stateStatus(self, dataDec, module):
if dataDec.upper() == "STYPE":
StorageLB.setServerConnected(StorageLB.getServerConnected(serverPath) + 1, serverPath)

print("NEXT SERVER: ", self.server)
if StorageLB.getServerConnected(serverPath) == 6:
StorageLB.setServerPort(StorageLB.getServerPort(serverPath) + 1, serverPath)
StorageLB.setServerConnected(1, serverPath)
if StorageLB.getServerConnected(serverPath) == 1 or StorageLB.getServerConnected(serverPath) == 6:
if StorageLB.getServerConnected(serverPath) == 0:
StorageLB.createCMD(StorageLB.getServerIP(serverPath), StorageLB.getServerPort(serverPath), serverInstancePath)
StorageLB.runCMD(serverInstancePath)
# if last server is almost full, create a new one, so that it'll be read by the time the next client connects
if StorageLB.getServerConnected(serverPath) == clientsPerServer -1:
StorageLB.createCMD(StorageLB.getServerIP(serverPath), StorageLB.getServerPort(serverPath) + 1, serverInstancePath)
StorageLB.runCMD(serverInstancePath)
if StorageLB.getServerConnected(serverPath) == clientsPerServer:
StorageLB.setServerPort(StorageLB.getServerPort(serverPath) + 1, serverPath)
StorageLB.setServerConnected(0, serverPath)
time.sleep(1)
StorageLB.setServerConnected(StorageLB.getServerConnected(serverPath) + 1, serverPath)
sendData("LB " + StorageLB.getServerIP(serverPath) + " " + str(StorageLB.getServerPort(serverPath)), module)
else:
sendData("Commands: STYPE", module)
Expand Down

0 comments on commit b23c7d3

Please sign in to comment.