aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2013-02-15 11:50:45 +0100
committerLinus Nielsen Feltzing <linus@haxx.se>2013-03-13 23:55:24 +0100
commit0f147887b0d592d5fa72215282e84103eb165ad7 (patch)
tree4ad5bc8185f3f8df0eed54ee45afd26d692b44a0 /tests/libtest
parent911b2d3f677eb1538d8469d43df5780e8b7c7abc (diff)
Multiple pipelines and limiting the number of connections.
Introducing a number of options to the multi interface that allows for multiple pipelines to the same host, in order to optimize the balance between the penalty for opening new connections and the potential pipelining latency. Two new options for limiting the number of connections: CURLMOPT_MAX_HOST_CONNECTIONS - Limits the number of running connections to the same host. When adding a handle that exceeds this limit, that handle will be put in a pending state until another handle is finished, so we can reuse the connection. CURLMOPT_MAX_TOTAL_CONNECTIONS - Limits the number of connections in total. When adding a handle that exceeds this limit, that handle will be put in a pending state until another handle is finished. The free connection will then be reused, if possible, or closed if the pending handle can't reuse it. Several new options for pipelining: CURLMOPT_MAX_PIPELINE_LENGTH - Limits the pipeling length. If a pipeline is "full" when a connection is to be reused, a new connection will be opened if the CURLMOPT_MAX_xxx_CONNECTIONS limits allow it. If not, the handle will be put in a pending state until a connection is ready (either free or a pipe got shorter). CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE - A pipelined connection will not be reused if it is currently processing a transfer with a content length that is larger than this. CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE - A pipelined connection will not be reused if it is currently processing a chunk larger than this. CURLMOPT_PIPELINING_SITE_BL - A blacklist of hosts that don't allow pipelining. CURLMOPT_PIPELINING_SERVER_BL - A blacklist of server types that don't allow pipelining. See the curl_multi_setopt() man page for details.
Diffstat (limited to 'tests/libtest')
-rw-r--r--tests/libtest/.gitignore2
-rw-r--r--tests/libtest/Makefile.inc10
-rw-r--r--tests/libtest/lib1900.c256
-rw-r--r--tests/libtest/lib530.c15
-rw-r--r--tests/libtest/libntlmconnect.c6
5 files changed, 285 insertions, 4 deletions
diff --git a/tests/libtest/.gitignore b/tests/libtest/.gitignore
index 28e83c08d..7fd6e7e30 100644
--- a/tests/libtest/.gitignore
+++ b/tests/libtest/.gitignore
@@ -1,5 +1,7 @@
chkhostname
lib5[0-9][0-9]
lib150[0-9]
+lib19[0-9][0-9]
+lib2033
libauthretry
libntlmconnect
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index 88fc7d8fa..391c6255e 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -23,7 +23,9 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
lib582 lib583 lib585 lib586 lib587 \
lib590 lib591 lib597 lib598 lib599 \
\
- lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508
+ lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
+ lib1900 \
+ lib2033
chkhostname_SOURCES = chkhostname.c ../../lib/curl_gethostname.c
chkhostname_LDADD = @CURL_NETWORK_LIBS@
@@ -323,3 +325,9 @@ lib1507_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1507
lib1508_SOURCES = lib1508.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1508_LDADD = $(TESTUTIL_LIBS)
lib1508_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1508
+
+lib1900_SOURCES = lib1900.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
+lib1900_CPPFLAGS = $(AM_CPPFLAGS)
+
+lib2033_SOURCES = libntlmconnect.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
+lib2033_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_PIPELINING
diff --git a/tests/libtest/lib1900.c b/tests/libtest/lib1900.c
new file mode 100644
index 000000000..b2a943440
--- /dev/null
+++ b/tests/libtest/lib1900.c
@@ -0,0 +1,256 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2013, Linus Nielsen Feltzing, <linus@haxx.se>
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "testutil.h"
+#include "warnless.h"
+#include "memdebug.h"
+
+#define TEST_HANG_TIMEOUT 60 * 1000
+#define MAX_URLS 200
+#define MAX_BLACKLIST 20
+
+int urltime[MAX_URLS];
+char *urlstring[MAX_URLS];
+CURL *handles[MAX_URLS];
+char *site_blacklist[MAX_BLACKLIST];
+char *server_blacklist[MAX_BLACKLIST];
+int num_handles;
+int blacklist_num_servers;
+int blacklist_num_sites;
+
+int parse_url_file(const char *filename);
+void free_urls(void);
+int create_handles(void);
+void setup_handle(char *base_url, CURLM *m, int handlenum);
+void remove_handles(void);
+
+static size_t
+write_callback(void *contents, size_t size, size_t nmemb, void *userp)
+{
+ size_t realsize = size * nmemb;
+ (void)contents;
+ (void)userp;
+
+ return realsize;
+}
+
+int parse_url_file(const char *filename)
+{
+ FILE *f;
+ int time;
+ char buf[200];
+
+ num_handles = 0;
+ blacklist_num_sites = 0;
+ blacklist_num_servers = 0;
+
+ f = fopen(filename, "rb");
+ if(!f)
+ return 0;
+
+ while(!feof(f)) {
+ if(fscanf(f, "%d %s\n", &time, buf)) {
+ urltime[num_handles] = time;
+ urlstring[num_handles] = strdup(buf);
+ num_handles++;
+ continue;
+ }
+
+ if(fscanf(f, "blacklist_site %s\n", buf)) {
+ site_blacklist[blacklist_num_sites] = strdup(buf);
+ blacklist_num_sites++;
+ continue;
+ }
+
+ break;
+ }
+ fclose(f);
+
+ site_blacklist[blacklist_num_sites] = NULL;
+ server_blacklist[blacklist_num_servers] = NULL;
+ return num_handles;
+}
+
+void free_urls(void)
+{
+ int i;
+ for(i = 0;i < num_handles;i++) {
+ free(urlstring[i]);
+ }
+ for(i = 0;i < blacklist_num_servers;i++) {
+ free(server_blacklist[i]);
+ }
+ for(i = 0;i < blacklist_num_sites;i++) {
+ free(site_blacklist[i]);
+ }
+}
+
+int create_handles(void)
+{
+ int i;
+
+ for(i = 0;i < num_handles;i++) {
+ handles[i] = curl_easy_init();
+ }
+ return 0;
+}
+
+void setup_handle(char *base_url, CURLM *m, int handlenum)
+{
+ char urlbuf[256];
+
+ sprintf(urlbuf, "%s%s", base_url, urlstring[handlenum]);
+ curl_easy_setopt(handles[handlenum], CURLOPT_URL, urlbuf);
+ curl_easy_setopt(handles[handlenum], CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt(handles[handlenum], CURLOPT_FAILONERROR, 1L);
+ curl_easy_setopt(handles[handlenum], CURLOPT_WRITEFUNCTION, write_callback);
+ curl_easy_setopt(handles[handlenum], CURLOPT_WRITEDATA, NULL);
+ curl_multi_add_handle(m, handles[handlenum]);
+}
+
+void remove_handles(void)
+{
+ int i;
+
+ for(i = 0;i < num_handles;i++) {
+ if(handles[i])
+ curl_easy_cleanup(handles[i]);
+ }
+}
+
+int test(char *URL)
+{
+ int res = 0;
+ CURLM *m = NULL;
+ CURLMsg *msg; /* for picking up messages with the transfer status */
+ int msgs_left; /* how many messages are left */
+ int running;
+ int handlenum = 0;
+ struct timeval last_handle_add;
+
+ if(parse_url_file("log/urls.txt") <= 0)
+ goto test_cleanup;
+
+ start_test_timing();
+
+ curl_global_init(CURL_GLOBAL_ALL);
+
+ m = curl_multi_init();
+
+ create_handles();
+
+ multi_setopt(m, CURLMOPT_PIPELINING, 1L);
+ multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L);
+ multi_setopt(m, CURLMOPT_MAX_PIPELINE_LENGTH, 3L);
+ multi_setopt(m, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, 15000L);
+ multi_setopt(m, CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, 10000L);
+
+ multi_setopt(m, CURLMOPT_PIPELINING_SITE_BL, site_blacklist);
+ multi_setopt(m, CURLMOPT_PIPELINING_SERVER_BL, server_blacklist);
+
+ gettimeofday(&last_handle_add, NULL);
+
+ for(;;) {
+ struct timeval interval;
+ struct timeval now;
+ long int msnow, mslast;
+ fd_set rd, wr, exc;
+ int maxfd = -99;
+ long timeout;
+
+ interval.tv_sec = 1;
+ interval.tv_usec = 0;
+
+ if(handlenum < num_handles) {
+ gettimeofday(&now, NULL);
+ msnow = now.tv_sec * 1000 + now.tv_usec / 1000;
+ mslast = last_handle_add.tv_sec * 1000 + last_handle_add.tv_usec / 1000;
+ if(msnow - mslast >= urltime[handlenum] && handlenum < num_handles) {
+ fprintf(stdout, "Adding handle %d\n", handlenum);
+ setup_handle(URL, m, handlenum);
+ last_handle_add = now;
+ handlenum++;
+ }
+ }
+
+ curl_multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
+ /* See how the transfers went */
+ while ((msg = curl_multi_info_read(m, &msgs_left))) {
+ if (msg->msg == CURLMSG_DONE) {
+ int i, found = 0;
+
+ /* Find out which handle this message is about */
+ for (i = 0; i < num_handles; i++) {
+ found = (msg->easy_handle == handles[i]);
+ if(found)
+ break;
+ }
+
+ printf("Handle %d Completed with status %d\n", i, msg->data.result);
+ curl_multi_remove_handle(m, handles[i]);
+ }
+ }
+
+ if(handlenum == num_handles && !running) {
+ break; /* done */
+ }
+
+ FD_ZERO(&rd);
+ FD_ZERO(&wr);
+ FD_ZERO(&exc);
+
+ curl_multi_fdset(m, &rd, &wr, &exc, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ curl_multi_timeout(m, &timeout);
+
+ if(timeout < 0)
+ timeout = 1;
+
+ interval.tv_sec = timeout / 1000;
+ interval.tv_usec = (timeout % 1000) * 1000;
+
+ interval.tv_sec = 0;
+ interval.tv_usec = 1000;
+
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
+
+ abort_on_test_timeout();
+ }
+
+test_cleanup:
+
+ remove_handles();
+
+ /* undocumented cleanup sequence - type UB */
+
+ curl_multi_cleanup(m);
+ curl_global_cleanup();
+
+ free_urls();
+ return res;
+}
diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c
index ad84ff8a5..06a846439 100644
--- a/tests/libtest/lib530.c
+++ b/tests/libtest/lib530.c
@@ -37,6 +37,7 @@ int test(char *URL)
CURLM *m = NULL;
int i;
char target_url[256];
+ int handles_added = 0;
for(i=0; i < NUM_HANDLES; i++)
curl[i] = NULL;
@@ -59,10 +60,13 @@ int test(char *URL)
easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
/* include headers */
easy_setopt(curl[i], CURLOPT_HEADER, 1L);
- /* add handle to multi */
- multi_add_handle(m, curl[i]);
}
+ /* Add the first handle to multi. We do this to let libcurl detect
+ that the server can do pipelining. The rest of the handles will be
+ added later. */
+ multi_add_handle(m, curl[handles_added++]);
+
multi_setopt(m, CURLMOPT_PIPELINING, 1L);
fprintf(stderr, "Start at URL 0\n");
@@ -79,9 +83,14 @@ int test(char *URL)
abort_on_test_timeout();
- if(!running)
+ if(!running && handles_added >= NUM_HANDLES)
break; /* done */
+ /* Add the rest of the handles now that the first handle has sent the
+ request. */
+ while(handles_added < NUM_HANDLES)
+ multi_add_handle(m, curl[handles_added++]);
+
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
diff --git a/tests/libtest/libntlmconnect.c b/tests/libtest/libntlmconnect.c
index b540ebf58..cd507dfa1 100644
--- a/tests/libtest/libntlmconnect.c
+++ b/tests/libtest/libntlmconnect.c
@@ -125,6 +125,12 @@ int test(char *url)
multi_init(multi);
+#ifdef USE_PIPELINING
+ multi_setopt(multi, CURLMOPT_PIPELINING, 1);
+ multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS, 5);
+ multi_setopt(multi, CURLMOPT_MAX_TOTAL_CONNECTIONS, 10);
+#endif
+
for(;;) {
struct timeval interval;
fd_set fdread;