本文介绍了Java日志记录:多个小文件与一个大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Unix上的log4j,Appender会最好地编写1000Meg:

Using log4j on Unix, which Appender would perform the best to write 1000Meg :

1)使用RollingFileAppender写入100 Meg的10个文件

1) Using RollingFileAppender writing 10 file of 100 Meg

2)使用FileAppender并写入单个1000Meg文件

2) Using a FileAppender and writing a single 1000Meg file

换句话说,在unix上使用java,大小重要吗?

In other words, using java on unix, does the size matter?

谢谢

推荐答案

在写入小文件或写入大文件之间,Java端的性能没有区别.当文件足够大以至于需要额外级别的索引块(取决于FS)时,在OS级别上可能有差异,但这可能不值得担心.

There no Java-side performance difference between writing to a small file or writing to a large file. There might be a small difference at the OS level when a file gets big enough that an extra level of index blocks is required (FS dependent), but it is probably not worth worrying about.

实施文件滚动行为会降低性能.附加程序必须:

There will be a performance cost in implementing the file rolling behavior. The appender has to:

  • 测试/记住文件的大小
  • 关闭当前的
  • 重命名,
  • 打开一个新文件.

我的直觉是这不太可能. (但是,值得考虑的是测量,看看性能影响是否值得关注.此外,您可能应该问自己是否没有做过多的日志记录.)

My gut feeling is that this is not likely to be significant. (However, it would be worth measuring to see if the performance impact should be a concern. Also, you should probably ask yourself if you are not doing too much logging.)

您必须将以上所有内容与文件滚动的优点进行比较:

You have to compare all of the above against the advantages of file rolling:

  • 日志文件大小有限,这意味着您的日志记录不会填满磁盘,从而导致应用程序以及同一台计算机上的其他应用程序出现问题.
  • 较小的日志文件可使在特定时间搜索事件更加容易/快捷. (在1000Mb的文件上运行less可能会很痛苦...)
  • Having a bounded size on log files means that your logging won't fill the disk, causing problems for the application and potentially others on the same machine.
  • Smaller log files can make it easier / quicker to do searches for events at specific times. (Running less on a 1000Mb file can be painful ...)

这篇关于Java日志记录:多个小文件与一个大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:47