2

I am starting to learn SimPy DES framework.I want to implement a simulation in which requests arrive at different times to the server. There are different types of requests, each one of them loads server with specific memory/cpu load. So, for instance, there might be requests that typically use 10% of CPU and 100MB of mem, while other requests might need 15% of CPU and 150MB of RAM (those are just example numbers). Server has its own characteristics and some ammount of memory. If a request arrive to server and it does not have required amount of resources ready this request should wait. I know how to handle case of a single resource - I could for instance implement CPU load using Container class with capacity of 100 and initial amount of 100, similarly for mememory. However, how do I implement situation in which my requests should wait for both CPU and memory to be available?

Thanks in advance!

1 Answers1

3

The easiest solution would be to use the AllOf condition event like this:

cpu_req = cpu.get(15)  # Request 15% CPU capactiy
mem_req = mem.get(10)  # Request 10 memories
yield cpu_req & mem_req  # Wait until we have cpu time and memory
yield env.timeout(10)  # Use resources for 10 time units

This would cause your process to wait until both request events are triggered. However, if the cpu would be available at t=5 and the memory at t=20, the CPU would be blocked for the whole time (from 5-20 + the time you actually use the CPU).

Might this work for you?

Stefan Scherfke
  • 3,012
  • 1
  • 19
  • 28
  • @StefanScherfke would it also be possible to model the case where two resources are requested, the first one arrives first and begins working without having to wait for the second one? – Allen Wang Apr 25 '17 at 18:29
  • @AllenWang I am trying to code for the exact same scenario. Have you found a solution? – Christian Lemp Dec 20 '17 at 20:54
  • @christianlemp could you give me some more context for your problem? I did develop a solution for my particular use case, but it is kind of specific to filling a demand over time. I could share the code with you if you want (although it won't be until next week) – Allen Wang Dec 22 '17 at 01:26