为什么Java IO中默认缓冲区大小是8k?

发布于 2024-11-29 12:00:19 字数 67 浏览 0 评论 0原文

在其他地方的 BufferedWriter 中,默认缓冲区大小为 8k。为什么要用8k?更大的缓冲区大小是否会提高性能?

The default buffer size is 8k in BufferedWriter of somewhere else. Why use 8k? Does larger buffer size improve the performance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-12-06 12:00:19

缓冲区减少了写入系统调用的数量,从而优化了输出。根据程序的活动,更大的写入缓冲区可能会提高性能,最好使用更大的缓冲区和与程序的工作负载相当的工作负载进行测试。此外,当底层文件系统的缓存是直写式(无写缓存)时,缓冲区的重要性更高,因为后写式缓存无论如何都会延迟/分组物理写入操作。

我认为 8k 的历史原因与磁盘上的传统分配大小有关,通常是 2k 或其倍数。

The buffer reduces the number of write system calls and thereby optimizes the output. Depending on your program's activity a bigger write buffer may improve performance, it's always best to test with a bigger buffer with a workload comparable to what your program does. Also, the buffer's importance is higher when the underlying filesystem's cache is write-through (no write cache), because a write-behind cache will delay/group the physical write operations anyways.

I think the historical reason for the 8k is related to the traditional allocation sizes on disk, often 2k or a multiple thereof.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文