Java:通过将应用程序升级为 Web 服务来测量应用程序的性能
我有一个在某种程度上充当服务器的应用程序。我有一些消费者(另一个应用程序)将任务发送到“服务器”应用程序并获得结果。该应用程序是用 Java 实现的控制台应用程序。问题是我需要测量应用程序的性能(CPU、内存、吞吐量(如果可能)以及我可以获得的其他任何内容)。如果我将“服务器”保留为控制台应用程序,则会遇到应用程序级别测量的问题,这可能非常困难。我的想法是将控制台应用程序“升级”为 Web 服务,即创建某种包装器,以便能够将“服务器”作为 Web 应用程序调用。我想那时监控部分会容易得多。
我想听听你对此的想法。这是个好主意吗?如果将其升级为 Web 服务,是否可以获得更好的结果?我该怎么做呢?此时我只想得到一些结果,代码可能很脏。应用程序最初被想象为一个 Web 服务(或类似的东西),控制台应用程序只是一个模拟,因此创建一个 Web 服务而不是控制台应用程序并不是一件可怕的事情。
I have an application that's behaving as a server in a way. I have some consumers (another application) which send tasks to the "server" application and get something as a result. The application is implemented in Java as a console application. The problem is that I need to measure the performance of the application (CPU, memory, throughput if possible and anything else I could get). If I keep my "server" as a console application, I get a problem of application level measuring, which can be extremely hard. My idea was to "upgrade" the console application to a web service, i.e., to create some kind of a wrapper so to be able to call the "server" as a web application. I guess that the monitoring part would be much easier then.
I'd like to hear your thoughts about it. Is that a good idea? Can I get better results if I upgrade it to a web service? And how do I even do that? At this point I just want to get some results, the code can be dirty. The application is originally imagined as a web service (or something similar), the console application is just a simulation, so creating a web service instead of a console application is not a terrible thing to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您可以使用 JMX 协议和 JConsole 连接到您的应用程序。使用 JConsole,您将获得有关内存使用情况、CPU 使用情况、线程等的详细信息。它还允许您通过 MBean 动态控制应用程序。
看一下: http://download.oracle .com/javase/1.5.0/docs/guide/management/jconsole.html
Maybe you can use JMX protocol and JConsole to connect to your application. With JConsole you will have detailed information about memory usage, CPU usage, threads etc. It will also allow you to control your application on the fly by means of MBean.
Take a look at: http://download.oracle.com/javase/1.5.0/docs/guide/management/jconsole.html
是的,让您的应用程序成为 Web 服务是个好主意。它将使您的应用程序安全且开箱即可扩展。
您可以自行选择要应用的网络服务。我建议您使用 RestFul Web 服务 (JAX-RS)。您可以使用 sl4j 记录有关内存和 CPU 使用情况的所有信息。
Yes its a good idea to make your application a Web Service. It will make your application secure and scalable out of the box.
You can chose yourself that which web service you want to apply. I would suggest you to go for RestFul web service (JAX-RS). And you can use sl4j for logging all the information about the mem and cpu usage.