服务器返回它们的和

by Nicolas Dao

由Nicolas Dao

无服务器有其陷阱。 这是避免它们的方法。 (Serverless has its pitfalls. Here’s how you can avoid them.)

In this post, I will share the lessons I learned over the past year while using Serverless to build mobile and web apps for a tech consultancy in Sydney. For each drawback, I will also recommend one or multiple solutions.

在这篇文章中,我将分享我在过去一年中使用Serverless为悉尼的一家技术咨询公司构建移动和Web应用程序时吸取的教训。 对于每个缺点,我还将推荐一个或多个解决方案。

1. FaaS-连接池限制 (1. FaaS - Connection Pooling Limitation)

FaaS conversations do not mention this limitation very often. Cloud providers market FaaS as a solution that could infinitely scale. While this may apply to the function itself, most of the resources that your function depends upon won’t be infinitely scalable.

FaaS对话很少提到此限制。 云提供商将FaaS作为可以无限扩展的解决方案进行营销。 尽管这可能适用于函数本身,但是函数所依赖的大多数资源都不会无限扩展。

The number of concurrent connections that your relational database supports is one of those limited resources. The unfriendliness of FaaS towards connection pooling is what makes this problem such a big deal.

关系数据库支持的并发连接数是那些有限的资源之一。 FaaS对连接池的不友好之处使这个问题变得如此重要。

Indeed, as I mentioned before, each instance of your function lives in its isolated stateless environment. That means that when it connects to a relational database (for example PostgreSQL, MySQL, Oracle), it should most probably use a connection pool to avoid reconnecting back and forth with your DB.

确实,正如我之前提到的,函数的每个实例都生活在其隔离的无状态环境中。 这意味着,当它连接到关系数据库(例如PostgreSQL,MySQL,Oracle)时,它很可能应该使用连接池,以避免与数据库来回重新连接。

Your relational database can only manage a certain amount of concurrent connections (usually the default is 20). Spawning more than 20 instances of your function will quickly exhaust your database connections, preventing other systems from accessing it.

您的关系数据库只能管理一定数量的并发连接(通常默认值为20)。 生成20多个函数实例将Swift耗尽数据库连接,从而阻止其他系统访问它。

For that reason, I recommend avoiding any FaaS if your function needs to communicate with a relational DB using a connection pool. If you need to use a connection pool, then a few options are available:

因此,如果您的功能需要使用连接池与关系数据库进行通信,我建议避免使用任何FaaS。 如果需要使用连接池,则可以使用一些选项:

  • Use a BaaS instead.请改用BaaS。
  • Some relational database like PostgreSQL offers plugins that can solve this problem by multiplexing the number of available concurrent connections.

    诸如PostgreSQL之类的关系数据库提供了可以通过多路可用并发连接数来解决此问题的插件。

2. FaaS-不支持WebSockets (2. FaaS - No Support For WebSockets)

This one is kind of obvious. But for those who think they can have the cake and eat it too, you can’t hope to maintain a WebSocket on a system that is by design ephemeral. If you’re looking for a Serverless WebSocket, then you’d need to use a BaaS like Zeit Now instead.

这是显而易见的。 但是对于那些认为自己也可以吃蛋糕也可以吃蛋糕的人,您不能希望在临时设计的系统上维护WebSocket。 如果您正在寻找无服务器WebSocket,则需要使用类似Zeit Now的BaaS。

Alternatively, if you’re attempting to create a Serverless GraphQL API, then it is possible to use Subscriptions (which relies on WebSockets) by using AWS AppSync. A great article that explains this use case in greater detail is Running a scalable & reliable GraphQL endpoint with Serverless.

另外,如果您尝试创建无服务器GraphQL API,则可以通过AWS AppSync使用Subscriptions(依赖WebSockets)。 一篇很棒的文章更详细地解释了该用例,它是使用Serverless运行可伸缩且可靠的GraphQL端点 。

3. FaaS-冷启动 (3. FaaS — Cold Start)

FaaS solutions like AWS Lambda have demonstrated huge gains when solving Map-Reduce challenges (for example, Leveraging AWS Lambda for Image Compression at Scale). However, if you’re trying to provide a fast response to events like HTTP requests, you’ll need to take into account the time required by the function to warm up.

