nagadomi / waifu2x

Image Super-Resolution for Anime-Style Art
http://waifu2x.udp.jp/
MIT License
27.33k stars 2.71k forks source link

[Low priority/Question] - AWS Lambda functions #429

Closed antenore closed 1 year ago

antenore commented 1 year ago

First, thanks so much for this project! Thanks to you, I'm saving some money, and I'll for sure devolve part of it to your Patreon project.

I was wondering how is set up the infrastructure behind http://waifu2x.udp.jp/index.html

As far as I understand, you're planning to move to Google virtual machines, wouldn't AWS Lambda Functions something much less expensive than a Virtual machine?

The huge advantage is that you would pay only when a user submits an image to be converted, therefore you would have to pay for the temporary storage, the extremely low fee of AWS Lambda, and that's all. And with that free tier plan, you would even not pay at all in the beginning or till when you would get a huge amount of traffic/requests.

I'm not an advocate of Amazon, but it's the only cloud service that I know quite well at the moment, so what I say may apply as well to other cloud provider. My argument is only Functions vs VMs.

https://aws.amazon.com/blogs/machine-learning/using-container-images-to-run-pytorch-models-in-aws-lambda/

nagadomi commented 1 year ago

Actually, I am not sure if the current AWS Lambda can provide waifu2x.udp.jp and reduce costs.

  1. When I checked that before(maybe around 2017), the GPU instance was unavailable. Also, at that time, CPU processing took more than one minute per request(superresolution requires much more processing time than object recognition), which was impractical.
  2. Also, currently waifu2x.udp.jp has more than 100,000 requests per day and no idle time.
  3. The main cost of waifu2x.udp.jp is the data transfer cost; when using EC2, roughly speaking, the instance cost was about $200/month and the data transfer cost about $500/month. https://github.com/nagadomi/waifu2x/issues/396#issuecomment-821035062

The current server uses GPC Preemptible VM instance (n1-standard-4, 3CPU, 1x NVIDIA Tesla T4, about $500/month, instance cost $100 + data transfer cost $400).

EDIT:

100,000 requests

This is the number of requests for recapcha, so actual API requests may be less.

antenore commented 1 year ago

Wow! That's a lot!!! I'll check later, but probably you are right

antenore commented 1 year ago

I think you should give it a try.

image

I've chosen ARM as it's what AWS advises for High computing Lambda functions (AI, and so forth).

Lambda functions are mainly billed per RAM used and storage, in this calculation I've chosen 1 GB of RAM, for CPUs it scales as much as needed, and ephemeral storage 10 GB.

S3 may be or not needed, it depends on how long you want to keep the images. In my example, I've clearly exaggerated to just have a pessimistic prevision.

Some details…

Lambda: Architecture (Arm), Architecture (Arm), Number of requests (100000 per month), Amount of ephemeral storage allocated (10 GB)

image

S3: S3 Standard storage (2 TB per month) DT Inbound: Internet (2 tb_month), DT Outbound: US East (N. Virginia) (2 tb_month)

Regarding the storage, it's probably overestimated.

nagadomi commented 1 year ago

100000 per month

This is daily, not monthly. I counted the log of "POST /api" in nginx log for " 26/Jul/2022". It was 72477. about 2200000 per month.

antenore commented 1 year ago

100000 per month

This is daily, not monthly. I counted the log of "POST /api" in nginx log for " 26/Jul/2022". It was 72477. about 2200000 per month.

Sorry I misread it. In that case it would be much more expensive! :-( Just for the Lambda function it'd cost around 3,645.09 USD per Month.

Closing as answered.

nagadomi commented 1 year ago

For small or personal servers, I think the cost can be less. My concern is that the CPU processing is probably very slow for super-resolution processing.