Monitoring resource usage

232 views
Skip to first unread message

Parthasarati Dileepan

unread,
Jul 31, 2021, 5:15:56 PM7/31/21
to python-simpy
documentation at the following link, but it is just too much for me. I am looking for an example of how it is used and how to compute time-based average line length. I appreciate any guidance.

camable10

unread,
Aug 3, 2021, 3:14:20 AM8/3/21
to python-simpy
The following lines might help.  Place them somewhere in your code.
Once the simulation ends you can process the list and get the average line length you need.


def monitor(env, data, resource):
  while True:
     item = (
      resource._env.now,  # The current simulation time
      resource.count,  # The number of users
      len(resource.queue),  # The number of queued processes
     )
     data.append(item)
     yield env.timeout(1)   #monitor every 1 time unit



data = []    #list with collected data
env.process(monitor(env, data, resource))   # define the resource to monitor

rt.van....@gmail.com

unread,
Aug 3, 2021, 4:56:10 AM8/3/21
to python-simpy
Beware that  the method proposed by @caam...@yahoo.com is just an approximation of the real length of the queue as the length is tallied only at discrete moments. You could improve the accuray by making a smaller step, at the cost of performance and memory, but you will never get the real mean (and other statistics).
If you want to do it properly, you should tally the length at the moment of a change and do the right (relatively complicated) calculations afterward.
The 'other' discrete event simulation package salabim has so called monitors that take care of all that.

Michael Gibbs

unread,
Aug 10, 2021, 8:50:29 PM8/10/21
to python-simpy
its not that hard, see my post in stack overflow

is...@oakland.edu

unread,
Aug 11, 2021, 7:10:58 PM8/11/21
to python-simpy
I use the same approach as michaelgbs3005. By logging tuples of (time, queue length) you can pretty easily do time averaged stats as shown in the StackOverflow monitor example. If you need things like time averaged standard dev or percentiles you can use DescrStatsW from statsmodels.:

from statsmodels.stats.weightstats import DescrStatsW
Reply all
Reply to author
Forward
0 new messages