Serverless Simulator

class simfaas.ServerlessSimulator.ServerlessSimulator(arrival_process=None, warm_service_process=None, cold_service_process=None, expiration_threshold=600, max_time=86400, maximum_concurrency=1000, **kwargs)

Bases: object

ServerlessSimulator is responsible for executing simulations of a sample serverless computing platform, mainly for the performance analysis and performance model evaluation purposes.

Parameters
  • arrival_process (simfaas.SimProcess.SimProcess, optional) – The process used for generating inter-arrival samples, if absent, arrival_rate should be passed to signal exponential distribution, by default None

  • warm_service_process (simfaas.SimProcess.SimProcess, optional) – The process which will be used to calculate service times, if absent, warm_service_rate should be passed to signal exponential distribution, by default None

  • cold_service_process (simfaas.SimProcess.SimProcess, optional) – The process which will be used to calculate service times, if absent, cold_service_rate should be passed to signal exponential distribution, by default None

  • expiration_threshold (float, optional) – The period of time after which the instance will be expired and the capacity release for use by others, by default 600

  • max_time (float, optional) – The maximum amount of time for which the simulation should continue, by default 24*60*60 (24 hours)

  • maximum_concurrency (int, optional) – The maximum number of concurrently executing function instances allowed on the system This will be used to determine when a rejection of request should happen due to lack of capacity, by default 1000

Raises
  • Exception – Raises if neither arrival_process nor arrival_rate are present

  • Exception – Raises if neither warm_service_process nor warm_service_rate are present

  • Exception – Raises if neither cold_service_process nor cold_service_rate are present

  • ValueError – Raises if warm_service_rate is smaller than cold_service_rate

analyze_custom_states(hist_states, skip_init_time=None, skip_init_index=None)

Analyses a custom states list and calculates the amount of time spent in each state each time we enterred that state, and the times at which transitions have happened.

Parameters
  • hist_states (list[object]) – The states calculated, should have the same dimensions as the hist_* arrays.

  • skip_init_time (float, optional) – The amount of time skipped in the beginning, by default None

  • skip_init_index (int, optional) – The number of indices skipped in the beginning, by default None

Returns

(residence_times, transition_times) where residence_times is an array of the amount of times we spent in each state, and transition_times are the moments of time at which each transition has occured

Return type

list[float], list[float]

calculate_time_average(values, skip_init_time=None, skip_init_index=None)

calculate_time_average calculates the time-averaged of the values passed in with optional skipping a specific number of time steps (skip_init_index) and a specific amount of time (skip_init_time).

Parameters
  • values (list) – A list of values with the same dimensions as history array (number of transitions)

  • skip_init_time (Float, optional) – Amount of time skipped in the beginning to let the transient part of the solution pass, by default None

  • skip_init_index ([type], optional) – Number of steps skipped in the beginning to let the transient behaviour of system pass, by default None

Returns

returns (unq_vals, val_times) where unq_vals is the unique values inside the values list and val_times is the portion of the time that is spent in that value.

Return type

(list, list)

calculate_time_lengths()

Calculate the time length for each step between two event transitions. Records the values in self.time_lengths.

cold_start_arrival(t)

Goes through the process necessary for a cold start arrival which includes generation of a new function instance in the COLD state and adding it to the cluster.

Parameters

t (float) – The time at which the arrival has happened. This is used to record the creation time for the server and schedule the expiration of the instance if necessary.

generate_trace(debug_print=False, progress=False)

Generate a sample trace.

Parameters
  • debug_print (bool, optional) – If True, will print each transition occuring during the simulation, by default False

  • progress (bool, optional) – Whether or not the progress should be outputted using the tqdm library, by default False

Raises

Exception – Raises if FunctionInstance enters an unknown state (other than IDLE for idle or TERM for terminated) after making an internal transition

get_average_lifespan()

Get the average lifespan of each instance, calculated by the amount of time from creation of instance, until its expiration.

Returns

The average lifespan

Return type

float

get_average_residence_times(hist_states, skip_init_time=None, skip_init_index=None)

Get the average residence time for each state in custom state encoding.

