How to use node Profiler

Source: Internet
Author: User

Wedge

When we write code, we tend to focus on the implementation of the function, and then perform performance testing, if the performance satisfies the demand, happy, otherwise, the path of optimization begins.

As a qualified cock silk yard, you should always keep in mind the performance optimization, even if you meet the needs, but also to think about whether it can be better.

However, JS, as a dynamic language, has a lot of differences with C + +. We know that the JS code is the JS engine dynamically compiled. One of the great advantages of dynamic languages is that the engine can re-tune the code that is already executing, especially the hot-spot function that is frequently called, based on the profile generated by the runtime (V8 's Crankshaft module), which is vaguely a closed-loop control in cybernetics, negative feedback. Finally found the use of textbook knowledge. wow haha ~ ~ ~

Do anything is a rule limit, JS Engine optimization JS code is no exception, if we can in the JS code to avoid using the JS engine can not optimize the format, undoubtedly can maximize the ability to play the engine.

Web-inspector inside the Cpu-profilor module can be very good evaluation of a JS function more than 10 years of the total project ratio, so you can stare at the top of the function to optimize. However, the native Web-inspector only gives the JS function's execution occupancy ratio, and does not list whether the function has been optimized, and if not, what the reason is.

After reading the JS engine V8 code, we present these very critical/useful information to the code farmer through Web-inspector. In this way, the top of the non-optimized function will need to be well repaired, and more importantly, the reason for not being optimized is also presented, so long as the right remedy is possible.

Download installation

After the installation is successful, the files are located in/usr/local/bin/node-profiler

Using the example
varhttp= require( 'http' ); HTTP.Createserver(function(req,Res) {Res.Writehead( $); Res.End( 'Hello world! ' );}).Listen(1334);
$ node-profiler server.jsstart agent for            commands... webkit-devtools-agent:websockets service Started on 0.0.0.0:9999  <= = Start successful

It appears as follows:

Error:listen eaddrinuse           <= = may be due to port occupancy

After successful startup, use Chrome (recommended) to manually open the URL (http://alinode.aliyun.com/profiler/inspector.html?host=localhost:9999&page=0) The following interface appears:

Default Collect javasript CPUprofile, click Start.

You can use a pressure test script to perform stress testing on the service to ensure more results:

# Here you can use WRK and other tools, such as AB

Click Stopto get the results as follows:

You can see more information about the function at run time.

UI meaning
UI Columns Signal
Self Exclusive Time
Total Inclusive Time
# of Hidden Classes Number of hidden classes
Bailout The reason for the last optimization to be extracted in V8
Function Function name Script:line

Red indicates that the function is not optimized, and the light green indicates that the function has been V8 optimized.

Precautions
    • The tool currently only supports the X64 platform (Linux, Mac, Win).
    • Do not deploy to a line, only for your own debugging use.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to use node Profiler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.