-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement trace option #290
Conversation
附上 benchmark
开了 trace 居然还变快了 😔 |
Codecov Report
@@ Coverage Diff @@
## master #290 +/- ##
==========================================
+ Coverage 92.56% 92.61% +0.04%
==========================================
Files 6 6
Lines 686 704 +18
Branches 185 191 +6
==========================================
+ Hits 635 652 +17
- Misses 51 52 +1
Continue to review full report at Codecov.
|
cc: @popomore |
@@ -164,6 +164,7 @@ httpclient.request('http://nodejs.org', function (err, body) { | |||
- ***proxy*** String | Object - proxy agent uri or options, default is `null`. | |||
- ***lookup*** Function - Custom DNS lookup function, default is `dns.lookup`. Require node >= 4.0.0(for http protocol) and node >=8(for https protocol) | |||
- ***checkAddress*** Function: optional, check request address to protect from SSRF and similar attacks. It receive tow arguments(`ip` and `family`) and should return true or false to identified the address is legal or not. It rely on `lookup` and have the same version requirement. | |||
- ***trace*** Boolean - Enable capture stack include call site of library entrance, default is `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没看到有地方使用 trace 这个参数?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😔太蠢了。。忘加了。补上了
lib/urllib.js
Outdated
@@ -862,6 +865,8 @@ exports.requestWithCallback = function requestWithCallback(url, args, callback) | |||
// request headers checker will throw error | |||
try { | |||
req = httplib.request(options, onResponse); | |||
req._callSite = {}; | |||
Error.captureStackTrace(req._callSite, requestWithCallback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trace 没设置为 true,不应该有这些额外信息吧。
warm up agent x 5,066 ops/sec ±6.64% (68 runs sampled)
request with no trace x 5,648 ops/sec ±1.25% (78 runs sampled)
request with trace x 4,518 ops/sec ±2.28% (74 runs sampled)
Fastest is request with no trace 开了 trace 以后,性能还是有挺大影响的。大概在 20% 上下。 |
package.json
Outdated
@@ -57,6 +58,7 @@ | |||
"intelli-espower-loader": "^1.0.1", | |||
"istanbul": "*", | |||
"jshint": "*", | |||
"microtime": "^2.1.8", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请去掉这个多余的依赖
@killagu 请给出开启 trace 之后的具体效果示例是怎样的? |
@@ -490,6 +492,7 @@ exports.requestWithCallback = function requestWithCallback(url, args, callback) | |||
err.status = statusCode; | |||
err.headers = headers; | |||
err.res = response; | |||
addLongStackTrace(err, req); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args.trace 没开启也不需要调用 addLongStackTrace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addLongStackTrace 这个已经作出判断了。
@fengmk2 README 里面加上 trace 的效果了 |
Error: connect ECONNREFUSED 127.0.0.1:11 | ||
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14) | ||
-------------------- | ||
at ~/workspace/urllib/lib/urllib.js:150:13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
推荐使用 projj https://npm.taobao.org/package/projj
No description provided.