在解决Map-Reduce挑战(例如, 利用AWS Lambda进行大规模图像压缩 )时, AWS Lambda之类的FaaS解决方案已展示出巨大的收益。 但是,如果您想对诸如HTTP请求之类的事件提供快速响应,则需要考虑函数预热所需的时间。

Your function lives inside a virtual environment that needs to be spawned to scale up based on the traffic it receives (something you naturally do not control). This spawning process takes a few seconds, and after your function idles due to low traffic, it will need to be spawned again.

您的功能位于一个虚拟环境中,需要根据接收到的流量(自然而然您无法控制)来生成该功能以扩大规模。 生成过程需要花费几秒钟的时间,并且由于流量减少而导致功能闲置后,需要再次生成它。

I learned that at my expense when deploying a relatively complex reporting REST API on Google Cloud Functions. That API was part of a microservice refactoring effort to break down our big monolithic web API. I started with a low-traffic endpoint, which meant that function was often in an idle state. The reports that were powered by that microservice became slow the first time they were accessed.

我了解到,在Google Cloud Functions上部署相对复杂的报告REST API时需要付出一定的代价。 该API是微服务重构工作的一部分,旨在分解我们庞大的整体Web API。 我从低流量的端点开始,这意味着该功能通常处于空闲状态。 由该微服务提供支持的报告在首次访问时变慢。

To fix that issue, I moved our microservice from Google Cloud Function (FaaS) to Zeit Now (BaaS). That migration allowed me to keep at least one instance up all the time (more about Zeit Now in my next post: Why We Love Zeit Now & When To Use It Over FaaS).

为了解决该问题,我将微服务从Google Cloud Function(FaaS)移至Zeit Now(BaaS)。 这次迁移使我能够一直保持至少一个实例(在我的下一篇文章中:关于Zeit Now的更多信息:为什么我们现在喜欢Zeit以及何时在FaaS上使用它)。

4. FaaS-长期存在的流程,不要打扰! (4. FaaS - Long-Lived Processes, Don’t Bother!)

AWS Lambda and Google Cloud Functions can run no longer than 5 and 9 minutes, respectively. If your business logic is a long-running task, you will have to move to a BaaS like Zeit Now instead.

AWS Lambda和Google Cloud Functions分别不能运行5分钟和9分钟。 如果您的业务逻辑是一项长期运行的任务,则必须改为使用Zeit Now之类的BaaS。

For more details on FaaS limitations, please refer to AWS Lambda quotas and Google Cloud Functions quotas.

有关FaaS限制的更多详细信息,请参阅AWS Lambda配额和Google Cloud Functions配额 。

5. BaaS&FaaS-放松基础架构控制 (5. BaaS & FaaS - Loosing Infrastructure Control)

If your product requirements necessitate some degree of control over your infrastructure, then Serverless will most likely leave you up the creek. Example of such problems could be:

如果您的产品要求需要对基础架构进行一定程度的控制,那么Serverless很有可能会让您不满意。 此类问题的示例可能是:

  • Microservices deployment orchestration. Ending up with a myriad of Serverless microservices will quickly become a deployment nightmare, especially if they need to be versioned altogether or by domain.微服务部署流程。 结束无数的无服务器微服务将很快成为部署的噩梦,尤其是如果需要对它们进行完全版本控制或按域进行版本控制时。
  • Controlling the lifecycle of each server to save on costs.控制每个服务器的生命周期以节省成本。
  • Having long-running tasks on multiple servers.在多台服务器上具有长期运行的任务。
  • Controlling the exact version of the underlying server OS, or installing specific libraries required by your app.控制基础服务器操作系统的确切版本,或安装应用程序所需的特定库。
  • Controlling exact geo-replication of your app or data to ensure consistent and fast performances globally (there are ways to overcome this in some scenarios. Check out Build a serverless multi-region, active-active backend solution in an hour).

    控制应用程序或数据的精确地理复制以确保全局一致和快速的性能(在某些情况下,有一些方法可以解决此问题。请检阅在一个小时内构建无服务器的多区域,双活后端解决方案 )。

