Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

High memory usage with docker #1473

Open
Uatschitchun opened this issue Jan 17, 2020 · 17 comments
Open

High memory usage with docker #1473

Uatschitchun opened this issue Jan 17, 2020 · 17 comments
Labels
in: docker Issues in the test module. status: waiting-for-feedback The replication have not been confirmed yet. Or no implementer or no PRs or tips to solve yet. type: question A general question.

Comments

@Uatschitchun
Copy link

Uatschitchun commented Jan 17, 2020

I'm running airsonic/airsonic docker with the following docker-compose.yml:

version: '2'

services:
  airsonic:
    image: airsonic/airsonic
    container_name: airsonic
    restart: always
    ports:
      - 4040:4040
    expose:
      - 4040
    networks:
      - web
      - default
    volumes:
      - /home/user/docker/airsonic/data/:/airsonic/data
      - /media/mp3/:/airsonic/music
      - /media/mp3/playlists:/airsonic/playlists
    environment:
      - TZ=Europe/Berlin
      - JAVA_OPTS=-Dserver.use-forward-headers=true
      - JAVA_OPTS=-Xmx1536m
    labels:
      - "traefik.enable=true"
      - "traefik.backend=airsonic"
      - "traefik.frontend.rule=Host:airsonic.somename.somedomain.org"
      - "traefik.port=4040"
      - "traefik.docker.network=web"
      - "traefik.protocol=http"
      - "traefik.frontend.passHostHeader=true"
      - "traefik.frontend.headers.SSLRedirect=true"
      - "traefik.frontend.headers.STSSeconds=315360000"
      - "traefik.frontend.headers.browserXSSFilter=true"
      - "traefik.frontend.headers.contentTypeNosniff=true"
      - "traefik.frontend.headers.forceSTSHeader=true"
      - "traefik.frontend.headers.SSLHost=somename.somedomain.org"
      - "traefik.frontend.headers.STSIncludeSubdomains=true"
      - "traefik.frontend.headers.STSPreload=true"
      - "traefik.frontend.headers.frameDeny=true"
      - "traefik.frontend.headers.customFrameOptionsValue=SAMEORIGIN"

networks:
  web:
    external: true

So far, so good.

Problem is, it's using up over 1GB of memory!

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
9dc6c6acc860        airsonic            0.09%               1.131GiB / 7.674GiB   14.75%              183MB / 237MB       5.38GB / 1.08GB     63

Even on another system with only 1 album as media-source, it's up to 400MB.

Is there anything I can do to reduce the memory usage?

@tesshucom
Copy link
Contributor

Because -Xmx1536m is specified(Maximum size of memory allocation pool), you could try a slightly smaller value.

Configure Airsonic running standalone

It is written in Java memory allocation.

@Uatschitchun
Copy link
Author

Uatschitchun commented Jan 19, 2020

I tried smaller values, but airsonic crashes.
The question is, what airsonic is using that much memory for?

@tesshucom
Copy link
Contributor

Probably, answering that question is not easy for everyone.

We recommend that you describe your environment according to the issues template, especially if your question is highly environment-dependent.
This is necessary to make comparisons with others.
Also, if environmental information is provided, users from similar environments may be able to provide advice.

Apart from Docker configuration, it is also effective to try it out from a stand-alone.
To make it easier to investigate the cause.

@Uatschitchun
Copy link
Author

It's just an airsonic/airsonic:latest docker running on an Ubuntu (18.04) server. Nothing special about it but configuration against traefik as reverse proxy. DB is the standard setting.
It's only serving music (99% mp3 and a few flac). The library is quite huge (800GB).
So what I'm wondering about is the fact, why airsonic is that hungry on memory? It's a server and I see no reason for that huge memory usage when airsonic even isn't serving anything to anyone, just idling around!?

I set the Java memory value in the beginning as airsonic failed with its standard setting of 256MB.

I can surely provide a log of just running with standards... but the memory usage should be explainable from a design point of view, shouldn't it?

@fxthomas
Copy link
Contributor

fxthomas commented Jan 23, 2020

I tried smaller values, but airsonic crashes.

Does it crash when scanning or at first startup?

I'm going to pull numbers from my head here : 800GB / 10MB per MP3 song is approx. 80k songs, times a guess of 2k per row in the MEDIA_FILE table (the biggest one) yields about 160MB, not counting indexes or other tables. So you've got at least, say, 400-500MB just for data? For me an empty Airsonic uses about 500-600M RSS, so your current memory usage seems about right.

