性能:使用AspectJ记录所有方法的运行时间 [英] Performance: using AspectJ to log run time of all methods

查看:316
本文介绍了性能:使用AspectJ记录所有方法的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用logback和AspectJ将应用程序中每种方法的运行时间记录到数据库中.这是一个大约有数千个类的企业应用程序,每个类中平均大约有10个方法.

I have a requirement to log the run time of every single method in the application to the DB using logback and AspectJ. It's an enterprise application with roughly a few thousand classes and on average about 10 methods inside each class.

我在这里遇到主要的性能问题吗?我知道记录每个方法都是最重要的,但是现在让我们来看一下.

Am I walking into major performance issues here ? I know it's over the top to log every single method, but let's look past that for now.

推荐答案

成千上万个类,每个类具有大约十个方法,您是否必须为所有这些方法实现跟踪日志记录?

Thousands of classes with about ten methods per class and you have to implement trace logging for all of them?

简短答案: 是的.

长答案: 是的.
您的表现将受到(或多或少)严重影响.要记录方法的运行时间,您将(至少)需要一个围绕建议,该建议会花时间进入和退出方法,构造一个字符串并将其发送到日志记录框架.取决于您成千上万种方法的工作方式,对于许多方法而言,它们可能比方法的实际执行还要耗费更多时间-方法越小,开销就越大.

Long answer: Hell yes.
Your performance will be (more or less) heavily affected. To log run time of methods you'll need (minimally) an around advice that takes the time at method entry and exit, constructs a string and sends that to the logging framework. Depending on what your tens of thousands methods do, for a lot of them that may be even more time consuming than the actual execution of the method - the smaller the method the bigger the overhead.

我不能代表您的应用程序,但是对于我的一个应用程序来说,激活跟踪后的实际净性能几乎减少了一半.只有您才能知道,这对您的应用程序是否同样适用还是对您来说是主要性能问题".

I can't speak for your application, but upon doing this for one of mine the actual net-performance with activated tracing just about halved. Whether that will hold true for your application as well or qualifies as your 'major performance issues', only you can tell.

因此,我的建议是只需尝试一下.围绕名称空间中的每个方法编写跟踪建议可以很容易地完成.然后,只需比较跟踪和非跟踪应用程序之间的性能即可.

Thus my advice would be to simply try it. Weaving a trace advice around every method within a namespace can be done easily enough. Then it's just a matter of comparing performances between the traced and non-traced applications.

这篇关于性能:使用AspectJ记录所有方法的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