Simpy - accessing multiple resources

给你一囗甜甜゛ 提交于 2021-02-11 08:42:42

问题


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:


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?



来源:https://stackoverflow.com/questions/37367019/simpy-accessing-multiple-resources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!