问题描述
使用unix上的log4j,哪个appender会执行最好的编写1000meg:
1)使用rollingfileappender编写10个文件100 meg
或
2)使用fileappender并编写单个1000meg文件
换句话说,使用unix上的java,尺寸很重要吗?
谢谢
推荐答案
在写入小文件或写入大文件之间没有Java侧性能差异.当文件变得足够大以至于需要额外的索引块(FS依赖)时,可能会在操作系统上有 小的差异,但可能不值得担心.
实施文件滚动行为将有绩效成本.附录必须:
- 测试/记住文件有多大,
- 关闭当前一个,
- 重命名,
- 打开一个新文件.
我的直觉是,这不太可能很重要. (但是,值得测量看看表现是否应该引起关注.此外,您可能应该问自己,您是否没有做 登录过多.)
您必须将上述所有内容与文件滚动的优势进行比较:
- 在日志文件上具有有限的大小,这意味着您的记录不会填充磁盘,因此对应用程序和其他机器上的其他磁盘有问题.
- 较小的日志文件可以使在特定时间进行搜索更容易/更快地搜索事件. (在1000MB文件上运行less可能很痛苦...)
其他推荐答案
他们都可以轻松地编写1000MB文件.我不明白为什么他们应该表现不同.
您确实需要RollingFileAppender,尽管为了设置日志文件可以达到的总最大尺寸.否则,假设您的应用程序有流量,则可能会用尽硬盘空间.
其他推荐答案
我认为,比大文件更可取,因为它们更易于管理.另外,考虑到大型文件,您可能会在文件系统填充的情况下遇到问题,因为当进程启动并运行以释放磁盘空间时必须删除日志文件.
问题描述
Using log4j on Unix, which Appender would perform the best to write 1000Meg :
1) Using RollingFileAppender writing 10 file of 100 Meg
or
2) Using a FileAppender and writing a single 1000Meg file
In other words, using java on unix, does the size matter?
Thank you
推荐答案
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:
- test / remember how big the file is,
- close the current one,
- rename it,
- open a new file.
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:
- 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 ...)
其他推荐答案
They'll both easily write 1000MB files. I don't see why they should perform differently.
You do need the RollingFileAppender though in order to set the total maximum size that the log file(s) can reach. Otherwise you may run out of hard disk space, assuming that you application has got traffic.
其他推荐答案
I think it's always preferable to use small files than large files because they are more manageable. Also, consider that with large files you may have problems in the case of file-system full because of the risk of having to remove the log file when the process is up and running to free up disk space.