From: Marcel van der Veldt Date: Sat, 25 Oct 2025 20:16:33 +0000 (+0200) Subject: Enable buffering by default on beefy hardware X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=b4c4438cc448e5e0ffbd1def31e852710126f21d;p=music-assistant-server.git Enable buffering by default on beefy hardware --- diff --git a/music_assistant/controllers/streams.py b/music_assistant/controllers/streams.py index 9ade5ea5..5774005e 100644 --- a/music_assistant/controllers/streams.py +++ b/music_assistant/controllers/streams.py @@ -74,7 +74,7 @@ from music_assistant.helpers.smart_fades import ( SmartFadesMixer, SmartFadesMode, ) -from music_assistant.helpers.util import get_ip_addresses, select_free_port +from music_assistant.helpers.util import get_ip_addresses, get_total_system_memory, select_free_port from music_assistant.helpers.webserver import Webserver from music_assistant.models.core_controller import CoreController from music_assistant.models.music_provider import MusicProvider @@ -95,6 +95,9 @@ isfile = wrap(os.path.isfile) CONF_ALLOW_BUFFER: Final[str] = "allow_buffering" CONF_ALLOW_CROSSFADE_SAME_ALBUM: Final[str] = "allow_crossfade_same_album" +# Calculate total system memory once at module load time +TOTAL_SYSTEM_MEMORY_GB: Final[float] = get_total_system_memory() + def parse_pcm_info(content_type: str) -> tuple[int, int, int]: """Parse PCM info from a codec/content_type string.""" @@ -181,7 +184,7 @@ class StreamsController(CoreController): ConfigEntry( key=CONF_ALLOW_BUFFER, type=ConfigEntryType.BOOLEAN, - default_value=False, + default_value=TOTAL_SYSTEM_MEMORY_GB >= 8.0, label="Allow (in-memory) buffering of (track) audio", description="By default, Music Assistant tries to be as resource " "efficient as possible when streaming audio, especially considering " diff --git a/music_assistant/helpers/util.py b/music_assistant/helpers/util.py index 212fe78e..1b0f4d65 100644 --- a/music_assistant/helpers/util.py +++ b/music_assistant/helpers/util.py @@ -50,6 +50,18 @@ T = TypeVar("T") CALLBACK_TYPE = Callable[[], None] +def get_total_system_memory() -> float: + """Get total system memory in GB.""" + try: + # Works on Linux and macOS + total_memory_bytes = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES") + return total_memory_bytes / (1024**3) # Convert to GB + except (AttributeError, ValueError): + # Fallback if sysconf is not available (e.g., Windows) + # Return a conservative default to disable buffering by default + return 0.0 + + keyword_pattern = re.compile("title=|artist=") title_pattern = re.compile(r"title=\"(?P.*?)\"") artist_pattern = re.compile(r"artist=\"(?P<artist>.*?)\"")