Serverless may fall short in all the above use cases. However, as I’ve discussed before, Serverless is just an extension of PaaS. To keep as much focus as possible on writing code rather than worrying too much about the underlying infrastructure scalability and reliability, leveraging the latest PaaS containerization strategies such as Google Kubernetes Engine can get you very close to what Serverless has to offer.

在以上所有用例中,无服务器都可能不足。 但是,正如我之前讨论的,Serverless只是PaaS的扩展。 为了尽可能专注于编写代码,而不是过多地担心基础架构的可伸缩性和可靠性,利用最新的PaaS容器化策略(例如Google Kubernetes Engine)可以使您非常接近Serverless所提供的功能。

6. BaaS和FaaS-合规性和安全性 (6. BaaS & FaaS - Compliance & Security)

Serverless shares all the usual complaints related to the cloud. You are giving up control of your infrastructure to one or multiple third parties. Depending on the vendor, Serverless may or may not provide the right SLA and security levels for your business case.

无服务器共享与云有关的所有常见投诉。 您正在将基础结构的控制权交给一个或多个第三方。 根据供应商的不同,Serverless可能会也可能不会为您的业务案例提供正确的SLA和安全级别。

Whether Serverless a go or no-go from a compliance and security point of view really depends on your particular case. Many articles discuss this topic in great details (like The state of serverless security).

从合规性和安全性的角度来看,无服务器运行还是不运行实际上取决于您的特定情况。 许多文章都非常详细地讨论了该主题(例如无服务器安全性状态 )。

结论 (Conclusion)

Serverless is not a silver bullet. The gains you can obtain from it depend on your knowledge of it. The good part is that the barrier to entry is so low that you should be proficient in no time.

无服务器不是灵丹妙药。 您可以从中获得的收益取决于您对它的了解。 好的方面是,进入门槛很低,您应该很快就精通。

下一步… (COMING NEXT…)

Of course, Serverless has limitations. All technical solutions have them. The question now is how we overcome them. In my next post, I’ll write about suggestions my team and I developed to deal with those limitations: “Why We Love Zeit Now & When To Use It Over FaaS”.

当然,无服务器具有局限性。 所有技术解决方案都有它们。 现在的问题是我们如何克服它们。 在我的下一篇文章中,我将撰写有关团队的建议,并为克服这些局限性提出建议:“为什么我们现在喜欢Zeit以及何时在FaaS上使用它”。

Follow me on Medium - Nicolas Dao - if you’re interested in what’s coming next:

在Medium- Nicolas Dao上关注我,如果您对接下来发生的事情感兴趣:

Current posts in this serverless series:

此无服务器系列中的当前帖子:

  • Do You Really Know What Serverless Is?

    您真的知道什么是无服务器吗?

  • The Impact of Serverless On Tech Leadership

    无服务器对技术领导力的影响

  • How Serverless Is Automating IT Engineers

    无服务器如何使IT工程师自动化

Future posts in the series:

该系列的未来文章:

  • Why We Love Zeit Now & When To Use It Over FaaS

    为什么我们现在爱Zeit以及何时在FaaS上使用它

  • Serverless Event-Driven Architecture: The Natural Fit无服务器事件驱动架构:自然而然的选择
  • How To Manage Back-Pressure With Serverless?如何使用无服务器管理背压?
  • GraphQL on Serverless In Less Than 2 Minutes不到2分钟的无服务器GraphQL

翻译自: https://www.freecodecamp.org/news/the-serverless-series-mistakes-you-should-avoid-9ec1ca6b9dff/

服务器返回它们的和

