## 4 Proposed Model
### Model Validation
#### 4.4.2 Events Simulation Software Platform (ESSP)
Listing 1 provides a pseudocode representation of the ESSP simulation workflow:```
1 STARTsimulation
3 Initializenext_time_interval_indexto0
4
5 whilecurrent_time-start_time<simulation_timeDO
6 foreachclientinclientsdo
7 event_type=client.game_plan.get_action()
8
9 ifevent_type==\"connect\"orconnected_clientsisemptythen
10 random_client=Selectrandomclient
11 ifrandom_clientnotinconnected_clientsTHEN
12 game_server=game_load_balancer.handle_request(random_client)
13 print\"Clientistryingtoconnect....\"
14 ifgame_serverandnotgame_server.is_capacity_reached(capacity_percentage)then
15 game_cluster=game_server.add_request(random_client.id,random_client.game_location)
17 ifgame_clusterandrandom_client.connect_to_server(game_server)then
18 print\"Clientconnectedogameserver,cluster\"
19 addrandom_clienttoconnected_clients
20 continue
21 else
22 print\"Gameserverisatcapacity,tryingfogserver...\"
23
24 fog_server=fog_load_balancer.handle_request(random_client)
25 iffog_serverthen
26 fog_cluster=fog_server.add_request(random_client.id,random_client.geo_location)
27 iffog_clusterandrandom_client.connect_to_server( fog_server)THEN
28 print\"Clientconnectedfogserver,cluster\"
29 ADDrandom_clienttoconnected_clients
30 else
31 print\"Clientcouldnotconnecttofogserver\"
32 else
33 print\"Clientcouldnotconnecttofogserver\"
34
35 elseifevent_type==\"disconnect\"then
36 client_to_disconnect=Selectrandomconnectedclient
37 print\"Clientisdisconnecting...\"
38 ifclient_to_disconnect.serverthen
39 client_to_disconnect.server.remove_request(client_to_disconnect.id)
40 client_to_disconnect.disconnect_from_server()
41 removeclient_to_disconnectfromconnected_clients
42
43 elseifevent_type==\"move\"then
44 client_to_move=Selectrandomconnectedclient
45 print\"Clientisnowing...\"
46 client_to_move.game_location=Generateerwardmomlocation
47 old_server=client_to_move.server
48
49 game_server=game_load_balancer.handle_request(client_to_move)
50 ifgame_serverthen
51 game_cluster=game_server.add_request(client_to_move.id,client_to_move.gane_location)
```
1 ifgame_clusterthen
2 ifold_serverthen
3 old_server.remove_request(client_to_move.id)
4 client_to_move.connect_to_server(game_server)
5 print\"Clientmovedtogameserver,cluster\"
6 CONTINUE
7 else
8 print\"Tryingtomovetofosserver...\"
9
10
11 fog_server=fog_load_balanceer.handle_request(client_to_move)
12 iffog_serverthen
13 fog_cluster=fog_server.add_request(client_to_move.id,client_to_move.geo_location)
14 iffog_clusterthen
15 ifold_serverthen
16 old_server.remove_request(client_to_move.id)
17 client_to_move.connect_to_server(fog_server)
18 print\"Clientmovedtofosserver,cluster\"
19 else
20 print\"Clientcouldnotmovetofosserver\"
21 else
22 print\"Clientcouldnotmovetofosserver\"
23
24 ifnext_time_interval_index<len(time_intervals)andcurrent_time-start_time>time_intervals[next_time_interval_index]then
25 record_server_loads()
26 INCREEMENTnext_time_interval_index
27
28 latencies=[client.average_latency()forclientINclientsifclient.latency_logEXISTS]
29 average_latency=Computeaverage(latencies)
30 APPENDaverage_latencytoaverage_latencies_with_lb
31
32 average_latency_with_lb,latency_stdev_with_lb=calculate_latency_stats(clients)
33 ENDsimulation
```  
The ESSP simulation includes several key components. The load balancer dynamically assigns requests to the most suitable server or fog node based on load and geographical proximity, ensuring optimal resource utilization. The client component represents users who perform various actions, such as connecting, disconnecting, and migrating between clusters or servers. The server/cluster/fog node infrastructure processes client requests while maintaining capacity constraints, offering scalability and flexibility to manage high-demand scenarios. Additionally, metric logging periodically collects performance data, such as server load and latency, which are crucial for evaluating system efficiency and user experience. ESSP was designed to analyze system behavior under various configurations, including scenarios with and without load balancing.