[英]Java web application really slow
I am using Rackspace as a hosting provider, using their Cloud server hosting, with 256mb plan. 我使用Rackspace作为托管服务提供商,并使用其256mb计划的Cloud服务器托管。
I am using Geronimo 2.2 to run my java application. 我正在使用Geronimo 2.2运行我的Java应用程序。
The server starts up no problem, loads Geronimo quite fast, however, when I started to deploy my web application, it is taking forever, and once it is deployed, it takes forever to navigate through pages. 服务器启动正常,加载Geronimo的速度非常快,但是,当我开始部署Web应用程序时,它会花费很多时间,而一旦部署它,就需要花费很多时间浏览页面。
I've been monitoring the server activity, the CPU is not so busy, however, 60% of the memory is being used up. 我一直在监视服务器的活动,CPU并不是很忙,但是60%的内存已用完。 Could this be the problem? 这可能是问题吗?
If so, what are my options? 如果是这样,我有什么选择? Should I consider upgrading this cloud server to something with more RAM, or changing a host provider to better suit my needs? 我应该考虑将此云服务器升级到具有更多RAM的设备,还是更改主机提供商以更好地满足我的需求?
Edit: I should note that, even if I don't deploy my application, just having Geronimo loaded, sometimes I would get a connection time when I try to shut down Geronimo. 编辑:我应该注意,即使我不部署我的应用程序,只是加载了Geronimo,有时当我尝试关闭Geronimo时我也会得到一个连接时间。
Also the database is on the same server as the application. 此外,数据库与应用程序位于同一服务器上。 (however I wouldn't say its query intensive) (但是我不会说它查询密集)
Update : 更新 :
After what @matiu suggested, I tried running free -m, and this is the output that I get: 在@matiu建议之后,我尝试运行free -m,这是我得到的输出:
total used free shared buffers cached
Mem: 239 232 6 0 0 2
-/+ buffers/cache: 229 9
Swap: 509 403 106
This was totally different result than running ps ux , which is how I got my previous 60%. 这与运行ps ux完全不同,这就是我之前获得60%的结果。
And I did an iostat check, and about 25% iowait time, and device is constantly writing and reading. 我进行了iostat检查,大约有25%的iowait时间,并且设备一直在读写。
I'm guessing you're running into 'swapping'. 我猜您正在遇到“交换”。
As you'll know Linux swaps out some memory to disk. 如您所知,Linux会将一些内存换成磁盘。 This is great for memory that's not accessed very much. 这对于不太需要访问的内存非常有用。
When Java starts eating heaps and heaps, linux starts: 当Java开始吃堆时,Linux启动:
As disk is 1000s of times slower than RAM, as the memory usage increases your machine grinds more and more closer to a halt. 由于磁盘的速度比RAM慢1000倍,因此随着内存使用量的增加,您的计算机变得越来越停顿。
With 256 MB Cloud Servers you get 512 MB of Swap space. 使用256 MB的云服务器,您可以获得512 MB的交换空间。
Checking: 检查:
You can check if this is the case with free -m
.. this page shows how to read the output: 您可以使用free -m
检查这种情况。 此页面显示了如何读取输出:
Next I'd check with 'iostat 5' to see what the disk IO rate on the swap partition is. 接下来,我将使用“ iostat 5”进行检查,以查看交换分区上的磁盘IO速率是多少。 I would say a write rate of 300 or more means you're almost dead in the water. 我想说300或更高的写入率意味着您几乎要死在水里了。 I'd say you'd want to keep the write rate of the swap partition down below 50 blocks a second and the read rate down below 500 blocks a second .. if possible both should be zero most of the time. 我要说的是,您希望将交换分区的写入速率降低到每秒50块以下,将读取速率降低到每秒500块以下..如果可能的话,大多数时候两者都应为零。 Remember disk is 1000s of times slower than RAM. 请记住,磁盘要比RAM慢1000倍。
You can check if it's Java eating the ram by running top
and hitting shift+m
to order the processes by memory consumption. 您可以通过运行top
并按shift+m
来按内存消耗对进程进行排序来检查Java是否在吃掉内存。
If you want .. you can disable the swap partition with swapoff -a
.. then open up the web console, and hit the site a bit .. you'll soon see error messages in the console like 'OOM Killed process xxx' (OOM is for Out of Memory I think). 如果您想要..您可以使用swapoff -a
..禁用交换分区,然后打开Web控制台,并稍稍访问该站点..您很快就会在控制台中看到错误消息,例如“ OOM Killed process xxx”(OOM已杀死进程xxx)( OOM是为内存不足而设计的)。 If you see those that's linux trying to satisfy memory requests by killing processes. 如果您看到那些Linux试图通过杀死进程来满足内存请求。 Once that happens, it's best to hard reboot. 一旦发生这种情况,最好进行硬重启。
Fixing: 定影:
If it's Java using the RAM .. this link might help. 如果是使用RAM的Java,则此链接可能会有所帮助。
I think the easy fix would be just to upgrade the size of the Cloud Server. 我认为简单的解决方法只是升级Cloud Server的大小。
You may find a different Java RTE may be better. 您可能会发现不同的Java RTE可能更好。
If you run it in a 32 bit chroot it may use less RAM. 如果在32位chroot中运行它,则可能会使用更少的RAM。
You should consider running a virtual dedicated Linux server, from something like linode. 您应该考虑从诸如linode之类的设备运行虚拟专用Linux服务器。 You'd have to worry about how to start a Java service and things like firewalls, etc, but once you get it right, you are in effect you're own hosting provider, allowing you to do anything a standalone actual Linux box can do. 您将不得不担心如何启动Java服务以及诸如防火墙之类的事情,但是一旦正确使用,您实际上就是您自己的托管服务提供商,允许您执行独立的实际Linux机器可以做的任何事情。
As for memory, I wouldn't upgrade until you have evidence that you do not have enough. 至于内存,在您没有足够的证据之前,我不会升级。 60% being used up is less than 100% used up... 60%的用完少于100%的用完...
Java normally assumes that it can take whatever it is assigned to it. Java通常假定它可以接受分配给它的任何内容。 Meaning, if you give it a max of 200MB, it thins that it's ok to take 200MB even though it's using much less. 意思是,如果您为其提供最大200MB的内存,那么即使它使用更少的内存,它也可以占用200MB的内存。 There is a way to make Java use less memory, by using the -Xincgc incremental garbage collector. 通过使用-Xincgc增量垃圾收集器,可以使Java使用更少的内存。 It actually ends up giving chunks of memory back to the system when it no longer needs it. 实际上,它最终在不再需要内存时将其提供给系统。 This is a bit of a kept secret really. 这确实是个秘密。 You won't see anyone point this out... 您不会看到有人指出这一点...
Based on my experience, memory and CPU load on VPSes are quite related. 根据我的经验,VPS上的内存和CPU负载是非常相关的。 Meaning, when application server will take up all available memory, CPU usage starts to sky rock, finally making application inaccessible. 这意味着,当应用程序服务器将占用所有可用内存时,CPU使用率开始飞速上涨,最终使应用程序无法访问。
This is just a side effect though - you should really need to investigate where your problems origin! 不过,这只是一个副作用-您确实需要调查问题的出处!
If the memory consumption is very high, then you can have multiple causes: 如果内存消耗很高,则可能有多种原因:
If you are interested in CPU usage: 如果您对CPU使用率感兴趣:
As you can see, it's not trivial task, but you have tools support which will can help you out. 如您所见,这并不是一件容易的事,但是您拥有可以帮助您的工具支持。 I personally use java melody and probe . 我个人使用Java melody和probe 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.