Skip to content
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

Merged
merged 3 commits into from
Sep 26, 2018
Merged

feat: implement trace option #290

merged 3 commits into from
Sep 26, 2018

Conversation

killagu
Copy link
Member

@killagu killagu commented Aug 28, 2018

No description provided.

@killagu killagu requested a review from fengmk2 August 28, 2018 13:33
@killagu
Copy link
Member Author

killagu commented Aug 28, 2018

附上 benchmark

warm up agent x 3,919 ops/sec ±5.42% (75 runs sampled)
request with no trace x 4,441 ops/sec ±1.87% (78 runs sampled)
request with trace x 4,618 ops/sec ±1.37% (79 runs sampled)
Fastest is request with trace

开了 trace 居然还变快了 😔

@codecov
Copy link

codecov bot commented Aug 28, 2018

Codecov Report

Merging #290 into master will increase coverage by 0.04%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
lib/urllib.js 96.15% <94.73%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dcf87cb...902e052. Read the comment docs.

@killagu
Copy link
Member Author

killagu commented Aug 28, 2018

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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没看到有地方使用 trace 这个参数?

Copy link
Member Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace 没设置为 true,不应该有这些额外信息吧。

@killagu
Copy link
Member Author

killagu commented Sep 26, 2018

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请去掉这个多余的依赖

@fengmk2
Copy link
Member

fengmk2 commented Sep 26, 2018

@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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args.trace 没开启也不需要调用 addLongStackTrace

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addLongStackTrace 这个已经作出判断了。

@killagu
Copy link
Member Author

killagu commented Sep 26, 2018

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fengmk2 fengmk2 merged commit b760530 into master Sep 26, 2018
@fengmk2 fengmk2 deleted the option-trace branch September 26, 2018 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants