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 realize online remote debugging with Serverless

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to implement online remote debugging in Serverless, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Online debugging is a feature introduced by Cloud function to solve the problem that users set up a debugging environment locally is complex, and the cloud environment is not easy to locate.

Various services on the cloud cannot be fully simulated locally, and programmers have mostly encountered inconsistent results between local and remote environments, which is time-consuming and laborious to trace, which is not only inefficient, but also leads to a very depressing work experience. Therefore, whether the whole development process can be completed directly in the remote environment is the most direct means to enhance the development experience. However, after other problems are solved, the remote debugging function is the last kilometer.

The following will take a memory leak code as an example to show you how to use the cloud function online debugging feature to locate and solve problems. For Node10 and above versions of runtime, open the SCF console using Chrome browser, and you can see the entry for online debugging in the function code page.

Turn on debug mode

Use the Chrome browser to open the function code editing page, and you can see it on the remote debugging page. To ensure the debugging experience, enabling debug mode will modify part of the configuration of the function, including the function entering single-instance mode and changing the function timeout to 900 seconds. Be sure to confirm these adjustments before opening them.

After loading, the page will automatically display the entry file.

Can't find the file you need?

Use the shortcut keys Cmd + P (Mac) or Ctrl + P (Windows) to open the file you want. However, you may find that when debug mode is first turned on, the required files cannot be found in the list of open files. This is because for dynamic scripting languages, the debugger does not load everything, only the files that have been executed. Let's click on the test first and let the function run once. After running it once, we can open the file we need.

Set breakpoint

Click in front of the code to set the breakpoint, in the upper right corner of the tool can continue to execute, step execution, single-step execution and other operations, you can also flexibly start or disable the breakpoint.

Memory leak troubleshooting-memory snapshot

This section describes how to use the memory snapshot feature to troubleshoot memory leaks. The troubleshooting method of memory leak is roughly as follows: find the right time of the memory leak, take a snapshot of the memory before and after the leak, and judge the problem point of the memory leak by comparing the contents of the snapshot.

First, we switch the debug window to the Memory page and click the solid circle button at the top left to capture the memory snapshot.

In this way, we have a pre-run memory snapshot. Now let's execute the code that has a memory leak. This line of code has a global cache that has never been cleaned and takes up more and more memory as the call increases.

Then, we take a second memory snapshot, open the comparison page, through the analysis of the Delta value, we can find that the part of concatenated string has increased a lot, which may be problematic.

After opening it, you can find that there is a lot of "recording time" data stored in memory.

These repetitive data also means that there is a memory leak in the code, find the relevant content in the code, adjust it, and solve the problem of memory leak.

In addition to the console of SCF, you can also use Serverless Framework Dev mode to enable online debugging.

This is the answer to the question about how to realize online remote debugging in Serverless. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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