Detailed Explanation of the Latest Application Scenarios of Function Computing Based on Alibaba Cloud Serverless Architecture (1)

The serverless concept is a technology concept that has become particularly popular in recent years. Based on this architecture, many application scenarios can be built, which are suitable for all walks of life. As long as you have requirements for scenarios such as light computing, high elasticity, and statelessness, you can use this article to familiarize yourself with some basic concepts and get inspiration from related scenarios.

Regarding the past and present life of the serverless architecture, a network diagram describing the development history of human form is popular on the Internet. From crawling hominids, to squatting hominids, to erect humans, and finally to tool-wielding emerging humans. From crawling on all fours to walking upright, hands free, from hands free to tool use.

Human evolution has been accompanied by an increase in production efficiency every time. In the same way, the development mileage of the entire IT computing is also the mileage of gradually improving production efficiency. The specific evolution diagram is as follows:

d8d956d66eec1d2ce5be9093f6e4d6a86fe9a2ce

From large-scale physical machines to virtualizing physical machines into single VM resources through virtualization technology, from virtualizing clusters to moving clusters to cloud computing for simple operation and maintenance, to dividing each VM into segments according to the smallest running space A finer Docker container, and then from a Docker container to a Serverless service that does not need to manage any operating environment at all, that is, only the core code needs to be written.

Intergenerational technological changes are all about dividing resources into more detail, making operation more efficient, and making hardware and software maintenance easier. The evolution of IT technology architecture mainly has the following characteristics:

1. The granularity of hardware resource usage becomes smaller

2. Resource utilization is getting higher and higher

3. The operation and maintenance work is gradually reduced

The serverless architecture mainly has the following characteristics:

1. Realize fine-grained computing resource allocation.

2. There is no need to pre-allocate resources.

3. It has a high degree of expansion and flexibility in the true sense.

4. On-demand use, on-demand billing.

 

Based on these general characteristics of Serverless, the following typical usage scenarios are summarized for your reference.

Event Request Scenario

custom image

网店中的商品图片维护,根据商品陈列位置,要求需要动态切割成不同尺寸图片,或者打上不同水印,当店家把图片上传到阿里云OSS上,会通过函数计算上定制的trigger来触发函数计算。根据计算规则,生成不同尺寸的图片,满足电商陈列使用,整个过程无需再搭建额外服务器,也无需网站美工干预。

 

 物联网中的低频请求

物联网行业中,由于物联网设备传输数据量小,且往往是固定时间间隔进行数据传输,因此经常涉及低频请求场景。

例如:物联网应用程序每分钟仅运行一次,每次运行50ms,这意味着CPU的使用率为0.1%/小时,这也意味着其实有1000个相同的应用可以共享计算资源。而Serverless架构下,用户可以购买每分钟100ms的资源来满足计算需求,通过这种方式就能够有效解决效率问题,降低使用成本。

 

定制事件

用户注册时发邮件验证邮箱地址,同样通过定制的事件来触发后续的注册流程,而无需再配置额外的应用无服务器来处理后续的请求。

 

固定时间触发

事件触发固定时间触发,例如在夜间或者服务空闲时间来处理繁忙时候的交易数据,或者运行批量数据,来生成数据报表,通过Serverless方式,不用再额外购买利用率并不高的处理资源。

 

流量突发场景

弹性扩展应对突发流量

移动互联网应用经常会面对突发流量场景。例如:移动应用的通常流量情况是QPS 20,但每隔5分钟会有一个持续10s的QPS 200流量(10倍于通常流量)。传统架构下,企业必须扩展QPS 200的硬件能力来应对业务高峰,即使高峰时间仅占整个运行时间的4%。

在Serverless架构下,您可以利用弹性扩展特性,快速构建新的计算能力来满足当前需求,当业务高峰后,资源能够自动释放,有效节省成本。

 

转码和流量扩容

 

视频直播某次专场活动,由于无法预估会有多少点播的观众视频接入,把转码和流量扩容这部分内容通过Function来处理,无需考虑并发和流量扩容。

处理大数据场景

由于安全审计问题,您需要从OSS(多个地域)过去一年的数据(1个小时一个文件)中找出特定关键字访问的日志,同时做聚合运算(计算出总值)。如果使用阿里云函数计算,您将高峰期每2小时的访问日志,或者低谷期每4小时的访问日志交给一个计算函数处理,并将处理结果存到RDS中。使用一个函数分派数据给另一个函数,使其执行成千上万个相同的实例。

