Nodejs v8.log分析出来的结果,如何解释呢?跪请懂得入帮忙说两句
Nodejs v8.log分析出来的结果,如何解释呢?跪请懂得入帮忙说两句
有些东西完全卡不懂,不知道哪里是什么意思,敬请指明两三条关键的意思(内容太长,我截取了每个项目靠前的几行)。
Code move event for unknown code: 0x3f5ed8208e60
Statistical profiling result from v8.log, (53903469 ticks, 94 unaccounted, 0 excluded).
[Unknown]:
ticks total nonlib name
94 0.0%
[Shared libraries]:
ticks total nonlib name
51661492 95.8% 0.0% /lib64/libc-2.12.so
917328 1.7% 0.0% /usr/lib64/libv8.so.3.14.5
274401 0.5% 0.0% /lib64/libpthread-2.12.so
56317 0.1% 0.0% /usr/bin/node
[JavaScript]:
ticks total nonlib name
463447 0.9% 48.6% LazyCompile: *exports._unrefActive timers.js:440
20906 0.0% 2.2% LazyCompile: *Socket._write net.js:619
20324 0.0% 2.1% LazyCompile: *Writable.write _stream_writable.js:162
18886 0.0% 2.0% LazyCompile: *append _linklist.js:63
18276 0.0% 1.9% LazyCompile: *remove _linklist.js:47
10186 0.0% 1.1% LazyCompile: *emit events.js:53
10047 0.0% 1.1% LazyCompile: *onwrite _stream_writable.js:248
9873 0.0% 1.0% KeyedLoadIC: A keyed load IC from the snapshot {1}
8424 0.0% 0.9% LazyCompile: *_nextTick node.js:479
7735 0.0% 0.8% LazyCompile: p.encodeInt /home/node21/net/node-amf/bin.js:53
7296 0.0% 0.8% Stub: StringAddStub
7198 0.0% 0.8% Builtin: A builtin from the snapshot {1}
6321 0.0% 0.7% LazyCompile: onread net.js:496
5708 0.0% 0.6% LazyCompile: *ChatPipe.sendBytes /home/node21/net/chat/ChatPipe.js:343
5613 0.0% 0.6% LazyCompile: Dictionary.each /home/node21/base/Dict.js:84
5518 0.0% 0.6% Stub: CallFunctionStub_Args0
5334 0.0% 0.6% LazyCompile: *Buffer buffer.js:156
5163 0.0% 0.5% LazyCompile: *Socket.write net.js:612
[C++]:
ticks total nonlib name
[GC]:
ticks total nonlib name
95380 0.2%
[Bottom up (heavy) profile]:
Note: percentage shows a share of a particular caller in the total
amount of its parent calls.
Callers occupying less than 2.0% are not shown.
ticks parent name
51661492 95.8% /lib64/libc-2.12.so
[Top down (heavy) profile]:
Note: callees occupying less than 0.1% are not shown.
inclusive self name
ticks total ticks total
51620474 95.8% 51620474 95.8% /lib64/libc-2.12.so
1580415 2.9% 6321 0.0% LazyCompile: onread net.js:496
1421489 2.6% 710 0.0% LazyCompile: *Readable.push _stream_readable.js:116
1420357 2.6% 2339 0.0% LazyCompile: *readableAddChunk _stream_readable.js:136
1409497 2.6% 485 0.0% LazyCompile: *emitReadable _stream_readable.js:410
1408141 2.6% 694 0.0% LazyCompile: *emitReadable_ _stream_readable.js:425
1406787 2.6% 2711 0.0% LazyCompile: *emit events.js:53
1365271 2.5% 1470 0.0% LazyCompile: *<anonymous> _stream_readable.js:759
1349438 2.5% 448 0.0% LazyCompile: *emit events.js:53
1122331 2.1% 189 0.0% LazyCompile: b native v8natives.js:1582
1116406 2.1% 89 0.0% LazyCompile: *onData /home/node21/net/chat/ChatPipe.js:104
993799 1.8% 104 0.0% LazyCompile: *put /home/node21/net/GLBuffer.js:82
990933 1.8% 1870 0.0% LazyCompile: proc /home/node21/net/GLBuffer.js:129
982671 1.8% 779 0.0% LazyCompile: *emit events.js:53
976041 1.8% 114 0.0% LazyCompile: b native v8natives.js:1582
974665 1.8% 1918 0.0% LazyCompile: ChatPipe.onReceivePackData /home/node21/net/chat/ChatPipe.js:124
663748 1.2% 632 0.0% LazyCompile: ~ChatPipe.CHAT_CHANGE_INFO /home/node21/net/chat/ChatPipe.js:273
652600 1.2% 44 0.0% LazyCompile: *ChatPipe.sendAll /home/node21/net/chat/ChatPipe.js:437
632741 1.2% 4051 0.0% LazyCompile: Dictionary.each /home/node21/base/Dict.js:84
603232 1.1% 2985 0.0% LazyCompile: *<anonymous> /home/node21/net/chat/ChatPipe.js:440
596431 1.1% 4166 0.0% LazyCompile: *ChatPipe.sendBytes /home/node21/net/chat/ChatPipe.js:343
591471 1.1% 3106 0.0% LazyCompile: *Socket.write net.js:612
580448 1.1% 13092 0.0% LazyCompile: *Writable.write _stream_writable.js:162
556373 1.0% 12726 0.0% LazyCompile: *Socket._write net.js:619
255119 0.5% 2833 0.0% LazyCompile: *createWriteReq net.js:658
128272 0.2% 128272 0.2% /usr/lib64/libv8.so.3.14.5
103480 0.2% 103480 0.2% /lib64/libpthread-2.12.so
235758 0.4% 194003 0.4% LazyCompile: *exports._unrefActive timers.js:440
242571 0.5% 1560 0.0% LazyCompile: updateRecord /home/node21/net/chat/ChatDB.js:41
129827 0.2% 236 0.0% LazyCompile: *newQuery /home/node21/net/chat/ChatDB.js:167
129267 0.2% 379 0.0% LazyCompile: *Pool.getConnection /home/node_modules/mysql/lib/Pool.js:22
127070 0.2% 672 0.0% LazyCompile: *acquireConnection /home/node_modules/mysql/lib/Pool.js:72
125737 0.2% 516 0.0% LazyCompile: *ping /home/node_modules/mysql/lib/Connection.js:188
125137 0.2% 278 0.0% LazyCompile: *ping /home/node_modules/mysql/lib/protocol/Protocol.js:63
119761 0.2% 1527 0.0% LazyCompile: *Protocol._enqueue /home/node_modules/mysql/lib/protocol/Protocol.js:128
70898 0.1% 727 0.0% LazyCompile: *Protocol._startSequence /home/node_modules/mysql/lib/protocol/Protocol.js:337
92510 0.2% 5 0.0% LazyCompile: ~put /home/node21/net/GLBuffer.js:82
92262 0.2% 137 0.0% LazyCompile: proc /home/node21/net/GLBuffer.js:129
91580 0.2% 63 0.0% LazyCompile: *emit events.js:53
90897 0.2% 12 0.0% LazyCompile: b native v8natives.js:1582
90767 0.2% 144 0.0% LazyCompile: ChatPipe.onReceivePackData /home/node21/net/chat/ChatPipe.js:124
66410 0.1% 52 0.0% LazyCompile: ~ChatPipe.CHAT_CHANGE_INFO /home/node21/net/chat/ChatPipe.js:273
65207 0.1% 9 0.0% LazyCompile: *ChatPipe.sendAll /home/node21/net/chat/ChatPipe.js:437
63369 0.1% 421 0.0% LazyCompile: Dictionary.each /home/node21/base/Dict.js:84
60536 0.1% 317 0.0% LazyCompile: *<anonymous> /home/node21/net/chat/ChatPipe.js:440
59816 0.1% 403 0.0% LazyCompile: *ChatPipe.sendBytes /home/node21/net/chat/ChatPipe.js:343
59284 0.1% 330 0.0% LazyCompile: *Socket.write net.js:612
58658 0.1% 1197 0.0% LazyCompile: *Writable.write _stream_writable.js:162
56834 0.1% 1197 0.0% LazyCompile: *Socket._write net.js:619
54226 0.1% 46231 0.1% LazyCompile: *exports._unrefActive timers.js:440
245674 0.5% 37 0.0% LazyCompile: listOnTimeout timers.js:79
245319 0.5% 15 0.0% LazyCompile: ~callbackWrapper /home/node21/node_modules/cron/lib/cron.js:379
223361 0.4% 2 0.0% LazyCompile: *CronJob.onTick /home/node21/app.js:52
223358 0.4% 7 0.0% LazyCompile: *self.checkOnlineSendQueue /home/node21/net/chat/ChatOnlineList.js:23
192589 0.4% 2 0.0% LazyCompile: *NDataPack /home/node21/net/chat/NDataPack.js:14
154384 0.3% 0 0.0% LazyCompile: *NDataObject.writeExternal /home/node21/net/DataTypeDefine.js:25
154367 0.3% 122 0.0% LazyCompile: NDataObject.writeSingle /home/node21/net/DataTypeDefine.js:90
153798 0.3% 910 0.0% LazyCompile: NDataObject.writeSingle /home/node21/net/DataTypeDefine.js:90
152271 0.3% 1575 0.0% LazyCompile: *NDataObject.writeExternal /home/node21/net/DataTypeDefine.js:25
150033 0.3% 493 0.0% LazyCompile: NDataObject.writeSingle /home/node21/net/DataTypeDefine.js:90
140222 0.3% 441 0.0% LazyCompile: amf3Object /home/node21/net/ByteBuffer.js:52
136819 0.3% 2281 0.0% LazyCompile: AMFSerializer.writeObject /home/node21/net/node-amf/serialize.js:217
80006 0.1% 709 0.0% LazyCompile: *AMFSerializer.writeValue /home/node21/net/node-amf/serialize.js:89
163153 0.3% 163153 0.3% /usr/lib64/libv8.so.3.14.5
125439 0.2% 3790 0.0% LazyCompile: *afterWrite net.js:706
104488 0.2% 88314 0.2% LazyCompile: *exports._unrefActive timers.js:440
67495 0.1% 2776 0.0% LazyCompile: afterWrite net.js:706
60000 0.1% 51685 0.1% LazyCompile: *exports._unrefActive timers.js:440
分析 v8.log
文件可以帮助我们了解 Node.js 应用程序的性能瓶颈。以下是对提供的 v8.log
分析结果的一些关键点解释:
1. 共享库(Shared Libraries)
共享库中的函数调用占用了绝大部分的时间,这可能意味着你的应用程序在运行时大量依赖这些库。例如:
/lib64/libc-2.12.so: 51661492 (95.8%)
这意味着大约95.8%的时间都花在了标准C库上。
2. JavaScript 代码
在JavaScript部分中,我们可以看到一些频繁执行的函数。例如:
LazyCompile: *exports._unrefActive timers.js:440: 463447 (0.9%)
这个函数在 timers.js
的第440行被编译并执行了463,447次,占用了0.9%的总时间。这表明该函数可能是性能瓶颈之一。
3. C++代码
C++代码部分较少,但如果有显著的占用率,可以进一步检查对应的C++代码。
/lib64/libpthread-2.12.so: 103480 (0.2%)
4. 堆栈跟踪(Stack Trace)
堆栈跟踪部分提供了更详细的调用层次结构,有助于定位具体的性能瓶颈。例如:
LazyCompile: *onread net.js:496: 1580415 (2.9%)
该函数在 net.js
的第496行被编译并执行了1,580,415次,占用了2.9%的总时间。进一步深入分析,可以看到其调用链:
LazyCompile: *readableAddChunk _stream_readable.js:136: 2339 (0.0%)
示例代码
假设我们发现 timers.js
的 _unrefActive
函数是一个性能瓶颈,我们可以考虑优化或重构该函数。以下是一个简单的示例,展示如何通过减少不必要的调用来优化性能:
// Original function
function _unrefActive() {
// Some heavy operations
// ...
}
// Optimized version
function optimizedUnrefActive() {
if (!someCondition()) return; // Add a condition to avoid unnecessary calls
// Heavy operations
// ...
}
// Usage
if (someCondition()) {
optimizedUnrefActive();
} else {
// Alternative logic
}
总结
通过对 v8.log
的分析,我们可以识别出哪些函数或库在运行时占用了大量的时间。这有助于我们针对性地进行性能优化,从而提高应用的整体性能。
自己顶
目前把一些.each(function(){})类似的函数改写为临时函数,有升有降,总体还升,继续检测中
根据你提供的 v8.log
文件内容,这里是对其中一些关键部分的解释:
1. 总览
文件开头显示总共统计到了 53903469
次计数(ticks),其中有 94
次未被计算到(unaccounted),0
次被排除(excluded)。
2. 共享库
共享库部分展示了哪些共享库占用了大部分时间:
/lib64/libc-2.12.so: 51661492 ticks (95.8%)
/usr/lib64/libv8.so.3.14.5: 917328 ticks (1.7%)
/lib64/libpthread-2.12.so: 274401 ticks (0.5%)
/usr/bin/node: 56317 ticks (0.1%)
从这些数据可以看出,libc
库占用了绝大部分时间,说明程序中有大量的标准库调用。
3. JavaScript 代码
这部分显示了在 JavaScript 代码中花费的时间:
LazyCompile: *exports._unrefActive timers.js:440: 463447 ticks (0.9%, 48.6%)
LazyCompile: *Socket._write net.js:619: 20906 ticks (0.0%, 2.2%)
LazyCompile: *Writable.write _stream_writable.js:162: 20324 ticks (0.0%, 2.1%)
例如,timers.js
中的 _unrefActive
方法占用了一定比例的时间。这可能意味着定时器操作是性能瓶颈之一。
4. C++ 代码
这部分显示了在 C++ 代码中花费的时间,但你的文件中没有相关内容。
5. 垃圾回收
垃圾回收部分显示了在垃圾回收上花费的时间:
GC: 95380 ticks (0.2%)
6. 上下文切换
上下文切换部分显示了调用栈的顶部信息:
/lib64/libc-2.12.so: 51620474 ticks (95.8%)
这再次强调了 libc
库对性能的影响。
示例代码优化建议
针对 timers.js
和 net.js
中的方法,可以考虑以下优化:
- 减少不必要的定时器:检查是否可以减少或合并定时器。
- 异步优化:确保使用非阻塞 I/O 操作,避免阻塞主线程。
- 减少不必要的函数调用:检查是否有重复或不必要的函数调用。
希望这些解释能帮助你理解 v8.log
的输出并进行相应的优化。