Research on the Serverless

   1 Introduction

         Serverless is a "non-server architecture," allowing users to run the environment, resources and do not care about the number, as long as the energy technology Focus on business logic.

Now the company has achieved DevOps technology, is moving to Serverless, and why the front-end to pay attention Serverless?

For FE students:

  • Interface specification defines the front and rear ends will change.

  • It will change the front and rear ends of the FBI, which allows the front-end server to participate in the development of logic, even Node Java mixing section.

  • Nodejs server maintenance is greatly reduced threshold, as long as you can write JS code maintenance Node service, without having to learn DevOps knowledge.

For a free Developer:

  • Future server deployments more resilient, more money.

  • Deployment faster and less error-prone.

Into the rear end of the front frame is always thinking, and Serverless is the front-end thinking into the back-end operation and maintenance.

In fact, front-end developer is the first to enjoy the "Serverless" benefits groups. They do not need to have their own services, do not even need your own browser, you can make your own JS code uniformity, load balancing run in each user's computer.

And each user's browser, as it is now the most fashionable, most mature Serverless clusters, starting from a cold start remote loading JS code, even on a cold start is remarkable leader: to accelerate the use of JIT make the code in milliseconds cold start . Not only that, the browser still achieve a perfect environment BAAS services, we can call any function to get the user Cookie, environmental information, the local database services, without concern for users to use what computers connected to how the network, and even the hard disk size.

This is the Serverless concept. By FAAS (function as a service) and BAAS (the background as a service) in an attempt to manufacture front-end server developers accustomed development environment, the front-end developers should better understand the benefits Serverless brings.

2. Intensive

FAAS (function as a Service) + BAAS (the background as a service) can be called a complete realization of Serverless, in addition, there is the concept of PASS (Platform as a Service) is. Usually internet technology environment through the container, in order to achieve ultimately noops (unmanned operation and maintenance), or at least the DevOps (O & M & Development).

Briefly explain a few terms, to prevent people being around the halo:

FAAS - Function as a service

A service function, each function is a service function can be written in any language, in addition to any Heyun Wei do not care about the details, such as: computing resources, flexible expansion, but also by the amount of billing, and supports event-driven . Industry big cloud vendors support FAAS, each has a set of tables, or visual workflow to manage these functions.

BAAS - Backend as a service

And back-end services, is the integration of a number of middleware technology, you can ignore environmental invoke services, such as data as a service (database service), cache services. Although there are many below XASS, but the composition Serverless concept only FAAS + BAAS.

PAAS - Platform as a service

Platform as a service, users can upload the source code can be automatically enjoy continuous integration and high availability services, if the speed is fast enough, can be considered similar Serverless. But with the rise to Docker represented container technology, container size to deploy PASS gradually become mainstream, it is the most common application deployment. For example, middleware, database, operating system, etc.

DAAS - Data as a service

I.e. data services, data acquisition, control, polymerization, packaged together to provide the service out. DASS service can be applied Serverless architecture.

IAAS - Infrastructure as a Service

Infrastructure services, such as computer storage, networking, servers and other infrastructure as a service provided.

SAAS - Software as a Service

Software as a service, such as ERP, CRM, mail services, software services to provide granularity.

container

Container is to isolate the virtual execution environment of the physical environment, and the environment can be described migration. Container technology is more popular Docker.

With the increase in the number of containers, there have been technical management of the container cluster, the more famous choreography container platform is Kubernetes. Container technology is an option Serverless architecture implementation also the basis for implementation.

NoOps

It is no operation and maintenance, more idealistic, perhaps by means of AI ability to fully unmanned operation and maintenance.

Unmanned operation and maintenance does not mean Serverless, Serverless people may also need the operation and maintenance (at least for now), but developers no longer need to care about the environment.

DevOps

I think that can be understood as "development that is operation and maintenance," after all, out of things, the development is to be accountable, but a mature DevOps system can allow more developers to take responsibility OP or the OP closer cooperation.

Back Serverless, back-end development of future experience may be similar to the front: do not care about the code running on which server (browser), without concern for the server environment (browser version), do not worry about load balancing (front-end never worried) , middleware services at any time call (LocalStorage, service Worker).

// ... UI 部分,画出一个倒计时伐木场建造进度条
const currentTime = await requestBuildingProcess();
const leftTime = new Date().getTime() - currentTime;
// ... 继续倒计时读条
// 读条完毕后,每小时木头产量 + 100,更新到客户端计时器
store.woodIncrement += 100;

For gaming experience, users can, without refreshing the browser and see the progress of the construction of sawmill read the article, and bang it completed the construction and get discovered more than 100 points per second timber! But when the former sawmill construction is completed, completion, any point in time after completion of refresh your browser, must maintain a unified logic, and data necessary to calculate the back end off. At this point you should write back-end code:

/ 每次登陆时,校验当前登陆
const currentTime = new Date().getTime()
// 获取伐木场当前状态
if ( /* 建造中 */) {
// 返回给客户端当前时间
const leftTime = building.startTime - currentTime
res.body = leftTime
} else {
// 建造完毕
store.woodIncrement += 100
}

Configuration Synchronization

To do the front and rear ends arranged synchronized may be configured individually managed front end up sharing, such as a new profile, designed to store game information:

export const buildings = {
wood: {
name: "..",
maxLevel: 100,
increamentPerLevel: 50,
initIncreament: 100
}
/* .. and so on .. */
};

Although this multiplexed configuration, the front and rear ends have some common logic can be reused, such as architectural state is determined according to building construction time, construction of production is determined after N seconds the like. The Serverless brought further optimization of space.

Games in Serverless environment

Imagine, you can size the server to function code execution, we can abstract game logic:

/ 根据建筑建造时间判断建筑状态
export const getBuildingStatusByTime = (instanceId: number, time: number) => {
/**/
};

// 判断建筑生产量
export const getBuildingProduction = (instanceId: number, lastTime: number) => {
const status = getBuildingStatusByTime(instanceId, new Date().getTime());
switch (status) {
case "building":
return 0;
case "finished":
// 根据 (当前时间 - 上次打开时间)* 每秒产量得到总产量
return; /**/
}
};

// 前端 UI 层,每隔一秒调用一次 getBuildingProduction 函数,及时更新生产数据
// 前端入口函数
export const frontendMain = () => {
/**/
};

// 后端 根据每次打开时间,调用一次 getBuildingProduction 函数并入库
// 后端入口函数
export const backendMain = () => {
/**/
};

PASS use the service, the front and rear side logic to write together, it will be uploaded to the FAAS service getBuildingProduction function segment, so that you can share the front and rear side logic simultaneously!

In the folder view, you can do the following structure plan:

.
├── client # 前端入口
├── server # 后端入口
├── common # 共享工具函数,可以包含 80% 的通用游戏逻辑

Some people may ask: before and after the end of the shared code there is more than Serverless can.

Indeed, if the code is abstract good enough, there is a mature engineering program support, is a code that can be exported to the browser and the server, respectively. But Serverless function of particle size on the front and rear end features also fit the concept of code reuse, it appears likely to promote wider front and rear side code reuse, although this is not a new invention, but enough to be called a great change.

Perspective front and rear ends

For front-end developer, you will find background service becomes simple. For the back-end developers, service discovery made thick, the challenge more.

Simpler background service

ECS server in the traditional leasing, environmental and AliyunOS choose CentOS is sufficient annoying. Individual developers, we want to build a complete continuous integration service is very difficult and many choices faced by the dazzling:

  • Yes, local database server's direct-developed database server installation and other services.

  • Docker can be installed locally connected to the local database services, will be packaged into the environment mirroring the overall deployment to the server.

  • The separation of the front and rear side code, the server code at the front end of the development of local, server-side code.

Even the stability of the server and other tools needed to manage PM2. When the server under attack after the restart, disk failure, open complex table or landing through a Shell operation to recover. This is how people concentrate to focus on to do it?

Serverless solve this problem, because we want to upload just a snippet, no longer need to face the problem server environment, system environment, resources, external services are also packaged BAAS system support.

In fact, before Serverless out, there are many back-end team used FAAS idea to simplify the development process.

In order to reduce the time to write back-end business logic, environment, interference deployment issues, many teams will be abstracted into a business logic blocks (Block), corresponds to the code fragment or Blockly, these blocks can be independently maintain, publish, and finally the code snippet into the main program, or dynamic loading. If accustomed to this way of development, it is also easier to accept Serverless.

      

Thicker background service

Standing backstage point of view, things become more complicated. Relative to the server and provides a simple container, now shields the user execution environment, the service made thicker.

I learned through a number of articles, Serverless the implementation still faces some challenges as follows:

  • Serverless manufacturers achieve many different types of business do you want to deploy cloudy, need to smooth out differences.

  • Mature PASS service is actually a pseudo-Serverless, how to follow the standardization.

  • FAAS cold start to reload code, dynamic allocation of resources, resulting in a cold start slow, in addition to warm-up, but also need to optimize the way the economy.

  • For high concurrency (such as dual 11 spike) applications without the capacity to assess the scene is a very dangerous thing, but if you really can do it perfectly elastic technology, eliminating the need to worry about the capacity assessment.

  • Stock of how to migrate applications. Serverless service industry companies have not solved the problem most of the stock of application migration.

  • Serverless features lead-free status, and complex Internet applications are stateful, so the challenge in state support without changing development habits.

Fortunately, these problems have been in active treatment, and many solutions have been landing

Benefits Serverless challenge to bring back more than facing:

  • To promote the integration of front and rear end. Further lower the threshold Node write server-side code, eliminating the cost of learning application operations. I have encountered their own application database service is migrated to another room which led to the application service interruptions, and never need to worry about, because the database as a BAAS services, which do not need to be concerned about the deployment, whether across the room, and how do the migration.

  • Improve the efficiency of resource use. Put an end to the exclusive use of resources, and replaced with on-demand loading must be able to reduce unnecessary consumption of resources, and will be shared equally to service each machine cluster, leveled CPU level cluster.

  • Lowering the threshold of using a cloud platform. No need to operation and maintenance, flexible expansion, according to the value of service, high availability, the ability to attract more customers at the same time, fully-demand billing features also reduce the user cost, to achieve a win-win.

Serverless try to take advantage of open service

      One of the underlying BI analysis platform is the ability to visualize structures.

So the ability to visualize how to build open it? Relatively easy to do now is open assemblies, after all, can be relatively decoupled front end and back-end design, the use of AMD loading system is more mature.

Now the challenge is to open a back-end capability encounter, because when there is demand for customized access capability, you may need custom logic back-end data processing. At present can do is use maven3, jdk7 up a local development environment test, if you want on-line, back-end need help students.

If the backend to build a unique Serverless BAAS service, then it can be the same as the front end assembly line Coding, debugging, and even gray hair pre-release testing. Now developers have a lot of front-end cloud mature exploration, Serverless front and rear side code can be unified development experience in the cloud, without the need to care for the environment.

    Serverless Application Architecture Design

    

Read some Serverless application architecture diagram, we found that most businesses can apply such an architecture diagram:

your 1

The abstract business function into one FAAS function, database, caching, acceleration and other services abstracted into BAAS service.

Restful provide upper or event trigger mechanism calls, correspondence to different end (PC, mobile terminal).

Want to expand platform capabilities, as long as do open (components of access) on the end of FAAS services do open (backhaul) can be.

   

Benefits and challenges

    Serverless brings benefits and challenges, we stand in the front angle chat.

Benefits One: Focus on the front end of the front end more technical experience, without the need to have much knowledge management applications.

Recently read a lot of front-end predecessors wrote a summary of the text, the greatest experience is to remember "front-end in the past few years in the end play what role." We tend to exaggerate their sense of presence, in fact, the meaning of existence is to solve the front-end human-computer interaction issues, most scenes, is a kind of icing on the cake, but not required.

Remember you most proud of work experience, may be mastered knowledge Node operation and maintenance applications, front-end engineering system construction, research and development to optimize performance, such as the development of standards, but the real onset of the business section, is the one you thought that it was the least It is worth mentioning that the business code. Front-end spend too much time around technology, and reduce a lot of thinking to business interactions.

Even large companies, it is difficult to recruit both skilled use Nodejs, but also has extensive knowledge of the operation and maintenance people, but also asked him to front-end technology skills, deep understanding of the business, almost can not have both fish and bear's paw.

Serverless can effectively solve this problem, students only need to write front-end JS code without having to master any He Yunwei knowledge, you can quickly realize their full set of ideas.

