-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbatch.h
320 lines (228 loc) · 8.22 KB
/
batch.h
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
* batch.h
*
* 2006-2007 Copyright (c)
* Robert Iakobashvili, <[email protected]>
* Michael Moser, <[email protected]>
* 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
*/
#ifndef BATCH_H
#define BATCH_H
#include <stddef.h>
#include <netinet/in.h>
#include <pthread.h>
#include <curl/curl.h>
#include "timer_queue.h"
#include "timer_node.h"
#include "url.h"
#include "statistics.h"
#define BATCH_NAME_SIZE 64
#define BATCH_NAME_EXTRA_SIZE 12
#define POST_BUFFER_SIZE 256
#define CUSTOM_HDRS_MAX_NUM 64
typedef enum form_usagetype
{
FORM_USAGETYPE_START = 0,
FORM_USAGETYPE_UNIQUE_USERS_AND_PASSWORDS,
FORM_USAGETYPE_UNIQUE_USERS_SAME_PASSWORD,
FORM_USAGETYPE_SINGLE_USER,
FORM_USAGETYPE_RECORDS_FROM_FILE,
FORM_USAGETYPE_AS_IS,
FORM_USAGETYPE_END,
} form_usagetype;
struct client_context;
struct event_base;
struct event;
/**********************
struct batch_context
Batch is a group of clients with the same characteristics and loading
behavior.
The structure is used to keep all batch-relevant configuration and run-time
information.
*/
typedef struct batch_context
{
/*------------------------ GENERAL SECTION ------------------------------ */
/* Some non-empty name of a batch load without empty spaces, tabs, etc */
char batch_name[BATCH_NAME_SIZE];
/* Logfile <batch-name>.log */
char batch_logfile[BATCH_NAME_SIZE+BATCH_NAME_EXTRA_SIZE];
/* Statistics file <batch-name>.txt */
char batch_statistics[BATCH_NAME_SIZE+BATCH_NAME_EXTRA_SIZE];
/* Operational statistics file <batch-name>.ops */
char batch_opstats[BATCH_NAME_SIZE+BATCH_NAME_EXTRA_SIZE];
/* Maximum number of clients (each client with its own IP-address) in the batch */
int client_num_max;
/* Number of clients to start with */
int client_num_start;
/*
Clients added per second for the loading start phase.
*/
long clients_rampup_inc;
/* Name of the network interface to be used for loading, e.g. "eth0", "eth1:16" */
char net_interface[16];
/* Flag: 0 means IPv4, 1 means IPv6 */
int ipv6;
/* Minimal IPv4-address of a client in the batch (host order). */
long ip_addr_min;
/* Maximum IPv4-address of a client in the batch (host order).*/
long ip_addr_max;
/*
Shared ip-addresses to be used by clients. Former ip-common for the single
common for all clients ip-address.
*/
int ip_shared_num;
size_t ipv4_shared_index;
/*
CIDR netmask number from 0 to 128, like 16 or 24, etc. If the input netmask is
a dotted IPv4 address, we convert it to CIDR by calculating number of 1 bits.
*/
int cidr_netmask;
/* "global", "host", "link", for IPV6 only "site" */
char scope[16];
/* Minimal IPv6-address of a client in the batch. */
struct in6_addr ipv6_addr_min;
/* Miximum IPv6-address of a client in the batch. */
struct in6_addr ipv6_addr_max;
struct in6_addr in6_prev, in6_new;
size_t ipv6_shared_index;
/*
Number of cycles to repeat the urls downloads and afterwards sleeping
cycles. Zero means run it until time to run is exhausted.
*/
long cycles_num;
/*
Time to run in msec. Zero means time to run is infinite.
*/
unsigned long run_time;
/*
Client fixed request rate per second. Zero means send request after
receiving reply.
*/
int req_rate;
/*
User-agent string to appear in the HTTP 1/1 requests.
*/
char user_agent[256];
/*------- URL SECTION - fetching urls ----- */
/* Number of total urls, should be more or equal to 1 */
int urls_num;
/* Array of all url contexts */
url_context* url_ctx_array;
/*
Index of the parsed url in url_ctx_array below.
*/
int url_index;
/*
Index of the first cycling url. Minimal index of url not marked
as <dont_cycle>.
*/
int first_cycling_url;
/*
Index of the last cycling url. Maximum index of url not marked
as <dont_cycle>.
*/
int last_cycling_url;
/* Indicates, that all cycling operations have been done */
int cycling_completed;
/*------------------------- ASSISTING SECTION ----------------------------*/
/*
The sequence num of a batch in batch_array. Zero batch is the batch group
leader and is in charge for statistics presentation on behave of all other batches
*/
size_t batch_id;
/* Thread id, filled by pthread_create (). Used by pthread_join () syscall */
pthread_t thread_id;
/* Multiple handle for curl. Contains all curl handles of a batch */
CURLM *multiple_handle;
/* Assisting array of pointers to ip-addresses */
char** ip_addr_array;
/* Current parsing state. Used on reading and parsing conf-file. */
size_t batch_init_state;
/* Common error buffer for all batch clients */
char error_buffer[CURL_ERROR_SIZE];
/* Array of all client contexts for the batch */
struct client_context* cctx_array;
/* Number of clients free to send fixed rate requests */
int free_clients_count;
/* List of clients free to send fixed rate requests */
int* free_clients;
/* Indicates that request scheduling is over */
int requests_completed;
/* Request rate timer invocation sequence number within a second */
int req_rate_timer_invocation;
/* Counter used mainly by smooth mode: active clients */
int active_clients_count;
/* Number of clients "sleeping" their after url timeout. */
int sleeping_clients_count;
/*
Whether to do gradual increase of loading clients to prevent
a simulteneous huge flow of client requests to server.
*/
int do_client_num_gradual_increase;
int stop_client_num_gradual_increase;
/*
Number of already scheduled clients. Used to schedule new
clients in a gradual fashion, when <clients_rampup_inc> is positive.
*/
int clients_current_sched_num;
/* Waiting queue timeouts in smooth mode */
timer_queue* waiting_queue;
/* The timer-node for timer testing the logfile size */
timer_node logfile_timer_node;
/* The timer-node for timer to add more clients during ramp-up period. */
timer_node clients_num_inc_timer_node;
/* The timer-node for timer checking user-input at a screen (stdin). */
timer_node screen_input_timer_node;
/* The timer-node for fixed request rate timer. */
timer_node req_rate_timer_node;
/* Event base from event_init () of libevent. */
struct event_base* eb;
/* Pointer to structure used by lebevent. */
struct event* timer_event;
/* Pointer to structure used by lebevent. */
struct event* timer_next_load_event;
/*--------------- STATISTICS --------------------------------------------*/
/* The file to be used for statistics output */
FILE* statistics_file;
/* The file to be used for operational statistics output */
FILE* opstats_file;
/* Dump operational statistics indicator, 0: no dump */
int dump_opstats;
/* Timestamp, when the loading started */
unsigned long start_time;
/* The last timestamp */
unsigned long last_measure;
/* HTTP counters since the last measurements */
stat_point http_delta;
/* HTTP counters since the loading started */
stat_point http_total;
/* HTTPS counters since the last measurements */
stat_point https_delta;
/* HTTPS counters since the loading started */
stat_point https_total;
/* Operations statistics */
op_stat_point op_delta;
op_stat_point op_total;
/* Count of response times dumped before new-line,
used to limit line length */
int ct_resps;
} batch_context;
int is_batch_group_leader (batch_context* bctx);
size_t next_ipv4_shared_index (batch_context* bctx);
size_t next_ipv6_shared_index (batch_context* bctx);
#endif /* BATCH_H */