0
votes

I am using Akka actors to simulate a real world situation. It depends on time, so I need a way to introduce an idea of a simulated time. For example, where 1s real time = 1ms simulated time. Normally messages arrive in the order they are sent (at least with the default dispatcher and locally). However, I need them to arrive in order based on the simulated time.

A message that is in the far-future could be sent before one in the near-future, as it incorporates a simulated time delay. The messages come with a sent field, providing the simulated time when the message was sent.

For instance, could I block messages that should arrive in the future? By keeping a waiting list in the actor and release the messages as the appropriate simulated time arrives?

Any other methods you would suggest?

1

1 Answers

1
votes

Search the net for "discrete-event simulation". Generally, real time has no relation to simulated time like "1s real time = 1ms simulated". Instead, simulated time is modelled with a priority queue, where priority is considered as simulated time. Each message, beside the destination address, has time value denoting the simulated time when it must arrive. All messages first are routed to the priority queue, then the simulator changes the reading of simulated clock to the nearest present in the queue, with no relation to the real time. All messages scheduled for that time are routed to destination, are processed, causing new messages to be routed to the priority queue, and then the clock is moved to the next time referenced in messages.

Since the interface of the message sending includes the value of simulated time, it differs from the Akka interface, so you cannot use Akka directly for your task. Look at List of discrete event simulation software to choose appropriate library.