perfsim

Contents

perfsim#

Subpackages#

Module contents#

PerfSim package is a discrete event simulator that simulates the behaviour of microservices in a Kubernetes cluster.

Submodules#

perfsim.cluster module#

class perfsim.cluster.Cluster(name, simulation, topology, service_chains_dict=None, scm_dict=None, network_timeout=inf)[source]#

Bases: Observable

A Cluster is imitating a real heterogeneous cluster with a configurable NetworkTopology, PlacementScenario and a set of ServiceChainManager instances.

Param:

name: Name of the cluster

Param:

service_chain_managers: A dict of all service chains running on the cluster

Param:

placement_algorithm: The hosts and routers’ placement scenario on the cluster

Param:

topology: The network topology of the cluster

Param:

network_timeout: The network timeout

Parameters:
name: str#

Name of the cluster

sim: Simulation#

The parent Simulation instance

topology: Topology#

The network topology of the cluster

network_timeout: float#

The timeout threshold for network transmissions

cluster_scheduler: ClusterScheduler#

The ClusterScheduler of this cluster responsible for scheduling replicas on the given topology

reinit()[source]#

Reinitialize the cluster

Returns:

None

count_total_service_edges()[source]#

Counts the total number of edges in the service topology that is being deployed in this cluster.

Returns:

The total number of edges in the service topology

register_events()[source]#

Register all events of the cluster

Returns:

None

set_service_chains_dict(service_chains_dict)[source]#

Set the service chains of the cluster

Parameters:

service_chains_dict (Dict[str, ServiceChain]) – The service chains to set

Returns:

None

set_scm_dict(scm_dict)[source]#

Set the service chain managers of the cluster. This method is used to set the service chain managers of the cluster when the cluster is created from a dictionary of service chain managers.

Parameters:

scm_dict (Dict[str, ServiceChainManager])

Returns:

property scm_dict: Dict[str, ServiceChainManager]#

List of all ServiceChainManager references running on this cluster

Returns:

The list of all ServiceChainManager references running on this cluster

is_there_a_thread_that_ends_sooner(time_of_next_event)[source]#

Check all active threads to see if there is one that ends sooner that time_of_next_event

Parameters:

time_of_next_event (int)

Return type:

Tuple[float, float, bool]

run_threads_on_hosts(duration)[source]#

Run all threads on all active hosts for duration nanoseconds

Parameters:

duration (float) – Duration of threads execution in nanoseconds

Return type:

int

run_active_threads(duration)[source]#

Transmit all requests in network for duration nanoseconds

Parameters:

duration (Union[int, float]) – Duration of threads execution in nanoseconds

Return type:

int

transmit_requests_in_network(duration)[source]#

Transmit all requests in network for duration nanoseconds

Param:

duration: Duration of network transmissions in nanoseconds

Returns:

None

Parameters:

duration (Union[int, float])

load_balance_threads_in_all_hosts()[source]#

Perform CPU load-balancing on all hosts

Returns:

None

run_idle(until)[source]#

Running threads idle for until - core.runqueue.time nanoseconds

Parameters:

until (int) – The time when running idle stops.

Return type:

None

property microservices_dict#

List of all Microservice references running on this cluster

Returns:

The list of all Microservice references running on this cluster

draw_all_service_chains(save_dir=None, show=True)[source]#

Draw all service chains of the cluster

Parameters:
  • save_dir (str)

  • show (bool)

Returns:

calculate_average_latency_in_seconds()[source]#

Calculate the average latency in seconds

Returns:

The average latency in seconds

print_and_plot_scenarios(printing=True, plotting=True)[source]#

Print and plot the scenarios

Parameters:
  • printing (bool)

  • plotting (bool)

Returns:

plot_hosts_cpu_heatmaps(save_dir=None, show=True)[source]#

Plot the hosts’ CPU heatmaps

Parameters:
  • save_dir (str) – The directory to save the heatmaps

  • show (bool) – Whether to show the heatmaps or not

Returns:

None

perfsim.cluster_scheduler module#

class perfsim.cluster_scheduler.ClusterScheduler(cluster)[source]#

Bases: object

This class is responsible for scheduling the cluster.

Parameters:

cluster (Cluster)

hosts_dict: Dict[str, Host]#
replicas: Set[MicroserviceReplica]#
active_hosts: Set[Host]#

