topbit 3.2.0 → 3.2.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 +0 -3
- package/README.md +0 -3
- package/demo/loader.js +1 -1
- package/demo/monitor.js +2 -2
- package/package.json +1 -1
- package/src/http1.js +2 -9
- package/src/http2.js +2 -12
- package/src/middleware1.js +0 -17
- package/src/middleware2.js +0 -19
- package/src/topbit.js +0 -7
- /package/src/{ctxpool.js → @remove-ctxpool.js} +0 -0
package/README.cn.md
CHANGED
package/README.md
CHANGED
|
@@ -897,9 +897,6 @@ Full configuration options for app initialization are as follows. Please read th
|
|
|
897
897
|
// Max URL length
|
|
898
898
|
maxUrlLength: 2048,
|
|
899
899
|
|
|
900
|
-
// Max number of request context cache pool.
|
|
901
|
-
maxpool: 4096,
|
|
902
|
-
|
|
903
900
|
// Timer milliseconds for child process resource reporting.
|
|
904
901
|
monitorTimeSlice: 640,
|
|
905
902
|
|
package/demo/loader.js
CHANGED
package/demo/monitor.js
CHANGED
|
@@ -33,7 +33,7 @@ const app = new Topbit({
|
|
|
33
33
|
globalLog : false,
|
|
34
34
|
logType: 'stdio',
|
|
35
35
|
loadInfoFile : args.load ? '' : '/tmp/topbit-loadinfo.log',
|
|
36
|
-
maxLoadRate: 0.
|
|
36
|
+
maxLoadRate: 0.6
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
app.get('/', async c => {
|
|
@@ -46,7 +46,7 @@ app.get('/test', async c => {
|
|
|
46
46
|
for (let i = 0; i < 90000; i++) {
|
|
47
47
|
sum += Math.random() * i;
|
|
48
48
|
}
|
|
49
|
-
c.to({sum});
|
|
49
|
+
c.setHeader(`x-test-${Math.floor(Math.random() * 100)}`, sum).to({sum});
|
|
50
50
|
}, {group: 'test', name : 'test'});
|
|
51
51
|
|
|
52
52
|
app.post('/test', async c => {
|
package/package.json
CHANGED
package/src/http1.js
CHANGED
|
@@ -7,7 +7,6 @@ const process = require('node:process');
|
|
|
7
7
|
const logger = require('./logger.js');
|
|
8
8
|
const {fpurl} = require('./fastParseUrl.js');
|
|
9
9
|
const Context = require('./context1.js');
|
|
10
|
-
const ctxpool = require('./ctxpool.js');
|
|
11
10
|
const checkHeaderLimit = require('./headerLimit.js');
|
|
12
11
|
const sendmsg = require('./sendmsg.js');
|
|
13
12
|
|
|
@@ -25,9 +24,6 @@ class Http1 {
|
|
|
25
24
|
this.isWorker = options.isWorker;
|
|
26
25
|
|
|
27
26
|
this.logger = logger;
|
|
28
|
-
ctxpool.max = this.config.maxpool;
|
|
29
|
-
|
|
30
|
-
this.ctxpool = ctxpool;
|
|
31
27
|
this.Context = Context;
|
|
32
28
|
this.fpurl = fpurl;
|
|
33
29
|
this.host = '';
|
|
@@ -109,7 +105,7 @@ class Http1 {
|
|
|
109
105
|
return ;
|
|
110
106
|
}
|
|
111
107
|
|
|
112
|
-
let ctx =
|
|
108
|
+
let ctx = new Context();
|
|
113
109
|
|
|
114
110
|
ctx.bodyLength = 0;
|
|
115
111
|
ctx.maxBody = self.config.maxBody;
|
|
@@ -134,10 +130,7 @@ class Http1 {
|
|
|
134
130
|
ctx.param = rt.args;
|
|
135
131
|
rt = null;
|
|
136
132
|
|
|
137
|
-
return self.midware.run(ctx)
|
|
138
|
-
ctxpool.free(ctx);
|
|
139
|
-
ctx = null;
|
|
140
|
-
});
|
|
133
|
+
return self.midware.run(ctx);
|
|
141
134
|
};
|
|
142
135
|
|
|
143
136
|
return callback;
|
package/src/http2.js
CHANGED
|
@@ -5,7 +5,6 @@ const fs = require('node:fs');
|
|
|
5
5
|
const process = require('node:process');
|
|
6
6
|
const logger = require('./logger.js');
|
|
7
7
|
const {fpurl} = require('./fastParseUrl.js');
|
|
8
|
-
const ctxpool = require('./ctxpool.js');
|
|
9
8
|
const Context = require('./context2.js');
|
|
10
9
|
const checkHeaderLimit = require('./headerLimit.js');
|
|
11
10
|
const sendmsg = require('./sendmsg.js');
|
|
@@ -25,9 +24,6 @@ class Httpt {
|
|
|
25
24
|
this.isWorker = options.isWorker;
|
|
26
25
|
|
|
27
26
|
this.logger = logger;
|
|
28
|
-
ctxpool.max = this.config.maxpool;
|
|
29
|
-
|
|
30
|
-
this.ctxpool = ctxpool;
|
|
31
27
|
this.Context = Context;
|
|
32
28
|
this.fpurl = fpurl;
|
|
33
29
|
|
|
@@ -114,7 +110,7 @@ class Httpt {
|
|
|
114
110
|
stream.close();
|
|
115
111
|
});
|
|
116
112
|
|
|
117
|
-
let ctx =
|
|
113
|
+
let ctx = new Context();
|
|
118
114
|
|
|
119
115
|
ctx.bodyLength = 0;
|
|
120
116
|
ctx.maxBody = self.config.maxBody;
|
|
@@ -128,10 +124,7 @@ class Httpt {
|
|
|
128
124
|
ctx.stream = stream;
|
|
129
125
|
ctx.res = ctx.stream;
|
|
130
126
|
ctx.req = ctx.stream;
|
|
131
|
-
|
|
132
|
-
ctx.dataHeaders = {};
|
|
133
127
|
ctx.headers = headers;
|
|
134
|
-
|
|
135
128
|
ctx.path = urlobj.path;
|
|
136
129
|
ctx.query = urlobj.query;
|
|
137
130
|
ctx.routepath = rt.key;
|
|
@@ -141,10 +134,7 @@ class Httpt {
|
|
|
141
134
|
ctx.param = rt.args;
|
|
142
135
|
rt = null;
|
|
143
136
|
|
|
144
|
-
return self.midware.run(ctx)
|
|
145
|
-
ctxpool.free(ctx);
|
|
146
|
-
ctx = null;
|
|
147
|
-
});
|
|
137
|
+
return self.midware.run(ctx);
|
|
148
138
|
};
|
|
149
139
|
|
|
150
140
|
return callback;
|
package/src/middleware1.js
CHANGED
|
@@ -15,30 +15,13 @@ class Middleware extends MidCore {
|
|
|
15
15
|
try {
|
|
16
16
|
await this.exec(ctx, ctx.group);
|
|
17
17
|
} catch (err) {
|
|
18
|
-
|
|
19
18
|
this.errorHandle(err, '--ERR-res--');
|
|
20
|
-
|
|
21
19
|
try {
|
|
22
20
|
if (ctx.res && !ctx.res.writableEnded) {
|
|
23
21
|
ctx.res.statusCode = 500;
|
|
24
22
|
ctx.res.end();
|
|
25
23
|
}
|
|
26
24
|
} catch (err) {}
|
|
27
|
-
|
|
28
|
-
} finally {
|
|
29
|
-
ctx.req = null;
|
|
30
|
-
ctx.res = null;
|
|
31
|
-
ctx.data = null;
|
|
32
|
-
ctx.box = null;
|
|
33
|
-
ctx.service = null;
|
|
34
|
-
ctx.requestCall = null;
|
|
35
|
-
ctx.headers = null;
|
|
36
|
-
ctx.body = null;
|
|
37
|
-
ctx.rawBody = null;
|
|
38
|
-
ctx.files = null;
|
|
39
|
-
ctx.param = null;
|
|
40
|
-
ctx.user = null;
|
|
41
|
-
ctx = null;
|
|
42
25
|
}
|
|
43
26
|
}
|
|
44
27
|
|
package/src/middleware2.js
CHANGED
|
@@ -16,9 +16,7 @@ class Middleware extends MidCore {
|
|
|
16
16
|
try {
|
|
17
17
|
await this.exec(ctx, ctx.group);
|
|
18
18
|
} catch (err) {
|
|
19
|
-
|
|
20
19
|
this.errorHandle(err, '--ERR-RESPONSE--');
|
|
21
|
-
|
|
22
20
|
if (ctx.stream && !ctx.stream.destroyed && ctx.stream.writable) {
|
|
23
21
|
try {
|
|
24
22
|
if (!ctx.stream.headersSent) {
|
|
@@ -30,24 +28,7 @@ class Middleware extends MidCore {
|
|
|
30
28
|
ctx.stream.end();
|
|
31
29
|
} catch (err) {}
|
|
32
30
|
}
|
|
33
|
-
} finally {
|
|
34
|
-
ctx.data = null;
|
|
35
|
-
ctx.dataHeaders = null;
|
|
36
|
-
ctx.stream = null;
|
|
37
|
-
ctx.req = null;
|
|
38
|
-
ctx.res = null;
|
|
39
|
-
ctx.service = null;
|
|
40
|
-
ctx.box = null;
|
|
41
|
-
ctx.requestCall = null;
|
|
42
|
-
ctx.body = null;
|
|
43
|
-
ctx.headers = null;
|
|
44
|
-
ctx.rawBody = null;
|
|
45
|
-
ctx.files = null;
|
|
46
|
-
ctx.param = null;
|
|
47
|
-
ctx.user = null;
|
|
48
|
-
ctx = null;
|
|
49
31
|
}
|
|
50
|
-
|
|
51
32
|
}
|
|
52
33
|
|
|
53
34
|
/** 这是最终添加的请求中间件。基于洋葱模型,这个中间件最先执行,所以最后会返回响应结果。 */
|
package/src/topbit.js
CHANGED
|
@@ -155,7 +155,6 @@ class Topbit {
|
|
|
155
155
|
* - memFactor {number} 控制内存最大使用量的系数,范围从 -0.45 ~ 0.45,会使用基本系数加上此值并乘以内存总量。默认值0.28。
|
|
156
156
|
* RSS基本系数是0.52。不要设置的太低,提供比较低的值是为了测试使用。
|
|
157
157
|
* - maxUrlLength 最大URL长度,包括path和querystring
|
|
158
|
-
* - maxpool 请求上下文的最大缓存池数量。
|
|
159
158
|
* - loadMonitor true|false,表示是否启用负载监控功能,在daemon模式有效,默认为true。
|
|
160
159
|
* - monitorTimeSlice 子进程获取系统占用资源的定时器时间片,毫秒值,默认为500。
|
|
161
160
|
* - maxQuery 最大允许的querystring的参数,默认为12。
|
|
@@ -240,8 +239,6 @@ class Topbit {
|
|
|
240
239
|
|
|
241
240
|
maxUrlLength: 1152,
|
|
242
241
|
|
|
243
|
-
maxpool : 8192,
|
|
244
|
-
|
|
245
242
|
//子进程汇报资源信息的定时器毫秒数。
|
|
246
243
|
monitorTimeSlice: 500,
|
|
247
244
|
|
|
@@ -339,10 +336,6 @@ class Topbit {
|
|
|
339
336
|
case 'maxUrlLength':
|
|
340
337
|
optionsCheck(k, options[k], this.config, {type: 'number', min: 1, max: 4096});
|
|
341
338
|
break;
|
|
342
|
-
|
|
343
|
-
case 'maxpool':
|
|
344
|
-
optionsCheck(k, options[k], this.config, {type: 'number', min: 2, max: 50000});
|
|
345
|
-
break;
|
|
346
339
|
|
|
347
340
|
case 'monitorTimeSlice':
|
|
348
341
|
optionsCheck(k, options[k], this.config, {type: 'number', min: 5, max: 10000});
|
|
File without changes
|