Yup, this could probably be optimized in some way.

@tesshucom
Copy link
Contributor

Java memory usage is not simple, so you need a profiler tool.

It seems that 512m is exemplified in Docoment.
You can use space separators.

JAVA_OPTS=-Dserver.use-forward-headers=true -Xmx512m

If it does n’t work very well ...
You may be able to easily set a limit on Docker and check...?

@Uatschitchun
Copy link
Author

Thx for the calculations ;)

Why does airsonic needs to keep data in memory?

@fxthomas
Copy link
Contributor

I don't have a definite idea, only hunches in this case.

I haven't been able to test it on a very large library like yours yet, but I wonder if switching to CACHED tables for the internal db could help. Not at home this week so I can't create a test build, but I will try to do that when I get back.

@fxthomas
Copy link
Contributor

fxthomas commented Feb 4, 2020

Can you try this build here: https://github.com/fxthomas/airsonic/releases/tag/10.6-snapshot-hsqldb-2.5 and let me know what happens?

It's better if you create a new Airsonic instance for this, as this will render your database unusable on previous versions.

@Uatschitchun
Copy link
Author

I'll see to find time to test!

@Uatschitchun
Copy link
Author

Hm, I'm used to run airsonic with docker... 🤔
Have to build my own image, I guess...

@fxthomas
Copy link
Contributor

fxthomas commented Feb 8, 2020

Ah, yes, sorry, I don't use Docker that much during development... Let me know if you're having trouble modifying the base image!

@fxthomas fxthomas added in: UNKNOWN-backend The problem location has not been identified yet. in: docker Issues in the test module. status: waiting-for-feedback The replication have not been confirmed yet. Or no implementer or no PRs or tips to solve yet. labels Apr 19, 2020
@tesshucom tesshucom added in: docker Issues in the test module. type: question A general question. and removed in: docker Issues in the test module. in: UNKNOWN-backend The problem location has not been identified yet. labels May 8, 2020
@lbesnard
Copy link

lbesnard commented May 9, 2020

my docker version used 1.5 Gb of ram. Before I moved to docker it was quite similar. It feels like it's correlated with the size of the library imo.

@cairobraga
Copy link

cairobraga commented Jul 29, 2020

I just did a clean install of airsonic standalone (Win7, Java 1.8), there's nothing on my library yet, I simply ran it for the first time, setup admin password, shut it down and started it again: 1.05GB of memory usage. it's even using more while idle than my Chromium with 5 tabs open. why?

@tesshucom
Copy link
Contributor

@lbesnard @cairobraga
"Tried on standalone Airsonic without Docker" Is this correct? The conditions look a bit vague. The Airsonic does have some memory leak issues that need to be handled carefully to resolve them.

"airsonic-advanced" is a subproject with a name that includes the original product name, which is prohibited in many projects. Please refrain from introducing the issues at Airsonic, as it is a completely separate project that may involve experimentation and risk. The bugs in "airsonic-advanced" may originate from Airsonic, but they may not. Especially for scanning, verification should be done as a completely different thing.

@cairobraga
Copy link

@tesshucom this was a newbie mistake, it was not my intention that the issue I opened there would end up here because I used a link to here as an example. I'm sorry and it won't happen again.

@tesshucom
Copy link
Contributor

OK, don’t take it seriously.
There are countless causes of memory overflow, and proper observation is needed. To be honest, the issues report has little environmental information, which makes it difficult to deal with. Please respect the template in question. Information about the CPU architecture and model name may also be useful.

At least what you can say is that Java 11 or later should be used if you want to perform validation with Docker. We should use post Java 10 to support Docker's memory configuration lookups, but it's better to use Java 11 from LTS. Simply put, the old JVM does not have proper control because it refers to the memory configuration of the host machine, not Docker. (As a result, there are cases where problems occur depending on the environment and cases where problems do not occur. It will depend on how many services are running concurrently on your machine.)
Parallel scanning is a different matter. There are some issues that need to be resolved in advance. And thread control must be implemented J2EE compliant. In the worst case, container threads will easily be exhausted. If can't see it, it's too early now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in: docker Issues in the test module. status: waiting-for-feedback The replication have not been confirmed yet. Or no implementer or no PRs or tips to solve yet. type: question A general question.
Projects
None yet
Development

No branches or pull requests

5 participants