这样会同时运行近千个计算函数(24 x 365 / 10),在不到一分钟的时间内完成整个工作。同样的事情交给ECS+计算脚本来做计算,单单为这些instance配置网络就让人头疼(不同地域无法走内网下载OSS文件):instance的数量可能已经超出了子网中剩余IP地址的数量(比如,您的VPC使用了24位掩码)。

下面结合阿里云的函数计算产品来讲解各个应用场景中架构以及如何解决的场景中的痛点。阿里云的函数计算是基于Serverless这种架构实现的一个全托管产品,用户只需要上传核心代码到函数计算,就可以通过事件源或者SDK&API来运行代码。函数计算会准备好运行环境,并根据请求峰值来动态扩容运行环境,函数计算是按照执行时间来计费,请求处理完成后,计费停止,对于有业务请求有明显高峰和低谷的应用来说,相对节省成本。

下图是函数计算的一个开发者试用操作流程:

918aa9e18325e5855f8a49c2dd18bda9aaf6a9db

步骤1:开发者编写代码,目前支持的语言Java、NodeJS、Python等语言。

步骤2:把代码上传到函数计算上,上传的方式有通过API或者SDK上传,也可以通过控制台页面上传上传,还可以通过命令行工具Fcli上传。

步骤3:通过API&SDK来触发函数计算执行,同样也可以通过云产品的事件源来触发函数计算执行。

步骤4:函数计算在执行过程中,会根据用户请请求量动态扩容函数计算来保证请求峰值的执行,这个过程对用户是透明无感知的。

步骤5:函数执行结束后,可以通过账单来查看执行费用,根据函数的实际执行时间按量计费,收费粒度精确到100ms。

讲解完上面的流程后,下面会详细讲解3Serverless的应用场景,通过案例分享能让您对Serverless这种架构有更清晰的认识。

事件触发计算能力

056cf4606d7b18ab74d22b2fd982cedc74daa4c8

场景描述:用户通过手机终端,Web应用,或者PC工具把各种文件包括图片、视频以及文本等上传到OSS(对象存储,下同)后,利用OSS的PutObject的事件可以触发函数计算对上传后的文件进行处理,目前比较典型的场景当用户把视频文件上传到OSS后,触发函数计算把对象的Meta信息获取并传输给核心算法库,核心算法库根据算法把相应的视频文件推送CDN源站,达到特定视频热加载的处理。另外一个场景,视频文件上传到OSS后也同时触发函数计算同步做多转码率的处理,并把处理后的视频文件存储到OSS中,完成轻量的数据处理。

在多媒体的处理场景中,经常会碰到海量文件上传到OSS后,还需要对文件进行进一步的加工,例如加水印、转码率、获取文件属性等操作,这个场景中,用户在处理的时候会遇到以下需要解决的技术难点:

1、 如何接收文件上传后的动作事件,通常的做法是定制消息通道来接收OSS事件通知,搭建一个运行环境,并编写相关的代码来处理事件通知。

2、如何高效的处理完海量上传的文件。

3、如何无缝的把多个云产品连接起来。

通过函数计算能比较方便解决以上几个技术难点,首先函数计算可以设置OSS的触发器来接收事件通知,在函数计算中编写业务代码来处理文件,并通过内网把文件传输到OSS中,整个流程简单易用可扩展。可以把核心代码部署到函数计算中,通过函数计算来并发处理事件通知。函数计算目前打通了多款产品的内部交互,通过控制台简单配置就可以高效的解决产品间连接问题。

 

事件触发场景常规做法:

1、设置消息通道接收事件,并编写业务代码。

2、购买服务器资源做后端数据处理。

3. Design a multi-concurrency framework to complete the processing of peak business upload files.

4. Open multiple products and call SDK code to complete business interaction.

 

Function calculation solution:

1. Configure event source notifications on the console and write business code.

2. The code is written into the function calculation, and there is no need to manage the software and hardware environment.

3.  Function computing will dynamically scale during peak business hours without management.

4. Built-in access to a variety of products, simple configuration can be seamlessly connected.

 

Original address: http://click.aliyun.com/m/40926/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326096223&siteId=291194637