topbit 3.0.8 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.cn.md +2 -2
- package/README.md +2 -2
- package/demo/allow.js +28 -8
- package/demo/group-api.js +1 -1
- package/demo/group-api2.js +1 -1
- package/demo/monitor.js +81 -0
- package/package.json +1 -1
- package/src/extends/Http2Pool.js +143 -309
- package/src/extends/http2proxy.js +39 -141
- package/src/extends/proxy.js +16 -17
- package/src/monitor.js +102 -90
- package/src/topbit.js +8 -8
- package/test/test-route-sort.js +1 -1
- package/test/test-route2.js +1 -1
package/README.cn.md
CHANGED
|
@@ -915,7 +915,7 @@ app.run(1234)
|
|
|
915
915
|
//展示负载信息,需要通过daemon接口开启cluster集群模式
|
|
916
916
|
loadMonitor : true,
|
|
917
917
|
|
|
918
|
-
//负载信息的类型,text 、
|
|
918
|
+
//负载信息的类型,text 、null, obj, orgobj
|
|
919
919
|
//json类型是给程序通信使用的,方便接口开发
|
|
920
920
|
loadInfoType : 'text',
|
|
921
921
|
|
|
@@ -1921,7 +1921,7 @@ let hxy = new Http2Proxy({
|
|
|
1921
1921
|
weight: 10,
|
|
1922
1922
|
path : '/',
|
|
1923
1923
|
reconnDelay: 200, // 重连延迟
|
|
1924
|
-
|
|
1924
|
+
maxConnect: 2,
|
|
1925
1925
|
headers: {
|
|
1926
1926
|
'x-test-key': `${Date.now()}`
|
|
1927
1927
|
},
|
package/README.md
CHANGED
|
@@ -879,7 +879,7 @@ Full configuration options for app initialization are as follows. Please read th
|
|
|
879
879
|
// Display load info, requires enabling cluster mode via daemon interface
|
|
880
880
|
loadMonitor : true,
|
|
881
881
|
|
|
882
|
-
// Load info type: text,
|
|
882
|
+
// Load info type: text, null, obj, orgobj
|
|
883
883
|
// json type is for program communication, convenient for interface development
|
|
884
884
|
loadInfoType : 'text',
|
|
885
885
|
|
|
@@ -1882,7 +1882,7 @@ let hxy = new Http2Proxy({
|
|
|
1882
1882
|
weight: 10,
|
|
1883
1883
|
path : '/',
|
|
1884
1884
|
reconnDelay: 200, // Reconnection delay
|
|
1885
|
-
|
|
1885
|
+
maxConnect: 2,
|
|
1886
1886
|
headers: {
|
|
1887
1887
|
'x-test-key': `${Date.now()}`
|
|
1888
1888
|
},
|
package/demo/allow.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const Topbit = require('../src/topbit.js');
|
|
4
|
+
const npargv = Topbit.npargv
|
|
5
|
+
|
|
6
|
+
let {args} = npargv({
|
|
7
|
+
'--loadtype': {
|
|
8
|
+
name: 'load',
|
|
9
|
+
default: 'text',
|
|
10
|
+
limit: ['text', 'json', 'orgjson']
|
|
11
|
+
},
|
|
12
|
+
'--loadstdio': {
|
|
13
|
+
name: 'loadstdio',
|
|
14
|
+
default: false
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const app = new Topbit({
|
|
6
19
|
debug : true,
|
|
7
20
|
allow : new Set(['127.0.0.1']),
|
|
8
21
|
maxIPRequest: 2,
|
|
@@ -10,11 +23,11 @@ const app = new titbit({
|
|
|
10
23
|
useLimit: true,
|
|
11
24
|
maxConn: 2000,
|
|
12
25
|
//http2: true,
|
|
13
|
-
|
|
14
|
-
loadInfoType :
|
|
26
|
+
loadMonitor: true,
|
|
27
|
+
loadInfoType : args.load,
|
|
15
28
|
globalLog : true,
|
|
16
29
|
logType: 'stdio',
|
|
17
|
-
loadInfoFile : '/tmp/loadinfo.log'
|
|
30
|
+
loadInfoFile : args.loadstdio ? '' : '/tmp/loadinfo.log',
|
|
18
31
|
});
|
|
19
32
|
|
|
20
33
|
app.use(async (c, next) => {
|
|
@@ -65,7 +78,12 @@ app.get('/', async c => {
|
|
|
65
78
|
}, 'home');
|
|
66
79
|
|
|
67
80
|
app.get('/test', async c => {
|
|
68
|
-
c.
|
|
81
|
+
//await c.ext.delay(10)
|
|
82
|
+
let sum = 0
|
|
83
|
+
for (let i = 0; i < 1000000; i++) {
|
|
84
|
+
sum += Math.random() * i;
|
|
85
|
+
}
|
|
86
|
+
c.to({sum});
|
|
69
87
|
}, {group: 'test', name : 'test'});
|
|
70
88
|
|
|
71
89
|
app.post('/test', async c => {
|
|
@@ -95,4 +113,6 @@ app.use(async (c, next) => {
|
|
|
95
113
|
}, {pre: true, method: 'POST', name: 'transmit'});
|
|
96
114
|
|
|
97
115
|
|
|
98
|
-
app.
|
|
116
|
+
app.autoWorker(3)
|
|
117
|
+
|
|
118
|
+
app.daemon(2034, 1)
|
package/demo/group-api.js
CHANGED
package/demo/group-api2.js
CHANGED
package/demo/monitor.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Topbit = require('../src/topbit.js');
|
|
4
|
+
const npargv = Topbit.npargv
|
|
5
|
+
|
|
6
|
+
let {args} = npargv({
|
|
7
|
+
'--loadtype': {
|
|
8
|
+
name: 'loadtype',
|
|
9
|
+
default: 'text',
|
|
10
|
+
limit: ['text', 'json', 'orgjson', 'obj', 'orgobj']
|
|
11
|
+
},
|
|
12
|
+
'--loadstdio': {
|
|
13
|
+
name: 'loadstdio',
|
|
14
|
+
default: false
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
'--http2': {
|
|
18
|
+
name: 'http2',
|
|
19
|
+
default: false
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const app = new Topbit({
|
|
24
|
+
debug : true,
|
|
25
|
+
allow : new Set(['127.0.0.1']),
|
|
26
|
+
maxIPRequest: 2,
|
|
27
|
+
unitTime: 10,
|
|
28
|
+
useLimit: true,
|
|
29
|
+
maxConn: 2000,
|
|
30
|
+
http2: args.http2,
|
|
31
|
+
loadMonitor: true,
|
|
32
|
+
loadInfoType : args.loadtype,
|
|
33
|
+
globalLog : false,
|
|
34
|
+
logType: 'stdio',
|
|
35
|
+
loadInfoFile : args.loadstdio ? '' : '/tmp/topbit-loadinfo.log',
|
|
36
|
+
maxLoadRate: 0.56
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
app.get('/', async c => {
|
|
40
|
+
c.to('ok');
|
|
41
|
+
}, 'home');
|
|
42
|
+
|
|
43
|
+
app.get('/test', async c => {
|
|
44
|
+
//await c.ext.delay(10)
|
|
45
|
+
let sum = 0
|
|
46
|
+
for (let i = 0; i < 90000; i++) {
|
|
47
|
+
sum += Math.random() * i;
|
|
48
|
+
}
|
|
49
|
+
c.to({sum});
|
|
50
|
+
}, {group: 'test', name : 'test'});
|
|
51
|
+
|
|
52
|
+
app.post('/test', async c => {
|
|
53
|
+
c.to(c.body);
|
|
54
|
+
}, {group: 'test', name : 'test-post'});
|
|
55
|
+
|
|
56
|
+
app.post('/transmit', async c => {
|
|
57
|
+
c.to('ok');
|
|
58
|
+
}, 'transmit');
|
|
59
|
+
|
|
60
|
+
app.use(async (c, next) => {
|
|
61
|
+
let total = 0;
|
|
62
|
+
|
|
63
|
+
c.box.dataHandle = (data) => {
|
|
64
|
+
total += data.length;
|
|
65
|
+
if (total > 32) {
|
|
66
|
+
c.response.statusCode = 413;
|
|
67
|
+
c.response.end('太多了,限制32字节以内');
|
|
68
|
+
return ;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
await next(c);
|
|
73
|
+
|
|
74
|
+
console.log(total, 'bytes');
|
|
75
|
+
|
|
76
|
+
}, {pre: true, method: 'POST', name: 'transmit'});
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
app.autoWorker(4)
|
|
80
|
+
|
|
81
|
+
app.daemon(2034, 1)
|