开发者

java statistics collection for performance evaluation

What is the most efficient way to collect and report performance statistic analysis from an application?

If I have an application that uses a series of network apis, and I want to report statistics at runtime, e.g.

Method doA() was called 3 times and consumed on avg 500ms  
Method doB() was called 5 times and consumed on avg 1200ms etc  

Then, I thought of using a well defined data structure (of collection) that each thread updates per remote call, and this can be used for the report.

But I think that it will make the performance worse, for the time spend for statistics collection. Am I correct? How would I procceed if I used a background thread for this, and the other threads that did the remote calls were u开发者_运维问答naware of this collection gathering?

Thanks


There are different ways to go about this:

  1. Dynamic alteration (Easy to Code - Very likely to Alter performance): Here you use code weaving (AspectJ or similar library) or dynamic proxying to do the counting. This has the pro of being very fast to setup and could give you the general idea. However, it carries the most overhead to your performance and will alter your results if your application is very finely tuned.

  2. Static alteration (Needs more code - lower performance impact): Here you create some ThreadLocals or a ConcurrentHashMap based on how do you want to track your stats (Per Thread or Across the application), impact here is a map lookup with a string key, no locking guaranteed and an integer increment. Which shouldn't mess up your data and is pretty constant and can be measured alone and factored out from your stats.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