rembg icon indicating copy to clipboard operation
rembg copied to clipboard

Performance: Docker vs Library

Open echtme opened this issue 3 years ago • 3 comments

Hi there. I'm running the rembg Dockerfile image (2.xx GB) on Google Cloud Run, which works pretty good. However, I've created a custom Docker image with Python-slim (0.5GB) to keep it ligther and used the rmbg library + Flask, with the same settings on Cloud Run, but surprisingly the larger rembg Docker Container is still much faster. How is this possible?

Also, is there a way to define the model when using the rembg library?

I'm looking for ways to speed up the process and a lighter image to improve server cold starts.

echtme avatar Nov 04 '22 06:11 echtme

Hi @echtme, do you try to move large files outside of the container? The .u2net folder is large than 0.5GB.

My repo costs more than 30s for cold start on Google Cloud Run.

BTW, I haven't tried moving large files out of the container. And PORT error when using rembg image on Google Cloud Run.

AlfredUFY avatar Nov 05 '22 07:11 AlfredUFY

I'm only using the one generic u2net model, which is a little less than 200mb if I remember correctly. But I would prefer to have it as part of the image rather than downloading every time when the container start up.

Regarding the cold starts, you can run a minimum instance, or setup a cron job and ping it every few minutes. Which is much much cheaper and the same at the end.

echtme avatar Nov 05 '22 08:11 echtme

Regarding the port error, make sure that the flask/fast api and Dockerfile ports are matching. I had another instance where I got some dependencies errors while compiling the Docker, and Google was giving me a port error message at the end. Doesn't makes sense, but when I've fixed the dependencies issue, it was working.

echtme avatar Nov 05 '22 08:11 echtme

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Dec 06 '22 02:12 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Dec 21 '22 01:12 github-actions[bot]

Hi @echtme ,

Can you briefly explain how you managed to get the Dockerfile image (2.xx GB) to play nicely on Google Cloud Run? Like @AlfredUFY , I too have that same port error despite doing very basic pulling of image (docker pull danielgatis/rembg), tagging and pushing to google container registry then creating service with rembg's default "5000" port. I don't see any dependency issues in log (I only pull the image not compile it), just the port issue. Any help is appreciated.

Riz0 avatar Jan 25 '23 11:01 Riz0

You have to adjust also the port in the Google Cloud console to 5000

echtme avatar Jan 26 '23 07:01 echtme

You have to adjust also the port in the Google Cloud console to 5000

@echtme Thanks for the reply as I've been really struggling with this. Can you please tell me how to actually adjust the port so it allows the image to start effectively? Here is where I edited in the port when I initially created the service on Google Cloud run:

AwUJ9Ga

Here is what my current log looks like:

2upU3VT

I was initially thinking it was a firewall issue as well, but apparently cloud run doesn’t really have firewall to adjust with like compute engine does so not sure how to change port settings otherwise from console. Thanks again for any help, I really appreciate it!

Riz0 avatar Jan 26 '23 08:01 Riz0

First make sure the server started. The last three line in the Docker file: EXPOSE 5000 ENTRYPOINT ["rembg"] CMD ["s"]

In the Google Cloud web interface go to "Google Cloud Run" of your project and "Edit and Deploy new Revision": 1 2

The first start takes some times, approx. 40 seconds but once the instance is warm, it's super fast.

echtme avatar Jan 26 '23 09:01 echtme

@echtme Thanks again for the explanation. Hm, I don't think it ever actually starts to completion as indicated by the missing url:

DFs8mfP

Our container settings where I insert the port looks to be the same, but I notice that the last three lines of the docker file you mention are different then one in main branch currently: https://github.com/danielgatis/rembg/blob/main/Dockerfile

EXPOSE 5000 ENTRYPOINT ["rembg"] CMD ["--help"]

I've never actually edited the docker file, I simply pulled the stock latest image from here: https://hub.docker.com/r/danielgatis/rembg

Should I be downloading locally, editing the last three lines of docker file to reflect what you mention:

EXPOSE 5000 ENTRYPOINT ["rembg"] CMD ["s"]

Then rebuild and push that to my project? Or can I override the docker file from google cloud console without having to rebuild docker file/image? Bit of a docker noob so not sure best way. I guess the default docker image is just calling help then exiting instead of starting the http server with "CMD ["s"]" entry, right? If not, could you please advise what is the best approach. Thanks again for any help.

Riz0 avatar Jan 26 '23 09:01 Riz0

I've directly modified the .Docker file from the Github. CMD ["s"] as per the docs starts the server, not sure why they've added --help.

echtme avatar Jan 26 '23 10:01 echtme

I've directly modified the .Docker file from the Github. CMD ["s"] as per the docs starts the server, not sure why they've added --help.

That was it! Edited and rebuilt so it works now. Thanks so much! By the way how are you securing your curl requests to the rembg http server on GCR, apikey or some other setting? Wouldn't want it to get abused I suppose.

Riz0 avatar Jan 26 '23 12:01 Riz0