The set of active hosts in the cluster that are actually having a thread running on them.

hosts_need_load_balancing: Set[Host]#

The set of hosts in the cluster that require CPU load balancing.

zombie_threads: Set[ReplicaThread]#

The set of zombie threads in the cluster that needs to be killed

active_threads: Set[ReplicaThread]#

The set of active threads in the cluster that are actually running on a host.

cluster: Cluster#

The cluster to which this scheduler belongs

property placement_matrix: DataFrame#

Get the placement matrix.

Returns:

reschedule(hosts_dict=None, use_current_hosts=False)[source]#

Reschedule the cluster.

Parameters:
  • hosts_dict (Dict[str, Host]) – The dictionary of hosts.

  • use_current_hosts (bool) – Whether to use the current hosts or not.

Returns:

None

perfsim.simulation module#

class perfsim.simulation.Simulation(name, simulation_scenario, service_chains_dict, topology_prototype, placement_algorithm, resource_allocation_scenarios_dict, affinity_prototypes_dict, traffic_prototypes_dict, storage_driver, validate=False, copy=True)[source]#

Bases: object

This class represents a simulation. It contains all the necessary information to run a simulation.

Parameters:
DEFAULT_DEBUG_LEVEL = 0#
DEFAULT_DEBUG_FILE_LOCATION = False#
DEFAULT_LOG_CPU_EVENTS = False#
DEFAULT_LOG_TIMELINE = False#
name: str#

The name of the simulation

scenario: SimulationScenario#

scenario is the simulation scenario

logger: Logger#

Collects various logs during simulation

service_chains_dict: Dict[str, ServiceChain]#

service_chains_dict is a dictionary of service chains

microservices_dict: Dict[str, Microservice]#

microservices_dict is a dictionary of microservices

topology: Topology#

topology is the topology of the simulation

resource_allocation_scenarios_dict: Dict[str, ResourceAllocationScenario]#

resource_allocation_scenarios_dict is a dictionary of resource allocation scenarios

affinity_prototypes_dict: Dict[str, AffinityPrototype]#

placement_algorithm is the algorithm used to place the microservices

traffic_prototypes_dict: Dict[str, TrafficPrototype]#

traffic_prototypes_dict is a dictionary of traffic prototypes

storage_driver: ResultsStorageDriver#

storage_driver is the storage driver of the simulation

cluster: Cluster#

cluster is the cluster of the simulation

load_generator: LoadGenerator#

load_generator is the load generator of the simulation

static set_object(obj, copy)[source]#

Set an object with or without copy

Parameters:
  • obj (Any)

  • copy (bool)

Returns:

setting_scaling_scenario()[source]#

Setting the scaling scenario

Returns:

None

setting_affinity_scenarios()[source]#

Setting the affinity scenarios

Returns:

validate_simulation_scenario(sim_scenario)[source]#

Validate the simulation scenario to make sure all the microservices are in the simulation scenario It raises an exception if a microservice is not found in the simulation scenario

Parameters:

sim_scenario (dict) – The simulation scenario

Returns:

None

static copy_sim_scenarios_to_dict(sim_scenarios)[source]#

Copy simulation scenarios to a dictionary

Parameters:

sim_scenarios (Union[List[SimulationScenario], Dict[str, SimulationScenario]])

Return type:

Dict[str, SimulationScenario]

Returns:

set_debug_properties(level=None, file_path=None, log_cpu_events=None, log_timeline=None)[source]#

Set debug properties

Parameters:
  • level (Union[bool, int])

  • file_path (str)

  • log_cpu_events (bool)

  • log_timeline (bool)

Returns:

property log_timeline#

Log timeline

Returns:

property debug#

Status of debug mode (automatically configured based on _debug_level)

Returns:

property debug_level#

Level of debug verbosity (1-5)

Returns:

Return debug level

property debug_file_location#

Return log file location :return: Log file path - None if empty (then log will print out in console) :rtype: str

property log_cpu_events#

Status of logging CPU events (used for drawing task load balancing heatmaps) :return: bool

property time: int#

Simulation time :return: Simulation time :rtype: float

static from_scenarios_manager(sm)[source]#

Create simulations from scenarios manager

Parameters:

sm (SimulationScenarioManager)

Return type:

dict[str, Simulation]

Returns: