-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
benchmark: chunky http client benchmark variation and server #228
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,102 @@ | ||
'use strict'; | ||
|
||
// test HTTP throughput in fragmented header case | ||
var common = require('../common.js'); | ||
var net = require('net'); | ||
var test = require('../../test/common.js'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
len: [1, 4, 8, 16, 32, 64, 128], | ||
num: [5, 50, 500, 2000], | ||
type: ['send'], | ||
}); | ||
|
||
|
||
function main(conf) { | ||
var len = +conf.len; | ||
var num = +conf.num; | ||
var type = conf.type; | ||
var todo = []; | ||
var headers = []; | ||
// Chose 7 because 9 showed "Connection error" / "Connection closed" | ||
// An odd number could result in a better length dispersion. | ||
for (var i = 7; i <= 7 * 7 * 7; i *= 7) | ||
headers.push(Array(i + 1).join('o')); | ||
|
||
function WriteHTTPHeaders(channel, has_keep_alive, extra_header_count) { | ||
todo = [] | ||
todo.push('GET / HTTP/1.1'); | ||
todo.push('Host: localhost'); | ||
todo.push('Connection: keep-alive'); | ||
todo.push('Accept: text/html,application/xhtml+xml,' + | ||
'application/xml;q=0.9,image/webp,*/*;q=0.8'); | ||
todo.push('User-Agent: Mozilla/5.0 (X11; Linux x86_64) ' + | ||
'AppleWebKit/537.36 (KHTML, like Gecko) ' + | ||
'Chrome/39.0.2171.71 Safari/537.36'); | ||
todo.push('Accept-Encoding: gzip, deflate, sdch'); | ||
todo.push('Accept-Language: en-US,en;q=0.8'); | ||
for (var i = 0; i < extra_header_count; i++) { | ||
// Utilize first three powers of a small integer for an odd cycle and | ||
// because the fourth power of some integers overloads the server. | ||
todo.push('X-Header-' + i + ': ' + headers[i % 3]); | ||
} | ||
todo.push(''); | ||
todo.push(''); | ||
todo = todo.join('\r\n'); | ||
// Using odd numbers in many places may increase length coverage. | ||
var chunksize = 37; | ||
for (i = 0; i < todo.length; i += chunksize) { | ||
var cur = todo.slice(i, i + chunksize); | ||
channel.write(cur); | ||
} | ||
} | ||
|
||
var success = 0; | ||
var failure = 0; | ||
var min = 10; | ||
var size = 0; | ||
var mod = 317; | ||
var mult = 17; | ||
var add = 11; | ||
var count = 0; | ||
var PIPE = test.PIPE; | ||
var socket = net.connect(PIPE, function() { | ||
bench.start(); | ||
WriteHTTPHeaders(socket, 1, len); | ||
socket.setEncoding('utf8') | ||
socket.on('data', function(d) { | ||
var did = false; | ||
var pattern = 'HTTP/1.1 200 OK\r\n'; | ||
if ((d.length === pattern.length && d === pattern) || | ||
(d.length > pattern.length && | ||
d.slice(0, pattern.length) === pattern)) { | ||
success += 1; | ||
did = true; | ||
} else { | ||
pattern = 'HTTP/1.1 ' | ||
if ((d.length === pattern.length && d === pattern) || | ||
(d.length > pattern.length && | ||
d.slice(0, pattern.length) === pattern)) { | ||
failure += 1; | ||
did = true; | ||
} | ||
} | ||
size = (size * mult + add) % mod; | ||
if (did) { | ||
count += 1; | ||
if (count === num) { | ||
bench.end(count); | ||
} else { | ||
WriteHTTPHeaders(socket, 1, min + size); | ||
} | ||
} | ||
}); | ||
socket.on('close', function() { | ||
console.log('Connection closed'); | ||
}); | ||
|
||
socket.on('error', function() { | ||
throw new Error('Connection error'); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: indentation seems off here. |
||
} |
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,47 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var http = require('http'); | ||
var fs = require('fs'); | ||
var spawn = require('child_process').spawn; | ||
var common = require('../common.js') | ||
var test = require('../../test/common.js') | ||
var pep = path.dirname(process.argv[1]) + '/chunky_http_client.js'; | ||
var PIPE = test.PIPE; | ||
|
||
var server; | ||
try { | ||
fs.unlinkSync(PIPE); | ||
} catch (e) { /* ignore */ } | ||
|
||
server = http.createServer(function(req, res) { | ||
res.writeHead(200, { 'content-type': 'text/plain', | ||
'content-length': '2' }); | ||
res.end('ok'); | ||
}); | ||
|
||
server.on('error', function(err) { | ||
throw new Error('server error: ' + err); | ||
}); | ||
|
||
try { | ||
var child; | ||
|
||
server.listen(PIPE); | ||
|
||
child = spawn(process.execPath, [pep], { }); | ||
|
||
child.on('error', function(err) { | ||
throw new Error('spawn error: ' + err ); | ||
}); | ||
|
||
child.stdout.pipe(process.stdout); | ||
|
||
child.on('exit', function (exitCode) { | ||
console.error('Child exited with code: ' + exitCode); | ||
}); | ||
|
||
} catch(e) { | ||
throw new Error('error: ' + e ); | ||
} | ||
|
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.
Are you sure
conf.len
andconf.num
will always be defined? If not they'll returnNaN
.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.
Yes, this seems to be the assumption in all of the configuration code in the benchmark client headers net/ section. I am simply following that pre-existing convention. I did notice that there is a conf.len downstairs line 65 or so. I pushed (rebase -i) a minor cleanup fix for it to use 'len' instead. But both seem fine and correct to me so I doubt that this is more than a very minor aesthetic clarity issue.