문제

I have a blocking queue and workers taking from that queue and then working for around 1-10ms.

I would like to figure out some relative figure of how much time the worker was active and idle in a given time frame (e.g 70% active in last minute).

Summing up the short 1ms periods might be to inaccurate and fetching the nano time consumes to much performance.

Is there some neat way of doing such a task?

I have these queue-worker setups more often in my code, therefore I would like to be able to profile bottlenecks at runtime.

EDIT: I only want to know if the thread could be working. If the OS moves the thread out of the processing focus it shall still count. Only when waiting on the queue lock should be counted as idle time.

도움이 되었습니까?

해결책

What about an approach that samples the Thread.getState() of each thread in your pool, and then reports the % of threads that were in each state when samples were taken?

That way you could get a feel for how often threads were found to be in NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING and TERMINATED.

The only other approach that I can think of would be to run your code in a profiling tool. YourKit's Java profiler is very nice, and comes with 1530-day trial license...

http://www.yourkit.com/java/profiler/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top