Multiple resources with one queue

543 views
Skip to first unread message

Michael Fairley

unread,
May 21, 2016, 3:26:18 AM5/21/16
to python-simpy
I would like to model a system where there is a single queue for multiple servers (each with their own service time). This is like the bank renege example but where the counter has different people working and each person provides service at a different rate. I can see how to model a system where each server has their own queue (set up each server as a resource object), but I cannot see an obvious way to model a system with multiple resources sharing the same queue.

James Arruda

unread,
May 21, 2016, 7:29:19 PM5/21/16
to python-simpy
You can have each server be a process that yields on the single queue. If you make a server class with a run method, you can create a bunch of different servers with the same behavior rules quickly.

Michael Fairley

unread,
May 21, 2016, 7:43:10 PM5/21/16
to python-simpy
Thanks, could you expand on your explanation? So I would have a single resource object that each arrival would place a request on. How do I implement the part where the next available server grants this request when it becomes available?

James Arruda

unread,
May 21, 2016, 11:11:57 PM5/21/16
to python-simpy
Sure!

I like to use Stores for queues, since they are FIFO. So whatever generates server requests will just put requests into the queue:

server_queue = Store()

def request_generator():
   
while True:
         
yield env.timeout(some_time_var)
          req_object
= #some object with data about the request
         
yield server_queue.put(req_object)

Then, have your servers watch that queue:

class Server():
   
def __init__(self, params, queue):
       
#do init things

   
def run(self):
       
while True:
           req_obj
= yield self.queue.get()
           
yield env.timeout(req_object.runtime) # or whatever

Use the run method as a process and all your servers will wait for requests, and the first server in line gets the request. 

Michael Fairley

unread,
May 22, 2016, 10:51:34 PM5/22/16
to python-simpy
Awesome, thanks!
Reply all
Reply to author
Forward
0 new messages