[英]GlassFish 4.1 Slow Localhost Servlet Response (NetBeans)
I have Netbeans 8.0.2 installed on Ubuntu 15.04 which includes the GlassFish 4.1 EE Container. 我在Ubuntu 15.04上安装了Netbeans 8.0.2,其中包括GlassFish 4.1 EE容器。
For some reason, after ensuring my resolv.conf
and hosts
files were set-up properly, accessing dynamic content, such as a servlet
that pulls data from a SQL database, is terribly slow. 由于某种原因,在确保正确设置了我的
resolv.conf
和hosts
文件之后,访问动态内容(例如从SQL数据库中提取数据的servlet
访问速度非常慢。
However, accessing static JSP pages returns in less than 1ms as it should. 但是,访问静态JSP页面将在不到1ms的时间内返回。
Pinging the server on 127.0.0.1 or localhost returns in 0.038ms or less, which is to be expected, so I don't think the DNS resolving issues common with Linux and localhost are to blame here. 在127.0.0.1或localhost上对服务器执行ping操作将在0.038ms或更短时间内返回,这是可以预期的,因此,我不认为Linux和localhost常见的DNS解析问题应归咎于此。
For kicks, I downloaded the GlassFish 4.1 server off their website and set-up NetBeans to deploy there, and I got the same results. 值得一提的是,我从他们的网站上下载了GlassFish 4.1服务器,并设置了NetBeans进行部署,得到了相同的结果。 In addition I also tried manually deploying my WAR files, and that also resulted in terribly slow response times from dynamic content / servlets.
另外,我还尝试手动部署WAR文件,这也导致动态内容/ Servlet的响应时间非常慢。
What gets me is that with the exact same set-up and configurations, I do not have this issues on Windows. 我得到的是,使用完全相同的设置和配置,我在Windows上没有此问题。
So in summary: 因此,总而言之:
I did look and see if it was my code. 我确实看了看是否是我的代码。 And no, it is not.
不,不是。 It runs perfectly fine on Windows and Windows Server.
它可以在Windows和Windows Server上完美运行。 It even runs fine when the server is on CentOS and pointing outwards, ie you would browse to a URL and not through the localhost.
当服务器位于CentOS上并指向外部时,它甚至可以正常运行,即您将浏览到URL,而不是通过本地主机。
To clarify, this problem occurs even on servlets that do not access any external resources, such as a servlet that only adds a few lines of HTML, or forwards the request to a static JSP page. 为了澄清,即使在不访问任何外部资源的servlet上也会发生此问题,例如仅添加几行HTML或将请求转发到静态JSP页面的servlet。
Well, 好,
After some extensive digging and profiling, I found the solution: 经过大量的挖掘和分析,我找到了解决方案:
I had a filter that would authenticate users, and set a cookie that changes for every request (prevents CSRF) but used a Java Utils SecureRandom
to inject a secure random bit of info into a MD5 hashing algorithm along with some other goodies to spit out a decently secure, one-time use cookie. 我有一个可以对用户进行身份验证的过滤器,并设置了一个针对每个请求而更改的cookie(防止CSRF),但使用了Java Utils
SecureRandom
将安全的随机信息注入MD5哈希算法中,以及其他一些东西,以吐出相当安全的一次性Cookie。
Apparently, the version of CentOS my production server is using already includes the haveged
daemon which keeps the /dev/random entropy topped up. 显然,我的生产服务器使用的CentOS版本已经包含了
haveged
守护进程,该守护进程使/ dev / random熵保持最高状态。
The issue is that SecureRandom
on Linux requests the /dev/random and is blocking. 问题是Linux上的
SecureRandom
请求/ dev / random并被阻止。 When there isn't enough entropy, it can wait up to 25 seconds before returning. 如果没有足够的熵,它最多可能需要等待25秒才能返回。
Solution was to of course: install the haveged
daemon. 解决方案当然是:安装
haveged
守护程序。 Problem solved. 问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.