当前位置:网站首页>How to use function framework to develop large web application

How to use function framework to develop large web application

2020-11-09 12:10:02 Noosphere

This is the sixth session of early talk last month Serverless Special sharing . The whole sharing demonstrates three examples , It introduces Midway Serverless Different functions of the system , Welcome to try .

PPT Download and share :https://github.com/midwayjs/midway/tree/resource

1\. Personal introduction

Hello everyone , I'm Zhang Ting from the infrastructure group of the Technology Department of Alibaba ( flower ), His real name is Chen Zhongyin , Usually the community sees Harry Chen,czy88840616 It's all me .

What I bring to you today is 5 Release one in minutes Serverless application, Why 5 Minutes , There's scientific research , The shortest time a person is in a daze is probably 5 minute , If you're not careful, you'll pass by 5 minute , It also shows that in Serverless Under the system , Convenient development and release .

I'm currently in charge of the group Node.js Infrastructure part , Supporting the group Node.js Middleware system ,midway Series and corresponding plug-ins ,Nodejs Monitoring and all kinds of follow-up Node.js Related work , In the open source community , At the same time, it also maintains the whole Midwayjs system , Include Midway,Pandora,Sandbox And the new Midway-Serverless system .

meanwhile , from 2 Years ago , We're doing it all the time Typescript Advance of , And the support of group middleware standard definition , The future should be TS Of the world .

Recently, I'm in charge of the economy Serverless Node.js Direction of infrastructure , Include yml Standardization of , The reuse of capabilities , As well as the framework 、 Runtime 、 Plug in stability .

2\. The outline

  1. Introduce Serverless Some content of the current group and community system , And the comparison of various cloud platforms , In China, it is mainly Alibaba cloud and Tencent cloud Two families , And we use Serverless Some of the solutions , Share some of what these solutions can do , And some of the risks of these options ;
  2. Interspersed with some examples , take Midway Serverless The ability of the system is shown to you ;
  3. Facing the future , Introduce some future directions ;

3\. Why use Serverless system

The first question is , Why would there be Serverless, What does it have to do with the front end ?

This problem , As an infrastructure team , I've been studying and thinking since the end of last year . In fact, at the beginning , It's not about having Serverless. From the year before , The group has a total of about 2000+ Of Node.js application , There are a lot of back-end systems , Mostly everyday CPU lower than 5%, There are even 0.5% Of , Each application will have multiple machines , This causes a great waste of resources to the group . So the first appeal , It's about reducing resource costs , Especially the backstage .

Second pieces , A guest has also introduced , The front end has also reached a bottleneck period , From the very beginning of the cutaway , To the front and back end ,BFF The whole stack , It's time for one to be recognized , The direction of output , signify , From the front end of intelligence , Extend to the entire application , Not just thinking about parts of the page , It also considers data flow globally 、 framework , This is the overall architecture quality of the front end , It's a very big improvement .

For these two purposes , We began to be right about Serverless from 0 Start practicing , The group experienced double promotion last year , It's also extended to basically all of BU, In the backstage ,C There are different practices , It's thriving . Based on these practices , Open source, we aim at Serverless System and design Midway Serverless frame .

4\. Front end appeal

In the domestic community , There are only two cloud service providers , Alibaba cloud and Tencent cloud . Cloud service providers hope to expand the market , It's about revenue , Another one , Cloud resources , It's a resource in itself , Although there are oversold ( Like a core , Sell two cores ) But the resource itself also needs to be delicately managed .

And for community users , Small and medium developers , You talk to him Serverless, He thought about the following questions , What do I do with him , What's the difference from before , Which platform to choose , How simple or first , What about my old code , And most importantly , How much do I have to spend . When it comes to money , Everyone is sensitive , I am also , The other day during the test ,aws Collect from me every day 0.08 cents , I don't know why , I was anxious . That's what we all want from the front end .

5\. Community and Ecology

So since the community has so many cloud platforms to support , Let's take a look at the ecology of the community ?

