yt-dlp/yt_dlp
Jody Bruchon a9ac178eb1 Use 64 KiB buffered writes for performance and less fragmentation
I use yt-dlp on Windows writing to a Linux system via SMB over a
10GbE connection and downloading via 400 Mbps cable internet. I
have observed that downloads often seem to start very fast (40+
MiB/sec) but then throttle down to 8-20 MiB/sec. I also observed
a large amount of disk thrashing for such a large array and small
amount of data that's supposedly being written sequentially.

The problem is two-fold. Downloaded fragments are stored using a
very short-lived *-FragX file, then immediately appended to the
stream upon fragment completion, and deleted. Both operations use
small write buffers. When the OS write buffers start to flush, the
two sets of writes plus the large number of writes start to force
competition to complete the queued writes in different areas of
the volume.

Python defaults to sending writes at the underlying device's
"block size" or a fallback to io.DEFAULT_BUFFER_SIZE. In practical
terms, this means a write buffer of 4096 or 8192 bytes. This
commit increases most write buffers to 65536 (64 KiB) using the
open() buffering=X option, significantly speeding up writes of
larger chunks of data and reducing potential fragmentation in low
disk space conditions. With these changes, I consistently see fast
downloads and the array thrashing is noticeably lessened.
2024-12-19 11:36:00 -05:00
..
__pyinstaller [rh:curlcffi] Add support for curl_cffi 2024-03-16 23:15:11 -05:00
compat [cleanup] Deprecate more compat functions (#11439) 2024-11-17 00:24:11 +01:00
dependencies [core] Catch broken Cryptodome installations (#11486) 2024-11-10 00:53:49 +01:00
downloader [cleanup] Bump ruff to 0.8.x (#11608) 2024-12-02 16:29:30 +01:00
extractor Use 64 KiB buffered writes for performance and less fragmentation 2024-12-19 11:36:00 -05:00
networking [cleanup] Misc (#10807) 2024-09-27 22:46:22 +00:00
postprocessor [cleanup] Bump ruff to 0.8.x (#11608) 2024-12-02 16:29:30 +01:00
utils Use 64 KiB buffered writes for performance and less fragmentation 2024-12-19 11:36:00 -05:00
__init__.py [cleanup] Bump ruff to 0.8.x (#11608) 2024-12-02 16:29:30 +01:00
__main__.py [docs] Misc Cleanup (#8977) 2024-03-11 00:48:47 +05:30
aes.py [cleanup] Bump ruff to 0.8.x (#11608) 2024-12-02 16:29:30 +01:00
cache.py [cleanup] Add more ruff rules (#10149) 2024-06-12 01:09:58 +02:00
cookies.py [cookies] Add --cookies-from-browser support for MS Store Firefox (#11731) 2024-12-04 18:41:58 +01:00
jsinterp.py [jsinterp] Improve slice implementation (#10664) 2024-08-05 20:28:24 +00:00
minicurses.py [docs] Consistent use of e.g. (#4643) 2022-08-14 17:34:13 +05:30
options.py [cleanup] Misc (#11554) 2024-11-17 23:25:05 +00:00
plugins.py [cleanup] Bump ruff to 0.8.x (#11608) 2024-12-02 16:29:30 +01:00
socks.py [cleanup] Add more ruff rules (#10149) 2024-06-12 01:09:58 +02:00
update.py [update] Check 64-bitness when upgrading ARM builds (#11819) 2024-12-15 19:55:30 +00:00
version.py Release 2024.12.13 2024-12-13 10:35:40 +00:00
webvtt.py [cleanup] Add more ruff rules (#10149) 2024-06-12 01:09:58 +02:00
YoutubeDL.py Use 64 KiB buffered writes for performance and less fragmentation 2024-12-19 11:36:00 -05:00