Firebase Blaze计划和云功能 [英] Firebase Blaze plan and Cloud Functions

查看:46
本文介绍了Firebase Blaze计划和云功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,Firebase的Flame计划消失了,我现在必须处理Blaze计划,我不喜欢Blaze计划,因为它是无限"的.预算(但我的钱包没有).昨天我在编码时,错误地制作了一个称为3 Cloud Functions的循环,我发现该循环的速度足以阻止大屠杀.

Unfortunately Firebase's Flame plan disappeared and I now have to deal with Blaze plan, which I'm not fan of because of it's "unlimited" budget (but my wallet isn't). Yesterday I was coding and by mistake made a loop that called 3 Cloud Functions, I spotted the loop fast enough to stop the carnage.

在仅15秒的执行时间内,我已经能够触发超过1万个请求,并且没有错误,这证明Firebase的性能相当不错,但也很可怕!如何设置上限以限制来自用户的请求?我对自己的代码非常有信心,但是众所周知,如果有人获得了我的Firebase配置文件,我就完成了.

In only 15 seconds of execution, I've been able to trigger more than 10K requests, and without errors, that a pretty good performance of Firebase, but it's scary as well! How can I cap this to throttle requests coming from users? I'm pretty confident in my code, but as we all know if someone gets my Firebase config file, I'm done.

我是一个单独的开发人员,这是我业余时间完成的第一个应用程序,我不想因为触发读取/写入/云功能而变得一团糟.没有人是完美的,每个人都会犯错,也许我没有在代码中发现一个小错误,只有在生产中一次它才能揭示出它的真正潜力.我不是要Firebase处理我的错误,但我希望能够停止CF和Firebase.

I'm a solo developer and it's my first app done on my spare time, I don't want to to become a mess because of triggering reads / writes / Cloud Functions. No one is perfect, everyone makes mistakes, maybe I didn't spot a small bug in my code that'll reveal it's true potential only once in production. I'm not asking Firebase to handle my mistakes, but I'd like to be able to stop the CF and Firebase if I want to.

我唯一的愿望是要有自信的睡眠,我不想在早上有10.000美元的账单时醒来.我读到有可能使用CloudFunctions完全禁用项目上的账单帐户,但是Firebase存储桶会发生什么(例如,优于Spark计划的存储)?而且这似乎并不容易.

My only desire is to sleep confident, I don't want to wake up one morning with a 10.000$ bill. I've read that's it's possible to totally disable billing account on a project with CloudFunctions, but what will happen to my Firebase Storage bucket for example (for the storage superior to the Spark plan)? And it doesn't seem easy to do.

Firebase是一个很棒的产品,我喜欢它的使用多么简单/有趣,但是现在由于Flame预算有限的计划已经不见了,因为我的应用程序几乎已经准备好投入生产,所以我感到非常受困,而我不愿意这样做.认为我是那里唯一的人.

Firebase is a great product and I love how easy / fun it is to use, but now that budget locked plans as Flame are gone I feel really trapped now that my application is almost ready to go into production, and I don't think I'm the only one out there.

推荐答案

啊,您偶然发现了速率限制"难题.不用担心,我花了很多时间为自己担心.

Ah you've stumbled onto the 'rate-limiting' conundrum. Not to worry, I've spent many nights worrying about this myself.

为了更好地控制您的应用程序,您将必须将项目链接到 Google云平台.然后导航到 IAM&Admin>配额(一旦选择了Firebase项目).

In order to get a bit more control over your application, you're going to have to link your project to google cloud platform. Then navigate to IAM & Admin>Quotas (once you've selected your firebase project).

现在,您可能一开始可能不知所措,并且对为什么云功能API限制器这么多感到困惑.这些配额应允许您通过多种方式对云功能API(类似于twitter的功能)进行速率限制,包括但不限于:

Now you might be overwhelmed initially, and confused as to why there are so many Cloud functions API limiters. These quotas should allow you to rate limit your cloud functions API (similar to what twitter does) in a number of ways, including but not limited to:

  • 每天阅读请求
  • 每100秒读取请求
  • 每100秒调用一次函数
  • 每天的函数调用

将列出的API是您已启用的API,因此您也可以设置云存储的限制.

The API that will be listed are the ones you've enabled, so you can set limits for cloud storage as well.

默认情况下,在火花计划中,每秒的最大调用数设置为每天最多5000次调用.但根据 docs ,绝对最大值为100,000,000/100秒!

By default, the max number of invocations per second is set to the maximum of 5000 invocations per day on the spark plan. but according to the docs, the absolute maximum is 100,000,000/100 seconds!

也值得一看的是定价文档,其中有一个很好的例子成功应用程式的典型每月使用案例.要大大简化,单次调用的费用为0.0000004美元,因此10,000,000次调用将花费您高达3.20美元.但是,不要让这么低的成本让您迷惑,如果您编写了一些糟糕的代码并且它具有指数级的复杂性(例如每次调用都读取firestore集合中的每个文档),那么您可能会付出沉重的代价.因此,请确保您设置了这些配额:)

Also worth having a look at is the pricing docs, which have a nice example of a typical monthly use case for a successful app. To grossly oversimplify, a single invocation costs $0.0000004, hence 10,000,000 invocations will cost you a whopping $3.20. However don't let that very low cost fool you, if you write some terrible code and it has exponential complexity (like reading every document in a firestore collection every invocation), you could get slapped with an exponential cost. So make sure you set those quotas :)

请记住,服务器管理员与代码本身一样是应用程序的一部分.如果您的应用程序已投入生产,请准备好每天花费一些时间浏览Google云仪表板并检查限制,分析趋势等.通过这种方式,您可以增加每天可以允许的调用数量并保持良好睡眠知道如果您用脚开枪射击,不会流血过多.

Remember, server admin is as much a part of the application as the code itself. If your app goes to production, be prepared to spend some time each day going through the Google cloud dashboard and checking limits, analyzing trends, etc. This way you can kind of step up the amount of invocations you can allow per day and sleep well knowing that if you shoot yourself in the foot, you won't bleed too much.

祝你好运

卑鄙的B.

这篇关于Firebase Blaze计划和云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