def test_10_add_server(self): gll = GLL(env=self.env) gll.add_server(*self.servers) self.assertEqual(gll._server_count, self.SERVER_COUNT) for i in range(self.SERVER_COUNT): self.assertTrue(self.servers[i] in gll._server) # Check no duplicates are inserted gll.add_server(*self.servers) self.assertEqual(gll._server_count, self.SERVER_COUNT) for i in range(self.SERVER_COUNT): self.assertTrue(self.servers[i] in gll._server) del gll
def test_20_route_least_loaded(self): gll = GLL(env=self.env, route_config=GLL.LEAST_LOADED) gll.add_server(*self.servers) gll.start() for s in self.servers: s._usage = 1 wr = [] index = [] for i in range(50): # Define which server should be the next chosen index.append(random.randrange(0, self.SERVER_COUNT)) gll._server[index[-1]]._usage = 0 # Create the request we want to submit wr.append(WebRequest(self.env)) gll.submit_request(wr[-1]) while not wr[-1].triggered: self.env.step() gll._server[index[-1]]._usage = 1 for i in range(50): self.assertTrue(wr[i] in gll._server[index[i]]._request_list)
def test_30_usage_interval(self): gll = GLL(env=self.env, route_config=GLL.LEAST_QUEUE) mlb = [] expected_count = 0 expected_usage = 0 for i in range(1, 16): mlb.append( MockLoadBalancer(usage_last_interval=i/16, count=i) ) expected_count += i expected_usage += i**2/16 expected_usage /= expected_count gll.add_server(*mlb) self.assertEqual(gll.usage_last_interval(5), expected_usage) self.assertEqual(gll.count, expected_count)
def test_05_route_config(self): gll = GLL(env=self.env) self.assertEqual(gll.route, None) gll.route_config("Invalid argument") self.assertEqual(gll.route, None) gll.route_config(GLL.TURNING) self.assertEqual(gll.route, gll.route_turning) gll.route_config(GLL.LEAST_LOADED) self.assertEqual(gll.route, gll.route_least_loaded) del gll
def test_15_route_turning(self): gll = GLL(env=self.env, route_config=GLL.TURNING) gll.add_server(*self.servers) gll.start() self.assertFalse(hasattr(gll, '_next_turn')) wr = [] for i in range(10): wr.append(WebRequest(self.env)) gll.submit_request(wr[-1]) all_served = sp.events.AllOf(self.env, wr) while not all_served.triggered: self.env.step() for i in range(10): srv_i = i % self.SERVER_COUNT req_i = i // self.SERVER_COUNT self.assertEqual(gll._server[srv_i]._request_list[req_i], wr[i]) del gll
def test_25_route_least_queue(self): gll = GLL(env=self.env, route_config=GLL.LEAST_QUEUE) loadbalancers = [MockLoadBalancer(i) for i in range(1, 50)] # this will be the one will always be chosen least_queue_load_balancer = MockLoadBalancer(0) loadbalancers.append(least_queue_load_balancer) random.shuffle(loadbalancers) gll.add_server(*loadbalancers) gll.start() for i in range(50): wr = WebRequest(self.env) gll.submit_request(wr) while not wr.triggered: self.env.step() self.assertEqual(wr, least_queue_load_balancer._request_list[-1])
def test_17_usage_interval(self): gll = GLL(env=self.env) with self.assertRaises(TypeError): gll.usage_interval = [5.2, 8] with self.assertRaises(ValueError): gll.usage_interval = 'something' with self.assertRaises(ValueError): gll.usage_interval = '-5.3' with self.assertRaises(ValueError): gll.usage_interval = -5.3 try: gll.usage_interval = '3.5' gll.usage_interval = 0.2 except (ValueError, TypeError) as exc: self.fail(str(exc)) self.assertEqual(gll.usage_interval, 0.2)
from context import pyfarmsim from pyfarmsim.server import Server, FullQueue from pyfarmsim.loadbalancer import GlobalLoadBalancer, LocalLoadBalancer from pyfarmsim.webrequest import WebRequest import simpy as sp import random from savecsv import savecsv from functools import partial random.seed(object()) env = sp.RealtimeEnvironment(strict=False, factor=0.2) # Create a Global Load Balancer gll = GlobalLoadBalancer(env, route_config=GlobalLoadBalancer.TURNING) gll.admission_rate = 50 # Create Local Load Balancers and Servers llbs = [] srvs = [] for x in range(4): llbs.append(LocalLoadBalancer(env, autostart=True)) llbs[-1].admission_rate = 10 srvs.append(Server(env, capacity=2, length=50)) llbs[-1].add_server(srvs[-1]) # Add the local load balancers to the list of VPMs the global loadbalancer # can forward requests to gll.add_server(*llbs) for i in range(4):
from pyfarmsim.webrequest import WebRequest import simpy as sp import random from savecsv import savecsv random.seed(object()) env = sp.RealtimeEnvironment(factor=0.1, strict=False) # Create 2 servers server_sautron = Server(env=env, capacity=2, length=100, name="Sautron") server_tenibres = Server(env=env, capacity=3, length=100, name="Tenibres") # Create a load balancer gll = GlobalLoadBalancer(route_config=GlobalLoadBalancer.TURNING, env=env, autostart=True) gll.add_server(server_sautron, server_tenibres) gll.admission_rate = 5 def request_generator(env, cloud_access, rate, number): for i in range(number): # Get inter request time interval interval = random.expovariate(rate) # Generate a request wr = WebRequest(env, time=0.5, timeout=1) # Submit request to cloud access host