5.1 Language support

We did a lot of research last year , Then it also includes some foreign platforms , Including Amazon , Google , Microsoft and these domestic manufacturers , There is one characteristic of so many platforms . In terms of language support, it is very biased to , The whole system is about Node.js Support has reached 70% above , And other languages support will be very small , especially Java and .Net These are some of the languages that are very traditional . These languages , It's just Serverless The system will not be very good , This is also determined by its efficiency and speed . One Java start-up ,2G Memory , and Node Account for only a 128M.

5.2 Ability support

So in terms of ability and knowledge , We also made some comparisons among the major manufacturers , As shown in the figure , At the moment, it looks very dense , In fact, the most commonly used system or function system service we can use , It's basically covered, including the common Object storage Message queue Timing task and journal , And the most commonly used front end Http Abilities are very useful .

6\. 2019 The front four directions

 And the other side is closely related to the front end ,2019 Top four directions in , because 2020 The year has not yet come out , So we see Serverless It's one of the big directions , Especially with the strong support of Ali's front-end Committee , We also promote and provide technical support all the way in the group and the community .

How it works , I believe we all know better , This is a very easy to understand picture from Amazon , It's also very popular. The above demonstrates from the call to the final execution and charging , The whole process can be clearly seen , Dynamic expansion of functions , Pay as you go and other advanced features ..

Back to the user itself, we just had some questions , If I were a user , that Serverless What scenarios are they serving , What can I do ?

Use some pictures of friends to show , In the community to do the most static website hosting , I will go GDP Of Epik High And the full stack model that combines these to replace traditional applications .

7\. What Ali does ?

  1. Shopping guide scene , Is Taobao home page and flying pig home page these marketing lists , Its flow in double 11 will also be very large , But it was also a smooth ride ;
  2. Backstage scenes , I just talked about the waste of our resources , We need to save these traditional waste resources , And can hope to gradually , When no one visits , Shrink the container's resources to 0, Then the app goes offline naturally ;
  3. RPC scene ,hsf The community is Dubbo, We also use functions to carry ;

These can all be part of the front end , In disguised form, the functions of the front end have been gradually expanded .

8\. The goal is

And this year our goal is cost , Of course, it's also a hope , It can transform tradition 80% The ability to support , At the same time, it also saves the machines mentioned above .

9\. Method

There are two kinds of functions in current applications , There are different people pushing , Move big applications directly ( Old application ), Or rewrite it directly ( New application ), Just now, the guest Guang Yi introduced the whole original egg The application is deployed to the function system , And the other , It's also what we're leading , Use a new framework that reuses most of the traditional capabilities to support functions .

The two models are natural trial and error , We feel that there is a certain risk in using traditional frameworks to directly add functions , The risk lies in the uncertainty of the traditional framework .

The traditional framework is for multiple processes , I don't know when to start , And state storage , And in the function scenario , We feel like we need to be more pure , It's called and executed differently , That's why the original Midway The core abstraction of , It produces lighter weight , Start faster , Single process design Midway Serverless frame .( We'll merge the two later , Do please look forward to )

10\. Midway Serverless Architecture

Whole Midway Serverless The system consists of three parts ,CLI part , Local cloud development , debugging , And the community's multi platform release , The second piece is the capabilities of the traditional framework , Dependency injection , Application sub environment configuration , And component reuse , Scalability, etc , The third is standardization , Include yml standard , Front end call function standard , And runtime standards for privatized runtime deployment .

11\. Example

Here's the sample section , This time I've brought three examples , Introduce different abilities separately , If you need to follow me , Some preparatory work needs to be done ahead of time .

11.1 preparation

11.2 Example 1

The first example , I'll show you how pure functions can be published as HTTP API, And how to develop locally , debugging .

1、 Introduce the directory structure , What each file does ;2、 Introduce f.yml The content of ;3、 Introduce the function entry , General structure , Class writing ;4、 How to test ;