Parameters
  • hist_states (list[object]) – The states calculated, should have the same dimensions as the hist_* arrays.

  • skip_init_time (float, optional) – The amount of time skipped in the beginning, by default None

  • skip_init_index (int, optional) – The number of indices skipped in the beginning, by default None

Returns

The average residence time for each state, averaged over the times we transitioned into that state

Return type

float

get_average_server_count()

Get the time-average server count.

Returns

Average server count

Return type

float

get_average_server_idle_count()

Get the time-averaged idle server count.

Returns

Average idle server count

Return type

float

get_average_server_running_count()

Get the time-averaged running server count.

Returns

Average running server coutn

Return type

float

get_cold_start_prob()

Get the probability of cold start for the simulated trace.

Returns

The probability of cold start calculated by dividing the number of cold start requests, over all requests

Return type

float

get_index_after_time(t)

Get the first historical array index (for all arrays storing hisotrical events) that is after the time t.

Parameters

t (float) – The time in the beginning we want to skip

Returns

The calculated index in self.hist_times

Return type

int

get_request_custom_states(hist_states, skip_init_time=None, skip_init_index=None)

Get request statistics for an array of custom states.

Parameters
  • hist_states (list[object]) – An array of custom states calculated by the user for which the statistics should be calculated, should be the same size as hist_* objects, these values will be used as the keys for the returned dataframe.

  • skip_init_time (float, optional) – The amount of time skipped in the beginning, by default None

  • skip_init_index (int, optional) – The number of indices that should be skipped in the beginning to calculate steady-state results, by default None

Returns

A pandas dataframe including different statistics like p_cold (probability of cold start)

Return type

pandas.DataFrame

get_result_dict()

Get the results of the simulation as a dict, which can easily be integrated into web services.

Returns

A dictionary of different characteristics.

Return type

dict

get_skip_init(skip_init_time=None, skip_init_index=None)

Get the minimum index which satisfies both the time and index count we want to skip in the beginning of the simulation, which is used to reduce the transient effect for calculating the steady-state values.

Parameters
  • skip_init_time (float, optional) – The amount of time skipped in the beginning, by default None

  • skip_init_index ([type], optional) – The number of indices we want to skip in the historical events, by default None

Returns

The number of indices after which both index and time requirements are satisfied

Return type

int

get_trace_end()

Get the time at which the trace (one iteration of the simulation) has ended. This mainly due to the fact that we keep on simulating until the trace time goes beyond max_time, but the time is incremented until the next event.

Returns

The time at which the trace has ended

Return type

float

has_server()

Returns True if there are still instances (servers) in the simulated platform, False otherwise.

Returns

Whether or not the platform has instances (servers)

Return type

bool

is_warm_available(t)

Whether we have at least one available instance in the warm pool that can process requests

Parameters

t (float) – Current time

Returns

True if at least one server is able to accept a request

Return type

bool

static print_time_average(vals, probs, column_width=15)

Print the time average of states.

Parameters
  • vals (list[object]) – The values for which the time average is to be printed

  • probs (list[float]) – The probability of each of the members of the values array

  • column_width (int, optional) – The width of the printed result for vals, by default 15

print_trace_results()

Print a brief summary of the results of the trace.

req()

Generate a request inter-arrival from self.arrival_process

Returns

The generated inter-arrival sample

Return type

float

reset_trace()

resets all the historical data to prepare the class for a new simulation

schedule_warm_instance(t)

Goes through a process to determine which warm instance should process the incoming request.

Parameters

t (float) – The time at which the scheduling is happening

Returns

The function instances that the scheduler has selected for the incoming request.

Return type

simfaas.FunctionInstance.FunctionInstance

trace_condition(t)

The condition for resulting the trace, we continue the simulation until this function returns false.

Parameters

t (float) – current time in the simulation since the start of simulation

Returns

True if we should continue the simulation, false otherwise

Return type

bool

update_hist_arrays(t)

Update history arrays

Parameters

t (float) – Current time

warm_start_arrival(t)

Goes through the process necessary for a warm start arrival which includes selecting a warm instance for processing and recording the request information.

Parameters

t (float) – The time at which the arrival has happened. This is used to record the creation time for the server and schedule the expiration of the instance if necessary.