-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApacheBenchmarkCodeGenerator.js
70 lines (61 loc) · 2.39 KB
/
ApacheBenchmarkCodeGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(function() {
//Based on https://github.com/luckymarmot/Paw-cURLCodeGenerator
var ApacheBenchmarkCodeGenerator = function() {
var self = this;
this.default_request_count = 10000;
this.default_concurrency = 100;
this.generateCommand = function(request) {
var command = "# " + request.name + "\n";
command += "ab -c" + (self.options.concurrency || self.default_concurrency);
command += " -n" + (self.options.request_count || self.default_request_count);
command += " -m" + request.method;
var header_name;
for (header_name in request.headers) {
command += ' -H "' + header_name + ": " + request.headers[header_name] + '"';
}
command += ' "' + request.url + '"';
return command;
/*
TODO:
-A auth-username:password
Supply BASIC Authentication credentials to the server. The user-
name and password are separated by a single : and sent on the
wire base64 encoded. The string is sent regardless of whether
the server needs it (i.e., has sent an 401 authentication
needed).
-k Enable the HTTP KeepAlive feature, i.e., perform multiple
requests within one HTTP session. Default is no KeepAlive.
*/
}
this.generate = function(context, requests, options) {
var commands;
for (option in options) {
console.log(option + "=" + options[option]);
}
self.options = (options || {}).inputs || {};
commands = requests.map(function(request) {
return self.generateCommand(request);
});
return commands.join('\n\n') + '\n';
}
}
ApacheBenchmarkCodeGenerator.identifier = "com.maxromanovsky.PawExtensions.ApacheBenchmarkCodeGenerator";
ApacheBenchmarkCodeGenerator.title = "ApacheBench";
ApacheBenchmarkCodeGenerator.fileExtension = "sh";
ApacheBenchmarkCodeGenerator.languageHighlighter = "bash";
ApacheBenchmarkCodeGenerator.inputs = [
InputField("request_count", "Number of requests", "Number", {
persisted: true,
defaultValue: this.default_request_count,
float: false,
minValue: 1
}),
InputField("concurrency", "Concurrency", "Number", {
persisted: true,
defaultValue: this.default_concurrency,
float: false,
minValue: 1
})
];
registerCodeGenerator(ApacheBenchmarkCodeGenerator);
}).call(this);