-
Notifications
You must be signed in to change notification settings - Fork 31k
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
child_process: measure buffer length in bytes #6764
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e20ff77
child_process: measure buffer length in bytes
Trott 3245de6
squash: run toString() just once at the end
Trott 7b96b64
squash: optimize Buffer.concat(), handle edge case
Trott 2b14b64
squash: benchmark nits
Trott 221dec5
squash: comment block explaining chunk.length
Trott 425128f
squash: get correct length for strings
Trott 2d56158
squash
Trott bce02ef
squash
Trott a8ba111
squash: nothing but nits
Trott 32925da
squash
Trott ec2cf57
squash: comment nit fixes
Trott 561c798
squash: fix comment
Trott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const bench = common.createBenchmark(main, { | ||
len: [64, 256, 1024, 4096, 32768], | ||
dur: [5] | ||
}); | ||
|
||
const exec = require('child_process').exec; | ||
function main(conf) { | ||
bench.start(); | ||
|
||
const dur = +conf.dur; | ||
const len = +conf.len; | ||
|
||
const msg = `"${'.'.repeat(len)}"`; | ||
msg.match(/./); | ||
const options = {'stdio': ['ignore', 'pipe', 'ignore']}; | ||
// NOTE: Command below assumes bash shell. | ||
const child = exec(`while\n echo ${msg}\ndo :; done\n`, options); | ||
|
||
var bytes = 0; | ||
child.stdout.on('data', function(msg) { | ||
bytes += msg.length; | ||
}); | ||
|
||
setTimeout(function() { | ||
child.kill(); | ||
bench.end(bytes); | ||
}, dur * 1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const unicode = '中文测试'; // Length = 4, Byte length = 13 | ||
|
||
if (process.argv[2] === 'child') { | ||
console.error(unicode); | ||
} else { | ||
const cmd = `${process.execPath} ${__filename} child`; | ||
|
||
cp.exec(cmd, {maxBuffer: 10}, common.mustCall((err, stdout, stderr) => { | ||
assert.strictEqual(err.message, 'stderr maxBuffer exceeded'); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this needed by the way?
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.
@mscdex It's needed so that
stdoutLen
has the correct value when passed toBuffer.concat()
later on. The alternative is to let the buffer length exceedoptions.maxBuffer
. However, that does not match the behavior of the current implementation whereas this does.