-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.c
239 lines (201 loc) · 7.65 KB
/
conf.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* conf.c
*
* 2006-2007 Copyright (c)
* Robert Iakobashvili, <coroberti@gmail.com>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// must be first include
#include "fdsetsize.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "conf.h"
extern int is_transparent_proxy;
/*
Command line configuration options. Setting defaults here.
*/
/* Configurable time to cut connect () in prog */
int connect_timeout = 5;
/* Flag, whether to perform verbose logging */
int verbose_logging = 0;
/* Flag, whether to run batches as batch per thread. */
int threads_subbatches_num = 0;
/*
Time in seconds between snapshot statistics printouts to
screen as well as to the statistics file
*/
long snapshot_statistics_timeout = 3; /* Seconds */
/*
Rewind logfile, if above the size above MB
*/
long logfile_rewind_size = 1024;
/* If to output client messages to stderr, otherwise to logfile */
int stderr_print_client_msg = 0;
#if 0
/* Storming or smooth loading */
int loading_mode = LOAD_MODE_DEFAULT;
#endif
/* Whether to include url to all log outputs. */
int url_logging = 0;
/* Output to logfile the details of request/response. */
int detailed_logging = 0;
int warnings_skip = 0;
/* Name of the configuration file */
char config_file[PATH_MAX + 1];
/* Name of the proxy */
char config_proxy[PATH_MAX];
/*
On errors, whether to continue loading for this client
from the next cycle, or to give it up.
*/
unsigned long error_recovery_client = 1; /* Default: error recovery and continue */
int parse_command_line (int argc, char *argv [])
{
int rget_opt = 0;
while ((rget_opt = getopt (argc, argv, "c:dehf:i:l:p:st:vVuwx:")) != EOF)
{
switch (rget_opt)
{
case 'c': /* Connection establishment timeout */
if (!optarg || (connect_timeout = atoi (optarg)) <= 0)
{
fprintf (stderr, "%s error: -c option should be a positive number in seconds.\n", __func__);
return -1;
}
break;
case 'd':
detailed_logging = 1;
break;
case 'e':
error_recovery_client = 0;
break;
case 'h':
print_help ();
exit (0);
case 'f': /* Configuration file */
if (optarg)
strcpy(config_file, optarg);
else
{
fprintf (stderr, "%s error: -f option should be followed by a filename.\n", __func__);
return -1;
}
break;
case 'i': /* Statistics snapshot timeout */
if (!optarg ||
(snapshot_statistics_timeout = atoi (optarg)) < 1)
{
fprintf (stderr, "%s error: -i option should be followed by a number >= 1.\n",
__func__);
return -1;
}
break;
case 'l': /* Number of cycles before a logfile rewinds. */
if (!optarg ||
(logfile_rewind_size = atol (optarg)) < 2)
{
fprintf (stderr, "%s: error: -l option should be followed by a number >= 2.\n",
__func__);
return -1;
}
break;
case 's': /* Stderr printout of client messages (instead of to a batch logfile). */
stderr_print_client_msg = 1;
break;
case 't': /* Create sub-batches and run each sub-batch of clients
in a dedicated thread. */
if (!optarg ||
(threads_subbatches_num = atoi (optarg)) < 2)
{
fprintf (stderr, "%s error: -t option should be followed by a number >= 2.\n",
__func__);
return -1;
}
break;
case 'v': /* accumulate verbosity */
verbose_logging += 1;
break;
/*Simon*/
case 'V':
fprintf (stderr, "%s\nCompile at %s %s\n", VERSION_NUMBER, __DATE__, __TIME__);
exit (0);
case 'u':
url_logging = 1;
break;
case 'w':
warnings_skip = 1;
break;
case 'x': /* set/unset proxy */
if (optarg)
{
is_transparent_proxy=0;
strcpy(config_proxy, optarg);
}
else
{
fprintf (stderr, "%s error: -x option should be followed by a proxy IP or name.\n", __func__);
return -1;
}
break;
default:
fprintf (stderr, "%s error: not supported option\n", __func__);
print_help ();
return -1;
}
}
if (optind < argc)
{
fprintf (stderr, "%s error: non-option argv-elements: ", __func__);
while (optind < argc)
fprintf (stderr, "%s ", argv[optind++]);
fprintf (stderr, "\n");
print_help ();
return -1;
}
return 0;
}
void print_help ()
{
fprintf (stderr, "Note, to run your load, create your batch configuration file.\n\n");
fprintf (stderr, "usage: run as a root:\n");
fprintf (stderr, "./curl-loader -f <configuration file name> with [other options below]:\n");
fprintf (stderr, " -c[onnection establishment timeout, seconds]\n");
fprintf (stderr, " -d[etailed logging; outputs to logfile headers and bodies of requests/responses. Good for text pages/files]\n");
fprintf (stderr, " -e[rror drop client (smooth mode). Client on error doesn't attempt next cycle]\n");
fprintf (stderr, " -i[ntermediate (snapshot) statistics time interval (default 3 sec)]\n");
fprintf (stderr, " -l[ogfile max size in MB (default 1024). On the size reached, file pointer rewinded]\n");
//fprintf (stderr, " -m[ode of loading, 0 - hyper (default), 1 - smooth]\n");
//fprintf (stderr, " -r[euse onnections disabled. Close connections and re-open them. Try with and without]\n");
fprintf (stderr, " -t[hreads number to run batch clients as sub-batches in several threads. Works to utilize SMP/m-core HW]\n");
fprintf (stderr, " -v[erbose output to the logfiles; includes info about headers sent/received]\n");
fprintf (stderr, " -u[rl logging - logs url names to logfile, when -v verbose option is used]\n");
fprintf (stderr, " -w[arnings skip]\n");
fprintf (stderr, " -x[set|unset proxy] \"<proxy:port>\"\n");
fprintf (stderr, "\n");
fprintf (stderr, "For more examples of configuration files please, look at \"conf-examples\" directory.\n");
fprintf (stderr, "\n");
fprintf (stderr, "Running thousands and more clients, please do not forget to consider the options:\n");
fprintf (stderr, "- to increase limit of open descriptors in shell by running e.g. ulimit -n 19999:\n");
fprintf (stderr, "- to increase total limit of open descriptors in systeme somewhere in /proc\n");
fprintf (stderr, "- to consider reusing sockets in time-wait state: by echo 1 > \n");
fprintf (stderr, " /proc/sys/net/ipv4/tcp_tw_recycle\n");
fprintf (stderr, "- and/or echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse\n");
fprintf (stderr, "\n");
fprintf (stderr, "\n");
}