Function demonstration :

1、f invoke -f index  Call function 
2、f invoke -p +  Changes take effect in real time   Modify the text  hello world111, In real time , Our local service , It simulates the ability of the gateway 
3、 Change the return value to  html, increase  type  , Our definition , Let's get used to it  koa  People who are familiar with , And through it , It can also be easily used directly  koa  middleware , Press  F12  View request 
4、 Start up debugging capability ,invoke -p —debug
5、 Demo deployed to [ Tencent cloud ](https://l.gushuji.site/tencent) and [ Alibaba cloud ](https://l.gushuji.site/aliyun)

11.3 Example 2

The second example is an integrated example , What is integration , It's the front end + Back end development together , Deploy together , It is very suitable for most of the background scenes , And remember , Our examples are all cross cloud , For the second example, I'll post the demo to Alibaba cloud , And for the third example, I'll post the demo to Tencent cloud .

Function demonstration :

1、f create  choice  vue  Example  
2、 Open locally , Introduce vue The components of , Function subdirectories , as well as  faas  Of vue  plug-in unit 
3、 start-up  http://127.0.0.1:8080/  see  vue  Rendering , Emphasize that only one port is started locally , The front and back end are developed entirely in one warehouse ( It's just a person 
4、F12  Look at the function interface , Modify the function interface , Refresh back to 
5、 Try to publish [ Alibaba cloud ](https://l.gushuji.site/aliyun), Pause before release , Introduce high density 
6、 Try to visit  vue-scf.mdemo.cn

11.4 Example 3

The third example is a complex full stack application , We've added a part of the data , Here we use Alibaba cloud Of OTS To store , In practice, you can also use your own MySQL Or other databases .

Because the code is relatively complex , We stratified it , The rules and user interface are abstracted .

The code structure

Function demonstration

1、 Because it contains a secret key , Not uploaded yet , There will be 
2、 Introduce the directory structure , Directory of functions , Database hierarchy , decoupling  , a key , It looks like an application , It's actually a function by interface dimension 
3、 This time we release [ Tencent cloud ](https://l.gushuji.site/tencent), I deleted the previous one , Visit and see  qy-scf.demo.cn  Confirm that it's not deployed 
4、 then  deploy, Revisit , Compare the same one in [ Alibaba cloud ](https://l.gushuji.site/aliyun) Code for  qy.demo.cn, Do some update operations , Data synchronization on both sides 

That's all for the demo , We show three different types of , be based on midway serverless Function development model of , Both simple pure functions provide HTTP Interface , There are also complex applications in the background , Develop daily blogs for small and medium developers , The backstage and the middle office are very helpful .

12\. Facing the future

The third part , We face the future , Look at what you're going to do later .

Serverless Is a very suitable for the front end to explore and explore a new system , His lightweight and face-to-face operation and maintenance allows the front-end not to maintain the server itself , And more focused on the logical part , meanwhile , It's also great for small companies , Individual developers build their own official website 、 Interface , service .

Midway Serverless For us , It's a functional framework in a new scenario , Hope to help users in the function system better in the code level to solve the problem . We are constantly looking for new scenes while pursuing the ultimate starting speed .

in addition , Also at the framework level , We hope to win together with various cloud platforms , Support the whole ecology .

Back , We will also consider using monomers and Serverless application Of each other , Even synergy , stay IoC Systems can be done .

in addition , Will also start to support other platforms , such as aws, And Tencent Component.

13\. Thanks

Last , We're also continuing to recruit people , Welcome to communicate , This is my wechat and Midway The answer group , Thank you for listening ( read ).

PPT Download and share :https://github.com/midwayjs/midway/tree/resource

A brief edition of the lecture notes ( The full version contains a demo. Please see the video and PPT), Links are as follows :

How to use function framework to develop large scale rapidly Web application | actual combat ​mp.weixin.qq.com Icon

版权声明
本文为[Noosphere]所创,转载请带上原文链接,感谢