@@ -34,6 +34,7 @@ function wsFiller(ws, req) {
34
34
ws . logReportTimer = null ;
35
35
ws . __tempSend = ws . send ;
36
36
ws . reportIndex = 1 ;
37
+ ws . messageTriggerCount = 0 ;
37
38
38
39
ws . send = function ( message ) {
39
40
if ( ws . readyState == WebSocket . OPEN ) {
@@ -49,19 +50,26 @@ function wsFiller(ws, req) {
49
50
ws . logKey = req . headers [ 'sec-websocket-key' ] || Math . random ( ) ;
50
51
}
51
52
53
+ function emitReportLog ( ws , type ) {
54
+ ws . upgradeReq . emit ( type ) ;
55
+ ws . messageTriggerCount = 0 ;
56
+ }
57
+
52
58
function reportWebSocketLog ( ws , isEnd ) {
53
59
// 这里触发log上报
54
60
const logLength = logger . getTextLength ( ) ;
55
61
// 每次上报log时,先看下Log多不多,不多的话,延迟上报下
56
62
clearTimeout ( ws . logReportTimer ) ;
57
63
if ( isEnd ) {
58
- ws . upgradeReq . emit ( 'reportLog' ) ;
64
+ emitReportLog ( 'reportLog' ) ;
59
65
} else if ( logLength > 30 ) {
60
66
// 立即上报
61
- ws . upgradeReq . emit ( 'reportLogStream' ) ;
67
+ emitReportLog ( 'reportLogStream' ) ;
68
+ } else if ( ws . messageTriggerCount > 9 ) {
69
+ emitReportLog ( 'reportLogStream' ) ;
62
70
} else {
63
71
ws . logReportTimer = setTimeout ( function ( ) {
64
- ws . upgradeReq . emit ( 'reportLogStream' ) ;
72
+ emitReportLog ( 'reportLogStream' ) ;
65
73
} , 5000 ) ;
66
74
}
67
75
}
@@ -186,6 +194,7 @@ function bind_listen(server) {
186
194
} ;
187
195
188
196
ws . on ( 'message' , function ( message ) {
197
+ ws . messageTriggerCount ++ ;
189
198
logger . debug ( 'server get message : ${message}' , {
190
199
message
191
200
} ) ;
0 commit comments