如何改进与BasicDataSource对象一起使用的Java应用程序? [英] How to improve a Java application working with BasicDataSource object?

查看:166
本文介绍了如何改进与BasicDataSource对象一起使用的Java应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的服务器在工作中遇到问题,我正在尝试了解正在发生的事情.这是一个运行在linux服务器上的Java应用程序,该应用程序从TCP套接字接收信息并对其进行分析,并在分析后将其写入数据库.

We have an issue in our server at job and I'm trying to understand what is happening. It's a Java application that runs in a linux server, the application recieve inforamtion form TCP socket and analyse them and after analyse write into the database.

有时数据包的数量太多,Java应用程序每秒需要多次写入数据库(例如100到500次).

Sometimes the quantity of packets is too many and the Java application need to write many times into the database per second (like 100 to 500 times).

我尝试在自己的计算机上重现该问题,并查看该应用程序如何与JProfiler一起使用.

I try to reproduce the issue in my own computer and look how the application works with JProfiler.

内存看起来总是在上升,这是内存泄漏吗(对不起,我不是Java程序员,我是C ++程序员)?

The memory look always going up, is it a memory leak (sorry I'm not a Java programmer, i'm C++ programmer)?

133分钟后

158分钟后

我有很多锁定线程,这是否意味着应用程序未正确编程?

I have many locked thread, does it means that the application did not programmed correctly?

与数据库的连接是否过多(应用程序使用BasicDataSource类来使用连接池)?

Is it too many connection to the database (the application use BasicDataSource class to use a connection pool)?

该程序没有FIFO来管理数据库写操作,以获取从TCP端口输入的连续信息.我的问题是(请记住,我不是Java程序员,并且我不知道这是Java应用程序应该工作的方式,还是程序可以更有效地编程的方式)

The program don't have FIFO to manage database writing for continual information entering from TCP port. My questions are (remeber that I'm not a Java programmer and I don't know if this is way that a Java application should work or the program can be programmed more efficient)

  1. 您是否认为代码有问题,不能正确管理数据库的写入,读取,更新并占用过多的内存和CPU时间,或者这是它在BasicDataSource类中的工作方式吗?

  1. Do you think that something is wrong with the code that are not correctly managing write, read, updates on the database and cosume too many memory and CPU time, or is it the way that it works in BasicDataSource class?

您认为我如何通过创建FIFO并删除创建过多线程的代码部分来改善此问题(如果您认为这是一个问题)?还是这些线程不是应用程序线程本身,而是BasicDataSource线程?

How do you think I can improve it (if you think it's an issue) this issue, by creating a FIFO and removing the part of code that create too many threads? Or the threads is not the application threads himself and thats the BasicDataSource threads?

推荐答案

有几个方面需要深入研究,但是首先,我将尝试找出实际上阻止了所讨论线程的内容.我还将假设在查看该应用程序之前的所有情况,所以这是从应用程序开始的.

There are several areas to dig into, but first I would try and find what is actually blocking the threads in question. I'll assume everything before the app is being looked at as well, so this is from the app down.

我知道这些图显示了空闲内存,但是它们只是时间点,因此我看不到趋势.可以使用GC日志记录,尽管我没有使用JProfiler太多,所以我不确定如何在该工具中将其指向.我知道在DynaTrace中,我可以看到GC事件及其持续时间,以及任何其他阻塞事件及其根本原因.如果此功能不可用,则可以使用命令行开关来记录GC活动,以查看其持续时间和频率.那是一个可能会阻塞的区域.

I know the graphs show free memory but they are just point in time so I can't see a trend. GC logging is available, I haven't used JProfiler much though so I am not sure how to point you to it in that tool. I know in DynaTrace I can see GC events and their duration as well as any other blocking events and their root cause as well. If this isn't available there are command line switches to log GC activity to see its duration and frequency. That is one area that could block.

我还将查看您的池中有多少个连接.如果每秒有100-500个请求尝试写入,并且由于您没有足够的连接来处理它们而使它们堆积起来,那么这也可能是一个问题.该图像显示了所有交易,但没有说明池的大小.无处可去的交易阻塞也可能导致您的内存跳跃.

I would also look at how many connections you have in your pool. If there are 100-500 requests/second trying to write and they are stacking up because you don't have enough connections to work them then that could be a problem as well. The image shows all transactions but doesn't speak to the pool size. Transactions blocked with nowhere to go could lead to your memory jumps as well.

还有另一面,您的数据库无法处理流量并被钉住,这也是阻塞连接的原因,因此您需要监视事情的结束并查看是否可能是原因的封锁.

There is also the flip side that your database can't handle the traffic and is pegged, and that is what is blocking the connections as well so you would want to monitor that end of things and see if that is a possible cause of the blocking.

也有可能由于同时运行SQL,等待页面锁释放等而发生阻塞.

There is also the chance that the blocking is occurring from the SQL being run as well, waiting for page locks to be released, etc.

有很多地方要看,但是我将从应用程序开始逐步处理并验证一层.

Lots of areas to look at, but I would address and verify one layer at a time starting with the app and working down.

这篇关于如何改进与BasicDataSource对象一起使用的Java应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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