Azure worker role: how do I query the memory usage from within the role and sleep or reboot

StackOverflow https://stackoverflow.com/questions/18724220

سؤال

I have a worker role that runs a number of parallel background workers. These workers run tasks that last from one minute to 5 hours and use quite a lot of memory.

I would like to delay the start of a new worker by testing the current level of memory consumption. Something like this:

while (memoryAvailable < 50%) {

    Thread.Sleep( 1000 * 60 * 10 ); // 10 minutes

}

Can I test for available memory within a worker role?

Also, can I automate a reboot of the instance if memory drops below a certain amount?

هل كانت مفيدة؟

المحلول

Since your worker role instances are Windows Server 2012, you can just set up an appropriate perf counter during role startup ( OnStart() ) with whichever pertinent Memory counters you're interested in, and set up a task to observe the perf counter periodically. When available memory drops below your threshold (or committed bytes exceeds your threshold), you can easily recycle the role instance:

RoleEnvironment.RequestRecycle();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top