Regular events - the timeout()
Last chapter we’ve created a grid graph and routed messages through that graph. To see the messages way we’ve marked every node the message passed. Now let’s extend that feature such that this mark disappears after some time.
NetSimLan regularly calls a function called timeout() if implemented. We can use that. Extend your program by the following function and rerun your simulation:
timeout(){
mark(false);
}
You can now see the mark disappearing very fast again. To see better see what’s happening you can slow down the frequency timeout() is called. By default this frequency is one call every 100 ms. It’s randomly differed by ±10% every call to not having every node running completely synchronous and that way be closer to a real environment.
There are two ways to change that frequency:
Change timeout interval by parameter
The first way to change the frequency is to give the parameter -i at startup.
To set the timeout interval to 1 second (=1000 ms) you can call netsimlan gridprogram -i 1000
on Linux.
On Windows there’s a field timeout (ms) where you can enter your timeout.
In general every parameter the netsimlan
command knows you can also enter in the Windows launcher. You can also set the same parameter in Windows to not entering them by hand every time. For this example that’s java.exe -jar Launcher.jar gridprogram -i 1000
.
Change timeout interval at runtime
After starting the simulation you can change the timeout interval in the main window. To do so go to the left area and scroll down to Timeout interval (ms). You can move the slider to change the timeout interval between 10 ms and 10 seconds. Please be aware this isn’t a linear but a logarithmic scale. Whatever you may enter here is for every node in the simulation. It will take effect the next time a node reaches the timeout() function.
Timeout and message delivery speed
When changing the timeout interval you may note the time a message takes from one node to another also changes. This is related to the way a semisynchronous node works:
- Every remote call reaching the node is stored in an input queue. Note remote calls are the only kind of messages between nodes.
- When the end of a timeout interval is reached all messages in this queue are processed. This ensures FIFO order between two nodes.
- After processing all messages the timeout() method is called if implemented.
Beside that semisynchronous node model there’s a asynchronous model offered by NetSimLan. That works in another way:
- Every message reaching the node is stored in an input set.
- When the end of a timeout interval is reached a random number of messages in that set are processed. The processed messages are picked randomly from the input set.
- With probability 1/(m+1) with m messages in the input set no message is processed but the timeout() method is called if implemented. Try it on your own: Restart the simulation but this time you select Implementation model: asynchronous by generating the nodes. Also toy around with the timeout interval.
When you generate nodes in multiple steps, you can also mix up semisynchronous and asynchronous nodes. By hand this means you’d have to create every node little groups of nodes itself and connect them by calling entry() with the right parameter on every node. That’s a bit nasty which leads us to the next chapter.
Previous: Connected Nodes Next: Automated runs