简体   繁体   English

使用Spring AspectJ进行日志记录的性能影响

[英]Performance impact of logging using Spring AspectJ

We are working on a web application where we are logging input and output of all the database calls in DAO classes. 我们正在开发一个Web应用程序,在其中记录DAO类中所有数据库调用的输入和输出。 An example is: 一个例子是:

@Override
public List<Long> findUsers(final List<Long> userIds) {
    LOGGER.info("findUsers: finding user ids  by  followeeId {} ", userIds);
    ... // hibernate DB call
    LOGGER.info("findUsers: number of ids  founds are {}", userIdList.size());  

This code will be present inside all the DAO classes, and the number of such classes is around 100, and it may go higher. 此代码将出现在所有DAO类中,并且此类的数量大约为100,并且可能会更高。

My question is shall we continue logging the info in the same way or shall we go for Spring-AspectJ implementation? 我的问题是我们应该继续以相同的方式记录信息还是应该去Spring-AspectJ实现? -We'll have an aspect defined for @Before and @After for all such methods. -我们将为所有此类方法的@Before@After定义一个方面。 This aspect will call logger and log the required info. 这方面将调用记录器并记录所需的信息。

Will implementing Spring-AspectJ be a performance hit? 实施Spring-AspectJ会对性能产生影响吗? Any pointers are appreciated. 任何指针表示赞赏。

I have gone through the below SO questions, but need some more clarity with respect to the example quoted above. 我已经经历了下面的SO问题,但是相对于上面引用的示例,需要更多的说明。

Using AOP will give you a small performance penalty, how much depends on how you apply AOP (proxies or weaving) and what you do in your aspect. 使用AOP会给您带来很小的性能损失,多少取决于您如何应用AOP(代理或编织)以及您在方面所做的工作。 I would suggest using Springs CustomizableTraceInterceptor or if you are also interested (or more interested in performance one of the subclasses of AbstractMonitoringInterceptor saves you implementing your own. 我建议您使用Springs CustomizableTraceInterceptor或者如果您也对性能感兴趣(或对性能更感兴趣),则AbstractMonitoringInterceptor的子类之一可以节省您实现的工作。

I wouldn't log in the way you are doing it as it is easy to forget and if you want to change something (or disable logging) you have to change those 100 classes instead of 1 or just configuration. 我不会以您执行操作的方式登录,因为它很容易忘记,并且如果您想更改某些内容(或禁用日志记录),则必须更改这100个类而不是1个类或仅更改配置。

如果您正在使用sping aop,则会降低您的性能,此外,如果您将spring与Aspectj一起使用,它的性能也会更好,请参见此处http://docs.spring.io/spring-framework/docs/current/spring-framework-reference /html/aop.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM