什么是无服务器工作流_什么是无服务器

news/2024/7/12 2:49:02 标签: https

什么是无服务器工作流

Whenever an application is built, it must be made available to users. Consider Facebook, which was created by Mark Zuckerburg in his Harvard dorm room — we wouldn’t have known about Facebook if he didn’t make it available for other people to use.

每当构建应用程序时,必须将其提供给用户。 考虑一下Facebook,它是由马克·扎克伯格(Mark Zuckerburg)在他的哈佛宿舍里创建的-如果他不将Facebook提供给其他人使用,我们将一无所知。

In the traditional approach, an application developer pays a Hosting Company some amount of money to rent servers. He then deploys his app unto this server and every year or month, he has to pay renewal fees to the Hosting company, whether anyone uses his application or not.

在传统方法中,应用程序开发人员向托管公司支付一定数量的钱来租用服务器。 然后,他将自己的应用程序部署到该服务器上,并且无论是否有人使用他的应用程序,每年或每月,他都必须向托管公司支付更新费用。

Image for posthttps://img-blog.csdnimg.cn/img_convert/ccf97ce84249e3254ea5bc05f92d7a99.png" width="543" height="371" style="outline: none;" />
Mark giving a lecture at Harvard
马克在哈佛大学演讲

In his lecture as a guest lecturer at Harvard, Mark Zuckerburg gave some insights into some of the problems he encountered when Facebook began to grow. At this time, Facebook was only used by schools in the US.

在他的演讲是哈佛大学客座讲师,马克Zuckerburg提出了一些见解一些他遇到当Facebook开始增长的问题。 目前,Facebook仅在美国的学校中使用。

In his words:

用他的话说:

“But after we hit about like 30 or 50 schools, … [we realized that] some of the ways that stuff was set up just wasn’t as optimal as it could.

“但是当我们打了大约30或50所学校之后,……[我们意识到]设置材料的某些方式并不是尽其所能。

So for example, when you have MySQL machines and Apache running on the same server, then if something happens to that server, then not only does the database for that school or the schools on that server just stop kind of responding in a way that will get you anything useful, but you can’t even load any web pages. So you get page not founds. And that kind of sucks.”

因此,例如,当您在同一台服务器上运行MySQL机器和Apache时,如果该服务器发生故障,那么该学校或该服务器上学校的数据库不仅会停止响应,而且会停止为您提供有用的信息,但您甚至无法加载任何网页。 这样您就找不到页面。 那太烂了。”

Mark and his friends had to find a way to scale Facebook to handle the enormous request it was then receiving. They had to do so or Facebook risked death: people would start losing interest if the site was down (due to too much traffic) any time they visited. By maintaining and monitoring the servers themselves, they were spending time that they could have used to build more features on Facebook to make sure it was prepared for enormous traffic.

马克和他的朋友们必须找到一种方法来扩展Facebook,以处理当时收到的巨大请求。 他们必须这样做,否则Facebook就有死亡危险:如果他们每次访问该网站(由于流量过多)而关闭,人们就会开始失去兴趣。 通过维护和监视服务器本身,他们花费了时间,本可以用来在Facebook上构建更多功能,以确保为大量流量做好准备。

Scaling an application is a major problem for any app developer. In the case of rented servers, this would mean renting more servers, deploying the app on the new servers, and making sure that there is data consistency across all servers.

扩展应用程序是任何应用程序开发人员的主要问题。 对于租用的服务器,这意味着要租用更多的服务器,在新服务器上部署应用程序,并确保所有服务器之间的数据一致性。

欢迎来到无服务器 (Welcome to Serverless)

Contrary to its name, Serverless does not mean the absence of servers (you still need servers in order for your app to be available online). It rather means that you don’t have to worry about server management, maintenance, monitoring, capacity planning, and scaling. You hand over these processes to a “serverless provider” and they take care of that for you.

与它的名称相反,Serverless并不意味着没有服务器(您仍然需要服务器才能在线上使用您的应用程序)。 而是意味着您不必担心服务器管理,维护,监视,容量规划和扩展。 您将这些过程交给“无服务器提供程序”,它们将为您处理这些过程。

In other words, serverless computing lets you build applications without thinking of servers.

换句话说,无服务器计算使您无需考虑服务器即可构建应用程序。

您只需为使用的商品付费 (You only pay for what you use)

I know you can already see the advantage in this, aside from making developers focus solely on what they do best: building apps, there is another good news. The Serverless architecture is a pay-per-use service, this means that if your app is on a serverless platform and it is not used, perhaps you haven’t gotten any user yet, you don’t pay anything. You pay lower on days with low usage, higher on days with high usage, and nothing on days with 0 usage!

我知道您已经看到了其中的优势,除了让开发人员完全专注于他们最擅长的方面:构建应用程序外,还有另一个好消息。 无服务器架构是按使用付费的服务,这意味着,如果您的应用程序位于无服务器平台上并且未被使用,那么也许您还没有吸引到任何用户,那么您无需支付任何费用。 在使用率较低的日子里,您支付的费用较低;在使用率较高的日子里,您支付的费用更高;而在使用率为0的日子里,您无需支付任何费用!

无服务器如何工作? (How does serverless work?)

You might be wondering if serverless providers are not losing money for hosting applications even when there is no usage. In the traditional approach, the application still needs to be ‘active’ on the servers all the time even when no one uses them and that is why hosting companies charge regardless.

您可能想知道,即使没有使用,无服务器提供程序是否也不会因托管应用程序而亏钱。 在传统方法中,即使没有人使用应用程序,应用程序仍必须始终在服务器上处于“活动”状态,这就是托管公司无论如何都要收费的原因。

Serverless providers do not charge you anything when your app has zero usage because they don’t keep your app ‘active’ all the time. How?

当您的应用使用量为零时,无服务器提供商不会向您收取任何费用,因为它们不会一直保持您的应用“活动”。 怎么样?

无服务器是事件驱动的:您适合被束缚吗? (Serverless is event-driven: are you fit to be tied?)

Image for posthttps://img-blog.csdnimg.cn/img_convert/1c45e6221a7c2f5c65ddcda0c025f76c.png" width="1400" height="1050" style="outline: none;" />

I love stories and analogies and I believe that one of the episodes of the cartoon series, Tom and Jerry titled ‘Fit to be tied’ can help us in understanding how the serverless application works.

我喜欢故事和类比,并且我相信卡通系列的一集,汤姆和杰瑞(Tom and Jerry)的标题为“适合被捆绑”可以帮助我们理解无服务器应用程序的工作方式。

In the episode, Jerry removes a tack from Spike’s paw. In gratitude, Spike gives Jerry a bell to ring when he’s in trouble. Each time Tom troubles Jerry, Jerry would ring the bell and Spike would rise from his rest to save Jerry from the hands of Tom. Spike would be resting the rest of the time and would only rise to help Jerry when he rings the bell.

在这一集中,杰里从斯派克的爪子上拔下了大头钉。 出于感激之情,Spike在遇到麻烦时给Jerry敲钟。 每次汤姆麻烦杰里时,杰里都会敲响钟声,斯派克会从他的休息中站起来,将杰里从汤姆手中救出来。 Spike会在其余时间休息,只会在铃响时帮助Jerry。

In serverless terms, we can say that the bell ringing is an ‘event’ and that ringing the bell means emitting an event. Spike then is an event listener. He is only ‘active’ (i.e saving Jerry) when an event is emitted.

用无服务器的术语,我们可以说响铃是一个“事件”,响铃就意味着发出一个事件。 Spike然后是一个事件侦听器。 发出事件时,他仅是“活动的”(即保存杰里)。

您的应用程式? 只是无服务器功能 (Your App? Just a serverless function)

Serverless providers treat your whole application as a function that is contained in some kind of ‘container’. This container contains everything your app needs for it to run and when this container is activated your app runs, otherwise it doesn’t. Simple.

无服务器提供程序将整个应用程序视为包含在某种“容器”中的功能。 此容器包含您的应用程序运行所需的所有内容,并且在激活此容器后,您的应用程序将运行,否则,它不会运行。 简单。

This means to automatically scale your application, the container just has to be replicated — as many times as needed.

这意味着要自动扩展您的应用程序,只需复制容器-根据需要进行多次。

These containers are event-driven: they are only active when certain events are triggered, and for the rest of the time (like Tom’s old friend, Spike), they are inactive.

这些容器是事件驱动的:它们仅在触发某些事件时才处于活动状态,而在其余时间(如汤姆的老朋友Spike)则处于非活动状态。

What happens can be represented in pseudocode as:

发生的情况可以用伪代码表示为:

if(event.isTriggered) { 
activateContainer()
} else
{
deactivateContainer()
}

Some of the triggers that can trigger the execution of a serverless function include HTTP requests, database updates, file uploads to file storage, and other serverless functions. A function container is both an event emitter and event listener and so it can be a trigger too.

可以触发无服务器功能执行的一些触发器包括HTTP请求,数据库更新,文件上载到文件存储以及其他无服务器功能。 函数容器既是事件发射器又是事件侦听器,因此它也可以是触发器。

Image for posthttps://miro.medium.com/max/9999/0*SSM5nzJFf7NRSRBM" width="1280" height="853" style="outline: none;" />

Just as these vases have everything the plants need to grow, serverless containers have everything your app needs to run.

就像这些花瓶具有植物生长所需的一切一样,无服务器容器也具有应用程序运行所需的一切。

无服务器基础架构提供商 (Serverless Infrastructure Providers)

Serverless requires big and expensive infrastructure to provide its benefits, this is why most of the vendors are the ‘big guys’. The most popular infrastructures are Amazon’s AWS Lambda Function, Google’s Cloud Functions, Microsoft’s Azure Functions. AWS currently dominates the market.

无服务器需要大型且昂贵的基础架构来提供其优势,这就是为什么大多数供应商都是“大人物”的原因。 最受欢迎的基础架构是亚马逊的AWS Lambda功能,谷歌的云功能,微软的Azure功能。 AWS目前在市场上占主导地位。

有时候,您不应该无服务器 (Sometimes, you should not go serverless)

Serverless comes with a lot of advantages and also have some disadvantages that we should discuss.

无服务器具有很多优点,但也有一些缺点我们应该讨论。

One of the most discussed cons of serverless is ‘vendor lock-in’. With serverless, you are not in charge of your servers. This means you are not in control over server hardware, runtimes and runtime updates, concurrency, and resource limits. Your vendor decides all of these and when you are set up with a vendor, it might be difficult to shift to another vendor. You might be locked-in.

无服务器讨论最多的缺点之一是“供应商锁定”。 借助无服务器,您无需管理服务器。 这意味着您无法控制服务器硬件,运行时和运行时更新,并发性和资源限制。 供应商将决定所有这些,当您与供应商建立合作时,可能很难转移到其他供应商。 您可能已被锁定。

Another disadvantage is latency. Using Tom and Jerry’s example, what would happen to Jerry when he is in trouble with Tom, rings the bell but Spike takes a long time to rise to his aid? Tom isn’t so nice. Sometime, your serverless application might take some time for it to start when triggered. You will have to deal with cold starts.

另一个缺点是延迟。 以汤姆和杰里的例子为例,当杰里遇到汤姆的麻烦时,杰里遇到了麻烦,但是当斯派克需要很长时间才能获得援助时,会发生什么? 汤姆不是很好。 有时,无服务器应用程序在被触发时可能需要一些时间才能启动。 您将不得不应对冷启动。

You should however know that most of these disadvantages have workarounds and you can research them before considering going serverless.

但是,您应该知道这些缺点中的大多数都有解决方法,可以在考虑使用无服务器之前对其进行研究。

结论 (Conclusion)