Indeed, to understand the server knowledge is necessary, but standing on the perspective of a reasonable division of labor, it should focus on the front end of the front end technology. The core competence of the front end or bring business value, and will not end with a little more understanding of the operation and maintenance knowledge be supplemented, on the contrary, it will devour us this time can bring more business value.

Languages ​​evolve, evolution of the browser, the server evolution, are from simple to complex, to the bottom of the packaging process, and operation and maintenance Serverless backend + as a whole further packaging process.

   

Receipts: code logic arrangement brings highly multiplexed, maintainable, the ability to cloud + client expansion.

Before a lot of teams tried to make the interface use GraphQL "more flexible", and Serverless is a more complete solution.

My own team tried GraphQL program, but because business is very complex and difficult to use a standard model to describe the needs of all scenarios, and therefore not suitable for use GraphQL. Blockly precisely set based on visual back-end development platform stuck with it, and has made remarkable development Efficiency. This Blockly After almost universal abstraction can be replaced by Serverless. So Serverless can be solved in complex scenes back-end development, Improve Efficiency problems.

Serverless cloud development after the fusion, can be further visualized adjustment function execution order, the dependency logical layout.

  Before I use advertising in Baidu data processing team through this platform computing log off, each compute node after MapReduce through visualization, you can easily see which node in the event of a fault blocking, you can also see the implementation of the longest link, and is each node reassigned to perform weight. Even logical layout can not solve all the pain points of development, but will be able to accomplish a great deal in a specific business scenario.

     

Challenge one: Serverless completely eliminated the back end of the threshold of the front turn?

Node students write front-end code is most likely to commit complaint is out of memory.

Browser + Tab is a natural throw-off scenario, UI components and logic creation and destruction is also very frequently, so students rarely front-end, it is not need to care about GC problems. The GC is a long habit in the back-end development scenario, therefore Nodejs program buffer overflow is our greatest concern.

Serverless applications are dynamically loaded, it will no longer release, so in general do not need to worry too much about GC problems, even if memory overflow, the process may have to be released before the memory is full, or abnormality is detected Kill forced out .

But after loading and release FAAS function is completely controlled by the cloud, a handy function for a long time do not uninstall also possible, therefore FAAS function or pay attention to control side effects.

So Serverless Although the smooth operation and maintenance of the environment, but the server also need to understand the basics, must be aware of the code to run in the front or back end.

Challenge 2: Performance Issues

Serverless cold start can lead to performance problems, and let the business side take the initiative to perform frequency or performance requirements of the program, and then open the warm service again dragged into the research and development operation and maintenance of the abyss.

Even the industry's most mature Serverless Amazon cloud services, can not do business completely do not care about call frequency, it can easily cope with the spike scene.

So now Serverless may be more suitable to use in conjunction with the appropriate scene, rather than force any application to apply Serverless.

Although you can run regularly FAAS services to ensure that the program has been Online, but I believe that this is contrary to the concept of Serverless.

Three challenges: how to ensure the code migration

There is a classic description of Serverless positioning Figure:
TU 2

Network, storage, services, virtual home, operating systems, middleware, runtime, the data do not need to care about, and even the application layer only need to care about which part of the function, without the need for additional care such as starting, destroyed part.

This is when the front always take advantage of, but you can turn considered a disadvantage. When your code is completely dependent on a public cloud environment, you will lose the power to control the overall environment, and even the code can only run on a specific platform to the cloud.

BAAS service specification different cloud platforms may be different, FAAS entrance, implementation may be different, want to adopt cloudy deployment must overcome this problem.

Now many are considering doing Serverless platform standardization, but there are some bottom-up tool library erase some differences, such as Serverless Framework and so on.

The entry function we write FAAS function, but also try to write platform-bound lighter, the actual entrance in common, such as the main function.

 

3. Summary

Serverless value than the big challenge, the idea can really solve a lot of R & D performance issues.

But the Serverless still in its early stage of development, the domestic Serverless also in trial stage, but there are many restrictions execution environment, that is not fully realized concept Serverless better, so if anything will set up stepped pit.

Probably in 3-5 years, these pits are filled, then fill the hole you choose to join the army, or to vote for a scene using the Serverless it right?

 

Guess you like

Origin www.cnblogs.com/zhouyideboke/p/11671318.html