aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/perf_get_concurrent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/perf_get_concurrent.c')
-rw-r--r--src/testcurl/perf_get_concurrent.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/testcurl/perf_get_concurrent.c b/src/testcurl/perf_get_concurrent.c
index deb949b2..da206490 100644
--- a/src/testcurl/perf_get_concurrent.c
+++ b/src/testcurl/perf_get_concurrent.c
@@ -153,7 +153,7 @@ ahc_echo (void *cls,
153 153
154 154
155static pid_t 155static pid_t
156do_gets () 156do_gets (int port)
157{ 157{
158 pid_t ret; 158 pid_t ret;
159 CURL *c; 159 CURL *c;
@@ -161,6 +161,9 @@ do_gets ()
161 unsigned int i; 161 unsigned int i;
162 unsigned int j; 162 unsigned int j;
163 pid_t par[PAR]; 163 pid_t par[PAR];
164 char url[64];
165
166 sprintf(url, "http://localhost:%d/hello_world", port);
164 167
165 ret = fork (); 168 ret = fork ();
166 if (ret == -1) abort (); 169 if (ret == -1) abort ();
@@ -174,7 +177,7 @@ do_gets ()
174 for (i=0;i<ROUNDS;i++) 177 for (i=0;i<ROUNDS;i++)
175 { 178 {
176 c = curl_easy_init (); 179 c = curl_easy_init ();
177 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); 180 curl_easy_setopt (c, CURLOPT_URL, url);
178 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer); 181 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
179 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL); 182 curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
180 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); 183 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
@@ -220,16 +223,16 @@ join_gets (pid_t pid)
220 223
221 224
222static int 225static int
223testInternalGet (int poll_flag) 226testInternalGet (int port, int poll_flag)
224{ 227{
225 struct MHD_Daemon *d; 228 struct MHD_Daemon *d;
226 229
227 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, 230 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag,
228 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 231 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
229 if (d == NULL) 232 if (d == NULL)
230 return 1; 233 return 1;
231 start_timer (); 234 start_timer ();
232 join_gets (do_gets ()); 235 join_gets (do_gets (port));
233 stop (poll_flag ? "internal poll" : "internal select"); 236 stop (poll_flag ? "internal poll" : "internal select");
234 MHD_stop_daemon (d); 237 MHD_stop_daemon (d);
235 return 0; 238 return 0;
@@ -237,40 +240,40 @@ testInternalGet (int poll_flag)
237 240
238 241
239static int 242static int
240testMultithreadedGet (int poll_flag) 243testMultithreadedGet (int port, int poll_flag)
241{ 244{
242 struct MHD_Daemon *d; 245 struct MHD_Daemon *d;
243 246
244 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, 247 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag,
245 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 248 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
246 if (d == NULL) 249 if (d == NULL)
247 return 16; 250 return 16;
248 start_timer (); 251 start_timer ();
249 join_gets (do_gets ()); 252 join_gets (do_gets (port));
250 stop (poll_flag ? "thread with poll" : "thread with select"); 253 stop (poll_flag ? "thread with poll" : "thread with select");
251 MHD_stop_daemon (d); 254 MHD_stop_daemon (d);
252 return 0; 255 return 0;
253} 256}
254 257
255static int 258static int
256testMultithreadedPoolGet (int poll_flag) 259testMultithreadedPoolGet (int port, int poll_flag)
257{ 260{
258 struct MHD_Daemon *d; 261 struct MHD_Daemon *d;
259 262
260 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, 263 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag,
261 1081, NULL, NULL, &ahc_echo, "GET", 264 port, NULL, NULL, &ahc_echo, "GET",
262 MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); 265 MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END);
263 if (d == NULL) 266 if (d == NULL)
264 return 16; 267 return 16;
265 start_timer (); 268 start_timer ();
266 join_gets (do_gets ()); 269 join_gets (do_gets (port));
267 stop (poll_flag ? "thread pool with poll" : "thread pool with select"); 270 stop (poll_flag ? "thread pool with poll" : "thread pool with select");
268 MHD_stop_daemon (d); 271 MHD_stop_daemon (d);
269 return 0; 272 return 0;
270} 273}
271 274
272static int 275static int
273testExternalGet () 276testExternalGet (int port)
274{ 277{
275 struct MHD_Daemon *d; 278 struct MHD_Daemon *d;
276 pid_t pid; 279 pid_t pid;
@@ -283,11 +286,11 @@ testExternalGet ()
283 int tret; 286 int tret;
284 287
285 d = MHD_start_daemon (MHD_USE_DEBUG, 288 d = MHD_start_daemon (MHD_USE_DEBUG,
286 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); 289 port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
287 if (d == NULL) 290 if (d == NULL)
288 return 256; 291 return 256;
289 start_timer (); 292 start_timer ();
290 pid = do_gets (); 293 pid = do_gets (port);
291 while (0 == waitpid (pid, NULL, WNOHANG)) 294 while (0 == waitpid (pid, NULL, WNOHANG))
292 { 295 {
293 max = 0; 296 max = 0;
@@ -316,6 +319,7 @@ int
316main (int argc, char *const *argv) 319main (int argc, char *const *argv)
317{ 320{
318 unsigned int errorCount = 0; 321 unsigned int errorCount = 0;
322 int port = 1081;
319 323
320 oneone = NULL != strstr (argv[0], "11"); 324 oneone = NULL != strstr (argv[0], "11");
321 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 325 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
@@ -323,13 +327,13 @@ main (int argc, char *const *argv)
323 response = MHD_create_response_from_buffer (strlen ("/hello_world"), 327 response = MHD_create_response_from_buffer (strlen ("/hello_world"),
324 "/hello_world", 328 "/hello_world",
325 MHD_RESPMEM_MUST_COPY); 329 MHD_RESPMEM_MUST_COPY);
326 errorCount += testInternalGet (0); 330 errorCount += testInternalGet (port++, 0);
327 errorCount += testMultithreadedGet (0); 331 errorCount += testMultithreadedGet (port++, 0);
328 errorCount += testMultithreadedPoolGet (0); 332 errorCount += testMultithreadedPoolGet (port++, 0);
329 errorCount += testExternalGet (); 333 errorCount += testExternalGet (port++);
330 errorCount += testInternalGet (MHD_USE_POLL); 334 errorCount += testInternalGet (port++, MHD_USE_POLL);
331 errorCount += testMultithreadedGet (MHD_USE_POLL); 335 errorCount += testMultithreadedGet (port++, MHD_USE_POLL);
332 errorCount += testMultithreadedPoolGet (MHD_USE_POLL); 336 errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL);
333 MHD_destroy_response (response); 337 MHD_destroy_response (response);
334 if (errorCount != 0) 338 if (errorCount != 0)
335 fprintf (stderr, "Error (code: %u)\n", errorCount); 339 fprintf (stderr, "Error (code: %u)\n", errorCount);