Nodeclipse / nodeclipse

Nodeclipse-1 : Eclipse plugin for Node.js, PhantomJS development (Nodeclipse core plugin); Maven and Gradle (with Android) plugins
https://nodeclipse.github.io/
158 stars 78 forks source link

Node.js Profiling #94

Open paulvi opened 10 years ago

paulvi commented 10 years ago

Standard Node.js comes without Profiling support, though this direction is to be useful

8 May 2012 CPU Profiling with Nodetime http://blog.nodetime.com/2012/05/cpu-profiling-with-nodetime.html

One of the reasons for slow load times is inefficient code, which uses a lot of CPU making everything else wait. This is especially painful in Node.js due to its single threaded model. First signes of the problem are high CPU times of requests, which is easily observable in Nodetime, where CPU times are provided for each request sample. Although, machine load can also indicate a problem. The logical next step is to locate what exactly blocks CPU and where is that function in the code.

V8 engine, on which Node.js is built, has a built-in sampling CPU profiler. It records where the instruction pointer was every millisecond and creates a call tree based on this. Although not exact, but the information is statistically sufficient to identify which functions spent the most time in CPU.

To run the profiler manually a few things must be done. d8 should be compiled separately and Node application should be started with --prof option. After starting, v8.log file will be created, which should be analyzed with special OS-specific tools packaged with Node. A couple of libraries are available, which allow starting and stopping V8 profiler via API.

Nodetime makes it increadably easy to use V8's CPU profiler. Just require('nodetime').profile() on the first line of your application and you're done. Normally you would start sending subsequent or parallel requrests to your server using ab, other tool of choice or just the browser, and while it's being done start the profiler from Nodetime's web console. Here is what it looks like in the web console (a screencast is available here):