-
-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webp-server uses to much memory #198
Comments
🤔 Thanks for reporting, we need to dig more on to this issue, are you using version 0.7.0 on this? Before that you can try running it with |
So , how to continue improve the memory usage ? |
Could you please have a try adding In my testing case the RAM it used after benching using method from #200, has reduced to less than 100MiB after testing:
My docker-compose.yml example:
|
Yes, but it eat 1-2-3Gb. |
@Ingiboy OK, that seems better. BTW, you can use
Use with |
When i set deploy section with mem limit=512M, LA grows up to 30-40, CPU in wait state 60-80%. And using swap up to 2.5G. Without 'deploy' LA less 1, no swap. |
that is because docker engine will try to kill and then restart the container quiet often, so high load average. @n0vad3v can we consider adding back |
No, i see 'docker ps' - container uptime is more than 6h. I think memlimit is only limits RAM, and container eats swap) |
@Ingiboy
So using the
The container can use 200M of RAM and 200M of swap, can be confirmed by
In order to limit the swap usage, here is an working example(Note I've added MALLOC_ARENA_MAX in env):
In this case, the container can use no swap and only 200M of RAM, and will restart the container if ram runs above 200M. Example inspired by https://stackoverflow.com/questions/70095537/how-to-use-swap-memory-in-docker-compose, have to say the structure is wierd somehow, not sure why it is designed like that. Please have a try on this, BTW, a higher ram limit than 512MB is suggested. |
@n0vad3v, o, thanks! i try it |
Hmm, don't helps.
after some minuts LA grows up to 30-40, CPU in wa state about 80%. webp utilizes CPU more than 100% |
Seems weird, in the compose file content provided above, in my understanding with May I have some more info on your case:
|
|
All not good) I tried to put memory=1G and memswap_limit=1G || memswap_limit=0. If the memory usage is about gigabyte - LA about 40, CPU wa about 80% etc( |
🤔 Kinda weird as I still cannot reproduce your issue in my local env, when setting memory and memswap_limit, my container gets instantly killed when RAM exceeds that value, with some failed requests and almost no high CPU spikes. Have you tried maybe change a VPS provider or machine to have another test on similar scenario? |
May be it helps:
Unfortunately i can't change server, because it prod |
Generally, it doesn't matter exactly how docker is restarted. webp-server - great tool, many thanks) |
I'm experiencing a similar issue when to many requests hits the server: 4 vCPU, 8GB of RAM box:
I'm going to take a look to vips setup |
So using this fixed config for vips.Startup(&vips.Config{
- ConcurrencyLevel: runtime.NumCPU(),
+ ConcurrencyLevel: 1,
+ MaxCacheMem: 16 * 1024 * 1024,
+ MaxCacheSize: 16 * 1024 * 1024,
+ MaxCacheFiles: 128,
}) But this is just a workaround; I'd say the solution is to solve #75, I'm now evaluating the following go-routine pool implementations: |
Maybe we need to figure out how theses params affect the real performance, as in PR #200 I've done some tests and said:
With @BennyThink 's reply
I mean, if given the MaxCacheMem,MaxCacheSize,MaxCacheFiles above will have no performance impact to WebP Server, maybe we should just hard code it? (maybe leave some env for user to adjust them if they wish) |
I've done some benchmark on some photos (239 Photos, total 2.4GiB) using prefetch Normal configuration:
bugfest configuration:
However in prefetch we'll be default use all cores to convert so it might not be the best case to benchmark, but RES usage somehow shows that bugfest configuration seems does no harm on performance and by the way reduced RAM usage. |
Sorry @n0vad3v I didn't mentioned I use it in proxy mode with AVIF enabled. I think the issue is each new HTTP request spins a new go routine so the memory consumption skyrockets. Specially on first load; with no cached webp/avif images in disk. |
Also, I don't know if we should develop some parallel test in which we benchmark edge-cases here; like concurrent images converstion with the max size allowed by the image format (64k x 64k) |
Yes, me too use it in proxy mode, but without avif, only webp |
Yeah, and I've been thinking of creating a testing website for proxy mode testing, like generating 200+ images and host it on a website for testing, but I have no idea on image source(especially when dealing with license). |
what about if we generate completely random/noise images (https://github.com/mathisve/GoRandomNoiseImage) on the fly so that we can benchmark/measure the conversion when running in parallel? |
Nice catch, I've done some local testing and found that I saw some related discussion at: lovell/sharp#955 (comment) and libvips/libvips#1064 (comment). Currently I'm planning to add jemalloc and tcmalloc to Dockerfile, and allow user using ENV for switching between those. |
We've released 0.8.4 https://github.com/webp-sh/webp_server_go/releases/tag/0.8.4, this version allows user to choose malloc when using docker, more info can be found on https://docs.webp.sh/usage/docker/ |
In proxy mode on prod:
|
I saw in |
I've been doing a lot of reseach and extended testing (including go profiling). I still have issues with WEBP+AVIF in concurrent context with proxy mode. With +70 requests in paralell when I start without any local cache, the server has to convert all those images and what I think is happening is that we're not queuing requests to govips; so when those requests get to the server, I get a peak of +100 go-subrotines converting to both image types. This leads to a physical memory consumption spike and then triggers docker or the host system OOM killer. Current known workarounds:
I think it'd be worth it to create a priority queue to then limit how many jobs we're really sending to govips. That way we could add some more config parameters to control how many parallel jobs the host is able to handle and even allowing us to execute opportunistic convertion to AVIF when enough system resources ara available, etc. Any thoughs @n0vad3v, @BennyThink ? |
|
@bugfest I agree with the conversion queue plan, thus user can control how many convert can be triggered at one moment, you've mentioned
Maybe a simple way to limit this can be done by limiting total Go routines in program?(thus can automatically queue the latter requests) |
@BennyThink Increasing the value, in my case, makes the server to consume resources faster: #198 (comment)
@n0vad3v Nice! I'll share a proposal as soon as I get it working
It also has impact on the http server performance itself so I wouldn't go that way. |
Hi @n0vad3v, @BennyThink I've prepared que async implementation as per my last comment. Opened PR #226 |
With alpine+docker version 0.9.2 down every 3-5 mins with:
how fix it? thx error out: https://pastebin.com/BGhEBVq2 |
@Ingiboy Hmmm, that's weird, but thanks for reporting, we're investigating on this, probably something wrong with the code. In the mean time, could you please have a try on our official docker image to see if this issue will reproduce? Example usage can be found on https://docs.webp.sh/usage/docker/ |
@Ingiboy We think we've found the problem, please have a try on version 0.9.3 to see if it solves this problem. |
@n0vad3v 30 mins on air without errors, it looks like it works) |
since user can use jemalloc or tcmalloc to mitigate OOM issue, consider this as finished. |
At the first time , it uses 1GB memory . But after 7 hours , it grows to 6.7GB and continue to grow slowly.
The text was updated successfully, but these errors were encountered: