Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to carry out Serverless Application practice and typical case Analysis

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to carry out Serverless application practice and typical case analysis. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Advantages and value of Serverless

Why do we devote so much time and energy to Serverless? Because we firmly believe that one of the future trends of cloud computing is Serverless. Because Serverless makes the application of cloud services easier and more efficient. For example, when deploying an application with a CVM, you should not only build and maintain the environment, but also evaluate the resource usage of the business, especially for operational activities, if the evaluation is not accurate, it may result in a huge waste of resources. or the service may be blown up, or even offline.

And Serverles can be used on demand, making the business perfectly flexible and scalable, which is simply not better for operation and maintenance students. And unlike prepaid instances, Serverless is the pay as you go model, which takes up resources only when the business is running, and charges only when the source is occupied. To put it simply, I pay as much as I actually use. This billing mode has obvious advantages for services with obvious peaks and troughs.

In addition, the development of cloud computing must make users more focused on the business. As far as operation and maintenance is concerned, those tedious resource maintenance work that has no core value for business development can be offload to cloud vendors, so that they can pay more attention to operation and maintenance at the business level. This is the value of Serverless, which not only minimizes the cost of using the cloud, but also speeds up the launch process to the greatest extent.

We can also review the emergence and development of cloud computing in recent years, compared with self-built IDC, users are more focused on business, and the use of resources is more and more efficient, and Serverless has achieved the extreme of these advantages.

Let's take a brief look at how cloud functions make up the Serverless architecture and how Serverless applications run.

In practice, developers can use WEB IDE or local IDE to complete code development, and then package and deploy the code and related dependencies to the cloud function platform through online or plug-ins or tools. In the code, we can call the back-end BaaS like traditional development methods, such as accessing databases, object storage, message queues, third-party service interfaces, and so on. Computing logic and back-end services together constitute the so-called Serverless application architecture.

According to the request method provided by the platform, the end user triggers the business code deployed on the cloud function platform, such as sending http requests, and the platform will pull up the corresponding computing resources to run the user code according to the number of user requests. The platform will ensure the availability and flexibility of resources, so users only need to focus on the business and its operation.

Building REST API based on Serverless

Let's move on to today's topic. First of all, let's take a look at the REST API scene. Serverless Framework will be used here to assist in development and deployment. With the SCF component of Serverless Framework, we can quickly deploy locally developed REST API applications to the cloud. We just need to write the corresponding yaml in advance. Serverless Framwork will quickly create cloud resources such as cloud functions and API gateways based on the configuration information in yaml.

Next, share the practice of Jiang Entertainment Interactive Serverless API. Will be shared from the following three aspects

Why migrate to Cloud function?

Value after migration

Some experience after using Cloud function

About a year ago, Jiang Yu Interactive planner designed a function in which the behavior of a server would trigger a system notification to be sent to the chat channel. In theory, there is no problem with this design, but without considering the scale, I didn't know it had such a function. After being online, the chat system suddenly had a 20-fold impact on the number of requests, and requests began to queue in large numbers. A sentence sent by the player will not be delivered until a minute later.

Therefore, the emergency plus server diversion has survived this wave of activity. After reviewing how to avoid this peak of sudden requests, the number of hard-heap servers was definitely not good. At that time, the direction was to consider the following aspects: elastic scaling, containerization, and cloud functions.

In the end, the cloud function is chosen because it is naturally suitable for stateless Http service scenarios.

First of all, in terms of ease of deployment, you only need to focus on the code level, ignoring the concepts of container, image, and server.

The second is how much to spend. When there is no request in the middle of the night, there is no cost.

Finally, no matter how many requests, as long as the resource limit allows, it can be supported. Of course, it is limited to the cloud function layer. So I decided to try the cloud function first.

It took the team less than a month to figure out the basic usage of the cloud function and migrate the interface for players to pull historical messages. It was very smooth and there was no problem with it, so it decided to migrate as a whole.

This is a great solution for both cost and performance. Since the migration, the API part of the chat service is very stable, with more and more game users, there is no need to consider the carrying capacity, and the overall cost can always be maintained at a relatively low level. Occasionally encounter extreme demand peak, also can survive normally, will not cause avalanche situation.

In addition, it is also convenient to combine cloud functions with other systems, such as message queues and log systems. There is also a timing trigger, which directly replaces the previous method of finding a server to run some scheduled tasks with crontab. And we are also using cloud functions to do some other peripheral systems to reduce the complexity of the game server as much as possible.

From the programmer's point of view. The use of cloud functions allows developers to focus more on the optimization of the code itself, rethink the nature of requirements and reorganize their own ideas. For example, what to do in the loop, whether to optimize SQL when querying the database, whether to release memory manually when large data is clearly not used, and so on. This is of great benefit to the improvement of the technical level of developers. And the positive feedback is a significant reduction in cost.

