Java - System.out对性能的影响 [英] Java - System.out effect on performance

查看:370
本文介绍了Java - System.out对性能的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过这个问题,这有点儿类似。我想知道它是否真的是影响我的应用程序性能的一个重要因素。这是我的方案。



我有这个Java webapp可以从电子表格上传数千个数据,每个行从上到下读取。我正在使用 System.out.println()在服务器端显示应用程序当前正在读取的行。



- 我知道创建一个日志文件。实际上,我正在创建一个日志文件,同时在服务器的提示符下显示日志。

是否还有其他方法可以在提示符下打印当前数据?

I've seen this question and it's somewhat similar. I would like to know if it really is a big factor that would affect the performance of my application. Here's my scenario.

I have this Java webapp that can upload thousands of data from a Spreadsheet which is being read per row from top to bottom. I'm using System.out.println() to show on the server's side on what line the application is currently reading.

- I'm aware of creating a log file. In fact, I'm creating a log file and at the same time, displaying the logs on the server's prompt.
Is there any other way of printing the current data on the prompt?

推荐答案

它可能会对您的应用程序性能产生影响。幅度将根据您运行的硬件类型和主机上的负载而变化。

It can have an impact on your application performance. The magnitude will vary depending on the kind of hardware you are running on and the load on the host.

这可以转化为性能的一些点:

Some points on which this can translate to performance wise:

- >像Rocket boy所述,println是同步的,这意味着你将在对象头上产生锁定开销,并可能导致线程瓶颈,具体取决于你的设计。

-> Like Rocket boy stated, println is synchronized, which means you will be incurring in locking overhead on the object header and may cause thread bottlenecks depending on your design.

- >在控制台上打印需要内核时间,内核时间意味着cpu不会在用户模式下运行,这基本上意味着你的cpu将忙于执行内核代码而不是你的应用程序代码。

-> Printing on the console requires kernel time, kernel time means the cpu will not be running on user mode which basically means your cpu will be busy executing on kernel code instead of your application code.

- >如果您已经记录了这个,那意味着I / O需要额外的内核时间,如果您的平台不支持异步I / O,这意味着您的cpu可能会在忙碌的等待中停滞不前。

-> If you are already logging this, that means extra kernel time for I/O, and if your platform does not support asynchronous I/O this means your cpu might become stalled on busy waits.

您可以尝试对此进行基准测试并自行验证。

You can actually try and benchmark this and verify this yourself.

有很多方法可以解决这个问题,比如拥有一个非常快的I / O,一台专用的巨大机器,如果你的应用程序有偏向锁定你的JVM选项在控制台打印中,设计不会是多线程的。

There are ways to getaway with this like for example having a really fast I/O, a huge machine for dedicated use maybe and biased locking on your JVM options if your application design will not be multithreaded on that console printing.

与性能上的所有内容一样,这一切都取决于您的硬件和优先级。

Like everything on performance, it all depends on your hardware and priorities.

这篇关于Java - System.out对性能的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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