简体   繁体   English

如何提高Java项目的性能?

[英]How to improve java project performance?

I have more than 20M data in MongoDB and by using java driver I try to get data and plot chart by using JFreeChart. 我在MongoDB中拥有超过20M的数据,并且通过使用Java驱动程序,我尝试通过使用JFreeChart获取数据并绘制图表。

I have simple main class which reads data from MongoDb,creates dataset and plots chart.When I run the program in PC (3GB Ram,i5 processor) it performs very slowly.In 10 hours it only performs 200K data.Then I try to run the code in IBM server with 24 GB RAM but the performance is same. 我有一个简单的主类,它从MongoDb读取数据,创建数据集并绘制图表。当我在PC(3GB Ram,i5处理器)中运行程序时,它的运行速度非常慢。在10小时内,它只能执行200K数据。然后尝试运行具有24 GB RAM的IBM服务器中的代码,但性能相同。

This is the command that i run : 这是我运行的命令:

java -cp my-program.jar:external1.jar:external2:jar Graph java -cp my-program.jar:external1.jar:external2:jar图

Shouldn't it be fast on the server? 它在服务器上应该不快吗? How could I improve the performance? 如何提高性能?

I solved the problem.It is not related with the Java, the problem is caused by Jfreechart. 我解决了这个问题,它与Java无关,问题是由Jfreechart引起的。

I am sorting data on MongoDB and add data to the XYSeries in order to create dataset. 我在MongoDB上对数据进行排序,并将数据添加到XYSeries ,以便创建数据集。 XYSeries has autoSort field in the constructor and by default it is true. XYSeries在构造函数中具有autoSort字段,默认情况下为true。 That means when you add new item to the dataset it checks whether or not the items in the series are sorted. 这意味着,当您向数据集中添加新项目时,它会检查系列中的项目是否已排序。 By setting it false improves the performance. 通过设置为false可以提高性能。

XYSeries series = new XYSeries("followersCount",false);

Secondly, I setted the notify to false in the add method . 其次,我在add方法中将notify设置为false。 If it is not setted as false, then it sends notification to all registered listeners which reduces performance. 如果未将其设置为false,那么它将向所有注册的侦听器发送通知,这会降低性能。

series.add(1,2000,false);

It seems like you're at the deployment step. 似乎您正在部署步骤。 So, if you have a web application that will run on a server then you shouldn't just run the app. 因此,如果您有一个将在服务器上运行的Web应用程序,则不应仅运行该应用程序。 (.jar) A Web Applcation Archive (.war) should be created and installed to your container (Tomcat, Glassfish, Weblogic etc.). (.jar)应该创建一个Web应用程序存档(.war)并将其安装到您的容器(Tomcat,Glassfish,Weblogic等)中。 After doing these, if you still have performance issues then that points a problem about your code/logic. 完成这些操作后,如果仍然存在性能问题,那么这将指出有关代码/逻辑的问题。

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

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