I am developing a MMORPG game server, while this approach is not needed for 80% of the functions in the game server, 20% of the functions that will use it make up 99% of the resources.
I am trying to perform a throttled function. Let's say you call a massive function, or you are looking for a massive data structure for certain criteria. This one of the called calls can lead to massive CPU usage.
For example, a massive function when calling uses 30% of the processor software for 4 seconds to complete, say, we are looking for millions of records in the auction system by criteria. Imagine that we have 4 people who do this right away. I want the same method to accept only 1% of the processor or less, taking perhaps more than 15-20 seconds to return the same result without starving equipment.
I am currently using this class.
public class AsyncLazy<T> : Lazy<Task<T>> { public AsyncLazy(Func<T> valueFactory) : base(() => Task.Factory.StartNew(valueFactory)) { } public AsyncLazy(Func<Task<T>> taskFactory) : base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap()) { } }
This does not block the initialization of the value and does not block when consuming a lazy value. However, during mass operations, performing the operation causes the hardware to end, resulting in 30% CPU utilization within 4 seconds. My goal is to throttle calls for virtually unlimited time so that they can complete their task without starving equipment.
Edit: Thanks to Scott Chamberlin for correcting me with the correct jargon. I am not trying to call the method lazily, but I am looking for special calls to the Throttle method.
source share