The combination of Serverless and server rendering

Next, let's take a look at the SSR scene. In the earliest days, the front-end application was actually SSR, and the Html page was generated by the server and sent to the browser. Later, in order to improve the engineering efficiency, the development mode of component and MVVM was introduced in the front-end, and then there was CSR, such as a single-page application, which completed rendering by loading JS and CSS on the browser side. However, we also find that single-page applications are not SEO-friendly. In addition, the loading time of the first screen of single-page applications is longer, especially when the network is worse.

So some companies turn to SSR again in order to optimize the user experience or SEO. But for the front-end students, I need to run the back-end, so I have to operate and maintain a node server cluster, which is a headache, and I also need to know a lot about the back-end, such as load balancing and high concurrency. With the help of Serverless, the burden of the front-end students can be liberated perfectly.

The cheetah mobile front-end team started using React,2017 in 2016 and began to study and try React Server Render. During the same period, Facebook's website has been implemented using Isomorphic technology, and the performance is very good. In order to meet the company's business needs and technology heritage, the team developed the cheetah front-end technology framework Koot.js, which has become the main technical solution of the cheetah front-end.

Koot.js is based on React, Koa and Webpack, in which Node built by Koa is used as a development service and SSR service for deployment. Page rendering is mainly a set of code completed by React+Redux, which is common in browser environment and Node environment. It uses Webpack programmability to dynamically generate configuration and execute it, packaging multi-scenario (development, testing and online environment, etc.) and multi-terminal code (front-end, server) deployment.

When landing, the cheetah mobile team encapsulated the self-developed Koot.js using Serverless Framework and made a Serverless component, so that it can be directly reused when other business scenarios need to be used, which can save a lot of costs, avoid repeated wheels and reduce the probability of error.

The landing of SSR projects is usually not very smooth, and server technical capabilities are required for project deployment in order to communicate smoothly with OPS. Therefore, the project landing requires front-end students not only to master back-end development capabilities, but also to consider operation and maintenance technology, concurrency and other issues, which has higher requirements for front-end technology students.

In this case, last year we began to contact Serverless technology, Serverless technology can reduce the front-end technical capabilities of the server and operation and maintenance, but the requirements are more suitable for most front-end teams that want to do SSR. The team investigated several major cloud vendors' Serverless services, and after a comprehensive comparison, Tencent Cloud was selected as the Serverless service support for SSR.

Tencent Cloud Serverless provides comprehensive component support, which is basically seamlessly integrated with Serverless Framework, and the surrounding communities and ecological support are also in place, so there will be fewer pitfalls in the process of use. It is smoother when the platform is selected, because Serverless Framework provides a lot of standardized interfaces and makes it easier to encapsulate Koot.js Serveless components.

Constructing Audio and Video Transcoding Scheme with Serverless

Finally, audio and video transcoding scenarios, the combination of cloud function and object storage COS, it is very convenient to upload audio and video to COS for automatic transcoding. Custom transcoding logic can be implemented based on ffmpeg in SCF, and CDN prefetch can be triggered automatically for files sent back to COS after transcoding.

With the powerful linkage capability of SCF, video upload, video processing, image processing and storage scenes are organically integrated. Users can customize the transcoding function to help customers quickly build customized task processing capabilities and make up for the functional blind spots of current individual cloud services. Ffmpeg services can be easily migrated from physical machines, cloud hosts or containers to cloud functions. Cloud functions provide a wealth of metering methods to help users gain significant cost advantages.

During the summer vacation every year, there are a large number of students studying on the platform of New Oriental. In the past, we all realized the storage and transcoding logic of audio and video courses based on server and NFS in the self-built computer room. However, due to the large summer traffic, the servers in IDC may not be able to meet the computing needs, and the hardware procurement cycle of self-built services is long. It is expected to find a flexible method that can not only support rapid business deployment, but also efficiently complete the transcoding function.

After comparison and selection, the cloud function of Tencent Cloud is finally selected. Cloud function + COS is used on the cloud to support auto scaling. Even if all local traffic is cut to the cloud, it can be fully loaded. Then a task scheduling module will be added to the new business process. When the business traffic comes, the traffic can be automatically or manually imported into the self-research service and cloud service respectively, and many highly available technologies have been added to the process, such as full link tracking through task TraceID, local recalculation of cloud computing failure, and so on. In the new scheme, cloud service development is very simple, and does not need to invest too much operation and maintenance effort, the cost is relatively low, pay as much as you use. Serverless is the inevitable trend of cloud computing, and it is also one of the cloud native application scenarios. We look forward to having more attempts and sharing.

The above is the editor for you to share how to carry out Serverless application practice and typical case analysis, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report