12 May 2013 02:35
SimPy 3: zombie timeout events
Jonathan Leivent <jleivent <at> comcast.net>
2013-05-12 00:35:18 GMT
2013-05-12 00:35:18 GMT
Here's an unexpected behavior in SimPy 3. Sorry if it sounds a bit too
much like a bad horror movie.
I have a large simulation (thousands of processes), and was measuring
several things about it, including the event queue length
(len(env._events)). After the simulation ran for a while, the event
queue length was growing much larger than I could account for just based
on how many processes exist. I then measured both the length of the
event queue and the number of events on it that have callbacks.
Interestingly, the number of events with callbacks never grows very
high, but the number without callbacks - which I'll refer to as zombie
events (since they won't do anything but die when step finally gets to
them) - grows very high. Further investigation shows that all the
zombies are timeout events (type simpy.core.Timeout).
This simulation makes heavy use of interrupts. That's probably the
source of the zombies. Unfortunately, it would be very hard to change
the simulation design to use substantially fewer interrupts. One very
common type of loop is like this:
while True:
self.adjust_state()
delay = self.compute_delay_to_next_adjustment()
try:
yield self.env.timeout(delay)
except simpy.Interrupt:
continue
where successive timeouts after recalculating following an interrupt are
usually earlier than the timeout they interrupted. Fortunately, there
(Continue reading)
RSS Feed