We have learned what serverless architecture is, how it works, and why to use or not use it.

我们已经了解了无服务器架构是什么,如何工作以及为什么使用或不使用它。

To can check out the following articles to continue learning about it:

可以查看以下文章以继续学习它:

  • When and why not to use serverless

    什么时候以及为什么不使用无服务器

  • Serverless Computing — AWS

    无服务器计算-AWS

Note: I used Facebook’s example to illustrate a point. Facebook maintains its servers and do not use any serverless providers. Originally published at https://solathecoder.hashnode.dev.

注意 :我使用Facebook的示例来说明这一点。 Facebook维护其服务器,并且不使用任何无服务器提供程序。 最初发布在 https://solathecoder.hashnode.dev

普通英语JavaScript (JavaScript In Plain English)

Did you know that we have three publications and a YouTube channel? Find links to everything at plainenglish.io!

您知道我们有三个出版物和一个YouTube频道吗? 在plainenglish.io上找到所有内容的链接!

翻译自: https://medium.com/javascript-in-plain-english/what-is-serverless-550dd9340042

什么是无服务器工作流


http://www.niftyadmin.cn/n/1468013.html

相关文章

30分钟java桌球小游戏_30分钟完成桌球小游戏项目

桌球在球桌中按照一定线路和角度移动,遇到边框会自动弹回。练手项目加速度控制//添加速度控制的台球游戏import java.awt.*;import javax.swing.*;public class BallGame2 extends JFrame {Image ball Toolkit.getDefaultToolkit().getImage("images/ball.png…

学习用React和反冲力来构建一个covid追踪器

Recoil.js is Facebook’s new state management library for React. It’s been designed to handle complex global state management with performance and asynchronous in mind.Recoil.js是Facebook针对React的新状态管理库。 它旨在处理性能和异步方面的复杂全局状态管理…

mysql 存储过程 注入_关于mysql:在PHP中使用预准备语句/存储过程时,如何保护自己免受SQL注入?...

我一直在研究如何最好地防止PHP / mysql中的sql注入,而不仅仅是使用mysqli / mysql真正的转义,因为阅读这个是mysql_real_escape_string足够的反SQL注入?我已经看到这个非常好的线程如何在PHP中阻止SQL注入?我用来在桌面/内部工具…

使用c#制作打字游戏_使用打字稿iii绘制网格构建游戏4 5

使用c#制作打字游戏Chapter III in the series of tutorials on how to build a game from scratch with TypeScript and native browser APIs本系列教程的第三章,介绍如何使用TypeScript和本机浏览器API从头开始构建游戏 Welcome to part 4 of the Chapter III “…

java窗体按钮改变颜色_[导入]课本习题:按钮改变窗体背景颜色

虽然事件接口和事件源繁多复杂, 但是处理事件的基本原理却很简单:即想要接受某个事件的类实现该事件监听器的接口,然后在事件源中注册自己,这样它就可以接收所要的事件,并通过监听器接口中的方法进行处理。此文中使用了…

javascript加载_在javascript中轻松加载图像

javascript加载When building a web application, we are always looking for the best performance in order not to impact user experience.在构建Web应用程序时,我们一直在寻找最佳性能,以便不影响用户体验。 Among all the techniques to improve …

vue.js 全局应用js_加快Vue JS应用程序的6种方法

vue.js 全局应用jsIf you’ve ever used Google’s Pagespeed Insights or Google Lighthouse then you’ve seen this webpage performance assessment:如果您曾经使用过Google的Pagespeed Insights或Google Lighthouse,那么您已经看到了此网页效果评估&#xff1a…

mysql 设置计算列_mysql – 创建计算列

我想创建一个评级权重,我需要计算AVG,然后找到COUNT并乘以两者来获得权重.我有类似的东西:SELECT post_id, COUNT(CASE WHEN vote > 0 THEN vote ELSE NULL END) AS voters,AVG(CASE WHEN vote > 0 THEN vote ELSE NULL END) AS average FROM wp_imdb_ratingG…