服务器返回它们的和_无服务器有其陷阱。 这是避免它们的方法。相关推荐

  1. 如何判断2服务器性能好或坏_无服务器革命:好,坏和丑

    如何判断2服务器性能好或坏 "这是愚蠢的. 比愚蠢还糟:这是一场营销炒作." ‐ 理查德·斯托曼 ( Richard Stallman)对云计算的评论,2008年9月 而且,十年后 ...

  2. 从零开始发布前端代码到服务器上_无服务器计算:让每行代码都能住上“经济适用房”...

    是时候展现真正的实力了!大胆报名吧!! 摘 要 独立的简单函数可以让开发工作变得更加容易,同时由事件驱动的执行可让操作变得更加便宜. 开发人员往往需要花费大量的时间编写代码以解决业务问题.随后,运营团 ...

  3. 自动驾驶行车记录仪训练集_无服务器安全性:将其置于自动驾驶仪上

    自动驾驶行车记录仪训练集 Ack :本文是从个人经验以及从无服务器安全性的其他多个来源学到的东西的混合. 我无法在这里列出或确认所有这些信息: 但是,应该特别感谢The Register , Hack ...

  4. JAVA服务器没回应_Java如何面对无服务器的挑战?

    这是来自jaxcenter组织的一个讨论,谈论了Java在无服务器浪潮冲击下面临的机会和挑战.下面摘录主要部分: Spring推动者Pivotal有一个名为 Riff的函数即服务平台,它是一个开源的. ...

  5. C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件)的解决方法

    C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件)的解决方法 参考文章: (1)C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文 ...

  6. nodejs 调用微服务器_无服务器NodeJS:构建下一个微服务的快速,廉价方法

    nodejs 调用微服务器 by Filipe Tavares 由Filipe Tavares 无服务器NodeJS:构建下一个微服务的快速,廉价方法 (Serverless NodeJS: the ...

  7. 服务器虚拟化发展现状_无服务器艺术的现状

    服务器虚拟化发展现状 Over the past 2 years, the Hydro team I lead at Berkeley's RISELab has been running hard ...

  8. mysql远程服务器返回错误404未找到_远程服务器返回错误: 404错误、远程服务器返回错误:500错误、 HttpWebResponse远程服务器返回错误:(404、500) 错误。...

    现象 我们编码实现请求一个页面时,请求的代码类似如下代码: HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strUrl); req.Us ...

  9. 项目不能使用fn标签_无服务器,Java和FN项目的第一步

    项目不能使用fn标签 无服务器不是什么新事物,但是可以说,仍然有很多关于它的炒作,以及它将如何改变一切,以及未来将如何成为无服务器. 除了云提供商提供的无服务器/功能之外,还有越来越多的无服务器项目正 ...

最新文章

  1. java读取字符串,生成txt文件
  2. 端口镜像NIDS技术(sniffer抓包)
  3. camvid数据集使用方法_使用PyTorch处理CIFAR10数据集并显示
  4. 7段均衡器最佳调节图_超高级的吉他均衡器 更细腻的控制 你值得拥有
  5. 数组转List的3种方法和使用对比!
  6. access文本框如何分开_ACCESS 2007 如何在窗体中将一个文本框的内容复制给另外一个文本框?...
  7. quartz的job类无法保留本身通过spring注入的属性问题
  8. BZOJ2815:[ZJOI2012]灾难(拓扑排序,LCA)
  9. Linux驱动开发|音频驱动
  10. 计算机丢失dll文件怎么弄,电脑缺少dll文件怎么办
  11. 各类软件激活码(更新中)
  12. AttributeError: module ‘hanlp.utils.rules‘ has no attribute ‘tokenize_english‘
  13. 生产进度管理系统为制造管理提供较完善的解决方案
  14. CentOS 8安装 GVM20.08
  15. 四步教你用网站源码建站
  16. class.forName
  17. hudson安装以及使用
  18. 奋斗不止 自强不息:职场话题之跳槽(四)—离职
  19. 阿里云安全组规则配置及Tomcat外网访问
  20. 平面、超平面的法线,平行超平面的距离

热门文章

  1. Nginx学习之一-第一个程序Hello World
  2. 媒体控件的暂停与播放 0130 winform
  3. 9203-1203-随堂笔记-窗体通讯录
  4. pptx给幻灯片添加内容
  5. django-图片上传,用户上传
  6. 网站迁移或者调整页面链接的方法
  7. freebsd配置IP
  8. (干货).NET开发丰富的公共类库助你事半功倍(供下载免费使用)
  9. js match函数注意
  10. 使用solrj和EasyNet.Solr进行原子更新