通过在servlet中使用外部jar来影响性能 [英] Impact on performance by using external jars in servlets

查看:156
本文介绍了通过在servlet中使用外部jar来影响性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse WTP作为项目。它需要使用很少的库。几个体积小,少数较大。我的问题是,当我们在servlet中使用外部jar时会发生什么?如果我在Servlet中导入了一个重量级的库,它会影响网页加载时间吗?



或者Java只是编译我的程序,包括库来提供结果。我知道重型jar将需要一些时间来加载我的本地机器,但我可以管理它们只被启动一次(通过创建一个单独的类,并启动静态变量并使用它们从其他类)。但是似乎这样,这不能在Servlet中完成,并且每次加载一个页面时,servlet都必须加载所有那些沉重的jar。



在Servlets中使用Guava和Solrj是否很好?他们放慢了(询问,因为我觉得Solrj正在减缓网页加载时间)?

解决方案

本身并没有减慢servlet的运行时间。但是,在jar中使用特定的工具/类/功能可能会减慢servlet,具体取决于您正在尝试的操作。



我建议使用分析器来分析你的代码实际上决定了它导致的减速。 这是Martin Fowler的重构的报价:


我已经猜测了团队的各个成员(肯特和马丁否认参与投机),我们知道的代码可能是错误的。我们甚至勾画出一些改进的设计,而无需首先衡量发生了什么。



我们完全错了。除了有一个非常有趣的谈话之外,我们还是没有任何好处。



这个教训是:即使你知道系统正在发生什么,测量性能,不要推测。你会学到一些东西,十分之九,这不会是你是对的!



I am using Eclipse WTP for a project. It requires few libraries to be used. Few are small in size and few are larger. My question is, what happens when we use external jars in servlets ? If I am importing a heavy-weight library in a Servlet, does it impacts webpage load time ?

Or Java just compiles my program including libraries to give results. I understand heavy-weight jar will take time to load once even on my local machine, but I can manage them to be initiated only once (by creating a separate class and initiate static variables and use them from other classes). But seems like, this can't be done in Servlets and every time a page is loaded, servlet has to load all those heavy jars.

Is it good to use Guava and Solrj in Servlets ? Do they slow down (asking because I feel Solrj is slowing down webpage load time) ?

解决方案

Including a jar in-and-of itself does not slow down servlet run time. However, using a particular tool/class/functionality in a jar may slow down the servlet, depending on what you are trying to do.

I recommend using a profiler to analyze your code and actually determine what it causing the slowdown. Here's a quote from Martin Fowler's Refactoring:

I had speculated with various members of the team (Kent and Martin deny participating in the speculation) on what was likely wrong with code we knew very well. We had even sketched some designs for improvements without first measuring what was going on.

We were completely wrong. Aside from having a really interesting conversation, we were doing no good at all.

The lesson is: Even if you know exactly what is going on in your system, measure performance, don't speculate. You'll learn something, and nine times out of ten, it won't be that you were right!

这篇关于通过在servlet中使用外部jar来影响性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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