3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
/*************************** -*- Mod: C++ -*- *********************
27
******************************************************************/
33
// ^[ ]*\([^ ]*\)[ ]*=[ ]*\([^ ]*\)[ ]*$ --> lhs=\1 rhs=\2
38
process_line(int line_no, char *line, int line_size, char *lhs, char *rhs)
42
lhs[0] = rhs[0] = '\0';
43
while (i < line_size && isspace(line[i]))
50
while (i < line_size && !isspace(line[i]) && (line[i] != '=')) {
54
printf("Syntax error in config file line %d\n", line_no);
58
while (i < line_size && isspace(line[i]))
61
printf("Syntax error in config file line %d\n", line_no);
65
printf("Syntax error in config file line %d\n", line_no);
69
while (i < line_size && isspace(line[i]))
72
printf("Syntax error in config file line %d\n", line_no);
76
while (i < line_size && !isspace(line[i])) {
84
Config::read_docsize_dist(long warmup)
89
double prob, avg_doc_size = 0.0;
94
n = fscanf(docsize_dist_file_p, "%ld %lf", &size, &prob);
95
if (n == EOF) { /*fscanf will return number of matched items. If it
96
returns EOF that means none were matched */
99
sizes[num_sizes] = size;
100
if (size == QOS_docsize)
102
if (num_sizes == 0) {
103
cumulative_size_prob[num_sizes] = prob;
105
cumulative_size_prob[num_sizes] = cumulative_size_prob[num_sizes - 1] + prob;
108
avg_doc_size += prob * size;
109
docsize_size_sum += size;
111
fprintf(stderr, "Error in docsize_dist_file\n");
114
} while (!end_of_file);
115
printf("Average Doc Size according to the specified distribution: %.2f\n", avg_doc_size);
117
for (i = 0; i < num_sizes; i++) {
118
printf("%7ld %.2f\n", sizes[i], cumulative_size_prob[i]);
121
if ((cumulative_size_prob[num_sizes - 1]<0.99999) || (cumulative_size_prob[num_sizes - 1]> 1.00001)) {
122
fprintf(stderr, "Error in docsize_dist_file: prob add up to %f\n", cumulative_size_prob[num_sizes - 1]);
125
if (QOS_docsize != 0) {
128
fprintf(stderr, "Note: Only documents of QOS_docsize %d bytes will be included in histograms.\n", QOS_docsize);
131
fprintf(stderr, "Error in QOS_docsize: %d is not in the document distribution\n", QOS_docsize);
138
Config::read_thinktime_dist()
143
double prob, avg_thinktime = 0.0;
146
n = fscanf(thinktime_dist_file_p, "%ld %lf", &thinktime, &prob);
147
if (n == EOF) { /*fscanf will return number of matched items. If it
148
returns EOF that means none were matched */
151
thinktimes[num_thinktimes] = thinktime;
152
if (num_thinktimes == 0) {
153
cumulative_thinktime_prob[num_thinktimes] = prob;
155
cumulative_thinktime_prob[num_thinktimes] = cumulative_thinktime_prob[num_thinktimes - 1] + prob;
158
avg_thinktime += prob * thinktime;
160
fprintf(stderr, "Error in thinktime_dist_file\n");
163
} while (!end_of_file);
165
printf("Average Think Time according to the specified distribution: %.2f\n", avg_thinktime);
166
printf("Thinktime probabilities:\n");
167
for (i = 0; i < num_thinktimes; i++) {
168
printf("%3ld %.2f\n", thinktimes[i], cumulative_thinktime_prob[i]);
171
if ((cumulative_thinktime_prob[num_thinktimes - 1] < 0.99999) ||
172
(cumulative_thinktime_prob[num_thinktimes - 1] > 1.00001)) {
173
fprintf(stderr, "Error in thinktime_dist_file: prob add up to %f\n", cumulative_thinktime_prob[num_thinktimes - 1]);
178
Config::read_target_byterate_dist()
182
long target_byterate;
184
num_target_byterates = 0;
186
n = fscanf(target_byterate_dist_file_p, "%ld %lf", &target_byterate, &prob);
187
if (n == EOF) { /*fscanf will return number of matched items. If it
188
returns EOF that means none were matched */
191
target_byterates[num_target_byterates] = target_byterate;
192
if (num_target_byterates == 0) {
193
cumulative_target_byterate_prob[num_target_byterates] = prob;
195
cumulative_target_byterate_prob[num_target_byterates] =
196
cumulative_target_byterate_prob[num_target_byterates - 1] + prob;
198
num_target_byterates++;
200
fprintf(stderr, "Error in target_byterate_dist file\n");
203
} while (!end_of_file);
204
printf("Byterate probabilities:\n");
205
for (i = 0; i < num_target_byterates; i++) {
206
printf("%3ld %.2f\n", target_byterates[i], cumulative_target_byterate_prob[i]);
208
if ((cumulative_target_byterate_prob[num_target_byterates - 1]
209
< 0.99999) || (cumulative_target_byterate_prob[num_target_byterates - 1]
211
fprintf(stderr, "Error in target_byterate_dist_file: prob add up to %f\n",
212
cumulative_target_byterate_prob[num_target_byterates - 1]);
217
Config::Config(long warmup, char *config_file, TSPlugin * aplug_in, int aread_timeout)
219
char line[MAX_LINE_SIZE], lhs[MAX_LINE_SIZE], rhs[MAX_LINE_SIZE];
230
strcpy(target_host, "localhost");
231
strcpy(target_port, "8090");
234
strcpy(target_host, "");
235
strcpy(target_port, "");
238
strcpy(document_base, "");
240
strcpy(log_file, "sample.log");
242
execution_interval = 10;
243
reporting_interval = 1000000;
244
histogram_max = 30.0;
245
histogram_resolution = 0.5;
246
round_trip_time_cutoff = 2000; /* msec */
247
connect_time_cutoff = 500; /* msec */
248
first_byte_latency_cutoff = 1000; /* msec */
251
read_timeout = aread_timeout;
257
num_origin_servers = 0;
258
strcpy(docsize_dist_file, "docsize.specweb");
259
strcpy(thinktime_dist_file, "thinktime.0");
260
strcpy(target_byterate_dist_file, "byterate.fast");
262
if (!(conf_file = fopen(config_file, "r"))) {
263
fprintf(stderr, "Error: could not open the config file %s\n", config_file);
264
perror("Error: Config File Open");
272
line[i++] = (c = getc(conf_file));
273
} while (c != '\n' && c != EOF && i < MAX_LINE_SIZE);
274
if (i == MAX_LINE_SIZE) {
275
fprintf(stderr, "Error in Config File: Lines can only be %d chars long\n", MAX_LINE_SIZE);
281
/* last char is either newline or EOF, so skip it */
285
process_line(line_no, line, i, lhs, rhs);
288
// target_host, target_port, and document_base
289
// will be passed to the TSOptionProcess() later, and
290
// comments are skipped.
291
if ((strcmp(lhs, "target_host") || strcmp(lhs, "target_port") || strcmp(lhs, "document_base")) && strcmp(lhs, "")) {
292
if (plug_in->options_process_fcn) {
293
(plug_in->options_process_fcn) (lhs, rhs);
298
if (!strcmp(lhs, "target_host")) {
299
strcpy(target_host, rhs);
300
} else if (!strcmp(lhs, "target_port")) {
301
strcpy(target_port, rhs);
302
} else if (!strcmp(lhs, "document_base")) {
303
strcpy(document_base, rhs);
304
} else if (!strcmp(lhs, "synthetic")) {
305
synthetic = atoi(rhs);
306
} else if (!strcmp(lhs, "log_file")) {
307
strcpy(log_file, rhs);
308
} else if (!strcmp(lhs, "users")) {
311
} else if (!strcmp(lhs, "execution_interval")) {
312
execution_interval = atoi(rhs);
313
assert((execution_interval) > 0);
314
} else if (!strcmp(lhs, "reporting_interval")) {
315
reporting_interval = atoi(rhs);
316
assert((reporting_interval) > 0);
317
} else if (!strcmp(lhs, "histogram_max")) {
318
histogram_max = atof(rhs);
319
assert((histogram_max) > 0.0);
320
if (histogram_max > 1000.0) {
321
fprintf(stderr, "Error: histogram times are (now) specified in seconds. %f sec is too big.\n",
325
} else if (!strcmp(lhs, "histogram_resolution")) {
326
histogram_resolution = atof(rhs);
327
assert((histogram_resolution) > 0.0);
328
} else if (!strcmp(lhs, "round_trip_cutoff")) {
329
round_trip_time_cutoff = atol(rhs);
330
assert(round_trip_time_cutoff > 0);
331
} else if (!strcmp(lhs, "first_byte_cutoff")) {
332
first_byte_latency_cutoff = atol(rhs);
333
assert(first_byte_latency_cutoff > 0);
334
} else if (!strcmp(lhs, "connect_cutoff")) {
335
connect_time_cutoff = atol(rhs);
336
assert(connect_time_cutoff > 0);
337
} else if (!strcmp(lhs, "debug")) {
339
assert(((debug) == 0) || ((debug) == 1));
340
} else if (!strcmp(lhs, "ssl")) {
342
assert(((ssl) == 0) || ((ssl) == 1));
343
} else if (!strcmp(lhs, "read_timeout")) {
344
read_timeout = atoi(rhs);
345
assert((read_timeout) > 0);
346
} else if (!strcmp(lhs, "hotset")) {
348
assert((hotset) > 0);
349
} else if (!strcmp(lhs, "docset")) {
351
assert((docset) > 0);
352
} else if (!strcmp(lhs, "hitrate")) {
354
assert((hitrate) >= 0 && (hitrate) <= 100);
355
} else if (!strcmp(lhs, "keepalive")) {
356
keepalive = atoi(rhs);
357
assert((keepalive) > 0);
358
} else if (!strcmp(lhs, "origin_servers")) {
360
num_origin_servers = 0;
361
while ((line[j] != '\0') && (line[j] != '='))
365
while (line[j] != '\0') {
366
assert((num_origin_servers) < MAX_ORIGIN_SERVERS);
367
while ((line[j] != '\0') && isspace(line[j]))
369
if (line[j] != '\0') {
370
for (k = 0; ((line[j] != '\0') && !isspace(line[j])); k++) {
371
origin_server_names[num_origin_servers][k] = line[j++];
373
origin_server_names[num_origin_servers++][k] = '\0';
377
for (j = 0; j < num_origin_servers; j++) {
378
p = strrchr(origin_server_names[j], ':');
379
if ((p == NULL) || (p == origin_server_names[j])) {
380
fprintf(stderr, "No port supplied for origin server %d: '%s'\n", j, origin_server_names[j]);
383
origin_server_ports[j] = p + 1;
386
} else if (!strcmp(lhs, "docsize_dist_file")) {
387
strcpy(docsize_dist_file, rhs);
388
} else if (!strcmp(lhs, "thinktime_dist_file")) {
389
strcpy(thinktime_dist_file, rhs);
390
} else if (!strcmp(lhs, "byterate_dist_file")) {
391
strcpy(target_byterate_dist_file, rhs);
392
} else if (!strcmp(lhs, "QOS_docsize")) {
393
QOS_docsize = atoi(rhs);
394
} else if (line[0] == '#') {
397
/* printf("Unrecognized input in config file line %d\n", line_no); exit(1); */
401
} while (!end_of_file);
403
if (num_origin_servers == 0) {
404
fprintf(stderr, "No origin servers specified.\n");
408
if ((strlen(target_host) == 0) || (strlen(target_port) == 0)) {
410
fprintf(stderr, "target_host and/or target_port not specified -- will connect directly to origin servers\n");
416
hotset_access_ratio = hitrate / 100.0;
417
read_timeout *= 1000; /* convert into msec */
419
reporting_interval = 9999999; /* Some large value */
420
execution_interval = 9999999; /* Some large value */
424
if (fclose(conf_file)) {
425
fprintf(stderr, "Error: could not close the config file %s\n", config_file);
426
perror("Error: Config File Close");
430
docsize_dist_file_p = NULL;
431
if (!(log_file_p = fopen(log_file, "r"))) {
432
fprintf(stderr, "Error: could not open the log file %s\n", log_file);
433
perror("Error: Log File Open");
438
/* Round-off hotset and docset */
439
if (!(docsize_dist_file_p = fopen(docsize_dist_file, "r"))) {
440
fprintf(stderr, "Error: could not open the docsize_dist_file %s\n", docsize_dist_file);
441
perror("Error: DocSize Dist File Open");
444
read_docsize_dist(warmup);
445
if (fclose(docsize_dist_file_p)) {
446
fprintf(stderr, "Error: could not close the docsize_dist file %s\n", docsize_dist_file);
447
perror("Error: Docsize File Close");
451
printf("Hotset %f num_origin_servers %d num_sizes %d\n", hotset, num_origin_servers, num_sizes);
452
printf("Docset %f num_origin_servers %d num_sizes %d\n", docset, num_origin_servers, num_sizes);
454
hotset = (double) (ceil(hotset * 1.0 / (num_origin_servers * num_sizes)) * (num_origin_servers * num_sizes));
456
docset = (double) (ceil(docset * 1.0 / (num_origin_servers * num_sizes)) * (num_origin_servers * num_sizes));
458
if (warmup) { // Don't need thinktimes or target_byterate
459
fprintf(stderr, "Total size of hotset: %.1f MByte\n",
460
(((double) hotset / (double) num_sizes) * (double) docsize_size_sum) / (1024.0 * 1024.0));
463
cumulative_thinktime_prob[0] = 1.0;
464
num_target_byterates = 1;
465
target_byterates[0] = -1;
466
cumulative_target_byterate_prob[0] = 1.0;
467
if (users > MAX_WARMUP_USERS) {
468
fprintf(stderr, "Reducing number of users for warmup from %d to %d\n", users, MAX_WARMUP_USERS);
469
users = MAX_WARMUP_USERS;
472
if (!(thinktime_dist_file_p = fopen(thinktime_dist_file, "r"))) {
473
fprintf(stderr, "Error: could not open the thinktime_dist_file %s\n", thinktime_dist_file);
474
perror("Error: Thinktime Dist File Open");
477
read_thinktime_dist();
478
if (fclose(thinktime_dist_file_p)) {
479
fprintf(stderr, "Error: could not close the thinktime_dist file %s\n", thinktime_dist_file);
480
perror("Error: Thinktime File Close");
483
if (!(target_byterate_dist_file_p = fopen(target_byterate_dist_file, "r"))) {
484
fprintf(stderr, "Error: could not open the target_byterate_dist_file %s\n", target_byterate_dist_file);
485
perror("Error: Target ByteRate Dist File Open");
488
read_target_byterate_dist();
489
if (fclose(target_byterate_dist_file_p)) {
490
fprintf(stderr, "Error: could not close the target_byterate_dist file %s\n", target_byterate_dist_file);
491
perror("Error: Target ByteRate File Close");
498
if (plug_in->options_process_fcn) {
499
(plug_in->options_process_fcn) ("target_host", target_host);
500
(plug_in->options_process_fcn) ("target_port", target_port);
501
(plug_in->options_process_fcn) ("document_base", document_base);
506
printf("target_host '%s'\n", target_host);
507
printf("target_port '%s'\n", target_port);
508
// printf("synthetic %d\n",synthetic);
509
// printf("log_file '%s'\n", log_file);
510
printf("users %d\n", users);
511
printf("execution_interval %d\n", execution_interval);
512
printf("reporting_interval %d\n", reporting_interval);
513
printf("debug %d\n", debug);
514
printf("ssl %d\n", ssl);
515
printf("read_timeout %d\n", read_timeout);
516
printf("adjusted hotset %.0f\n", hotset);
517
printf("adjusted docset %.0f \n", docset);
518
printf("hitrate %d \n", hitrate);
519
printf("keepalive %d\n", keepalive);
520
printf("num_origin_servers %d\n", num_origin_servers);
522
/////////////////////////////
524
if (plug_in->options_process_finish_fcn) {
525
(plug_in->options_process_finish_fcn) ();
528
/////////////////////////////