commit 20699d328b1327233cb9787ac4f92be09d244f4f parent a9e36d372055530d4e949e5dd5369be87033a090 Author: Evgeny Grin (Karlson2k) <k2k@narod.ru> Date: Thu, 6 Mar 2014 13:22:35 +0000 Use number of CPUs in tests and examples Diffstat:
25 files changed, 188 insertions(+), 24 deletions(-)
diff --git a/configure.ac b/configure.ac @@ -645,6 +645,8 @@ AC_ARG_ENABLE([coverage], AC_MSG_RESULT($use_gcov) AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"]) +AX_COUNT_CPUS +AC_SUBST([CPU_COUNT]) AC_SUBST(MHD_LIB_CPPFLAGS) AC_SUBST(MHD_LIB_CFLAGS) diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am @@ -6,6 +6,8 @@ AM_CPPFLAGS = \ AM_CFLAGS = @LIBGCRYPT_CFLAGS@ +CPU_COUNT_DEF = -DCPU_COUNT=$(CPU_COUNT) + if USE_COVERAGE AM_CFLAGS += --coverage endif @@ -72,6 +74,8 @@ demo_SOURCES = \ demo.c demo_CFLAGS = \ $(PTHREAD_CFLAGS) $(AM_CFLAGS) +demo_CPPFLAGS = \ + $(AM_CPPFLAGS) $(CPU_COUNT_DEF) demo_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ $(PTHREAD_LIBS) -lmagic @@ -87,11 +91,15 @@ mhd2spdy_LDADD = \ benchmark_SOURCES = \ benchmark.c +benchmark_CPPFLAGS = \ + $(AM_CPPFLAGS) $(CPU_COUNT_DEF) benchmark_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la benchmark_https_SOURCES = \ benchmark_https.c +benchmark_https_CPPFLAGS = \ + $(AM_CPPFLAGS) $(CPU_COUNT_DEF) benchmark_https_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la diff --git a/src/examples/benchmark.c b/src/examples/benchmark.c @@ -25,6 +25,13 @@ #include "platform.h" #include <microhttpd.h> +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" @@ -34,7 +41,7 @@ * Number of threads to run in the thread pool. Should (roughly) match * the number of cores on your system. */ -#define NUMBER_OF_THREADS 4 +#define NUMBER_OF_THREADS CPU_COUNT static unsigned int small_deltas[SMALL]; diff --git a/src/examples/benchmark_https.c b/src/examples/benchmark_https.c @@ -25,6 +25,13 @@ #include "platform.h" #include <microhttpd.h> +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" @@ -34,7 +41,7 @@ * Number of threads to run in the thread pool. Should (roughly) match * the number of cores on your system. */ -#define NUMBER_OF_THREADS 4 +#define NUMBER_OF_THREADS CPU_COUNT static unsigned int small_deltas[SMALL]; diff --git a/src/examples/demo.c b/src/examples/demo.c @@ -39,11 +39,18 @@ #include <limits.h> #include <ctype.h> +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + /** * Number of threads to run in the thread pool. Should (roughly) match * the number of cores on your system. */ -#define NUMBER_OF_THREADS 8 +#define NUMBER_OF_THREADS CPU_COUNT /** * How many bytes of a file do we give to libmagic to determine the mime type? diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am @@ -9,6 +9,7 @@ if ENABLE_HTTPS endif AM_CPPFLAGS = \ +-DCPU_COUNT=$(CPU_COUNT) \ -I$(top_srcdir) \ -I$(top_srcdir)/src/microhttpd \ -I$(top_srcdir)/src/include \ diff --git a/src/testcurl/https/Makefile.am b/src/testcurl/https/Makefile.am @@ -4,6 +4,8 @@ if USE_COVERAGE AM_CFLAGS = --coverage endif +CPU_COUNT_DEF = -DCPU_COUNT=$(CPU_COUNT) + AM_CPPFLAGS = \ -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/microhttpd \ @@ -59,6 +61,8 @@ test_tls_options_LDADD = \ test_https_get_parallel_SOURCES = \ test_https_get_parallel.c \ tls_test_common.c +test_https_get_parallel_CPPFLAGS = \ + $(AM_CPPFLAGS) $(CPU_COUNT_DEF) test_https_get_parallel_CFLAGS = \ $(PTHREAD_CFLAGS) $(AM_CFLAGS) test_https_get_parallel_LDADD = \ @@ -77,6 +81,8 @@ test_empty_response_LDADD = \ test_https_get_parallel_threads_SOURCES = \ test_https_get_parallel_threads.c \ tls_test_common.c +test_https_get_parallel_threads_CPPFLAGS = \ + $(AM_CPPFLAGS) $(CPU_COUNT_DEF) test_https_get_parallel_threads_CFLAGS = \ $(PTHREAD_CFLAGS) $(AM_CFLAGS) test_https_get_parallel_threads_LDADD = \ diff --git a/src/testcurl/https/test_https_get_parallel.c b/src/testcurl/https/test_https_get_parallel.c @@ -33,6 +33,13 @@ #include <gcrypt.h> #include "tls_test_common.h" +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 4 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 4 +#endif + extern const char srv_key_pem[]; extern const char srv_self_signed_cert_pem[]; @@ -94,7 +101,7 @@ test_parallel_clients (void * cls, const char *cipher_suite, int curl_proto_version) { int i; - int client_count = 3; + int client_count = (CPU_COUNT - 1); void *client_thread_ret; pthread_t client_arr[client_count]; struct https_test_data client_args = diff --git a/src/testcurl/https/test_https_get_parallel_threads.c b/src/testcurl/https/test_https_get_parallel_threads.c @@ -35,6 +35,13 @@ #include <gcrypt.h> #include "tls_test_common.h" +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 4 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 4 +#endif + extern const char srv_key_pem[]; extern const char srv_self_signed_cert_pem[]; @@ -94,7 +101,7 @@ test_parallel_clients (void *cls, const char *cipher_suite, int curl_proto_version) { int i; - int client_count = 3; + int client_count = (CPU_COUNT - 1); void *client_thread_ret; pthread_t client_arr[client_count]; struct https_test_data client_args = diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c @@ -50,6 +50,13 @@ #include <sys/socket.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + /** * How many rounds of operations do we do for each * test? @@ -306,7 +313,7 @@ testMultithreadedPoolGet (int port, int poll_flag) cbc.size = 2048; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, port, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; start_timer (); diff --git a/src/testcurl/perf_get_concurrent.c b/src/testcurl/perf_get_concurrent.c @@ -41,6 +41,13 @@ #include <time.h> #include "gauger.h" +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + /** * How many rounds of operations do we do for each * test (total number of requests will be ROUNDS * PAR). @@ -50,7 +57,7 @@ /** * How many requests do we do in parallel? */ -#define PAR 4 +#define PAR CPU_COUNT /** * Do we use HTTP 1.1? @@ -262,7 +269,7 @@ testMultithreadedPoolGet (int port, int poll_flag) d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, port, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; start_timer (); diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c @@ -46,6 +46,13 @@ #include <sys/socket.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int oneone; struct CBC @@ -214,7 +221,7 @@ testMultithreadedPoolGet (int poll_flag) cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, 1081, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c @@ -40,6 +40,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + struct CBC { char *buf; @@ -243,7 +250,7 @@ testMultithreadedPoolGet () cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); diff --git a/src/testcurl/test_get_response_cleanup.c b/src/testcurl/test_get_response_cleanup.c @@ -48,6 +48,13 @@ #include <windows.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + #define TESTSTR "/* DO NOT CHANGE THIS LINE */" static int oneone; @@ -202,7 +209,7 @@ testMultithreadedPoolGet () d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 64; ok = 1; diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c @@ -40,6 +40,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + #define TESTSTR "This is the content of the test file we are sending using sendfile (if available)" char *sourcefile; @@ -218,7 +225,7 @@ testMultithreadedPoolGet () cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); diff --git a/src/testcurl/test_iplimit.c b/src/testcurl/test_iplimit.c @@ -44,6 +44,13 @@ #include <windows.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int oneone; struct CBC @@ -208,7 +215,7 @@ testMultithreadedPoolGet () d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_PER_IP_CONNECTION_LIMIT, 2, - MHD_OPTION_THREAD_POOL_SIZE, 4, + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; diff --git a/src/testcurl/test_large_put.c b/src/testcurl/test_large_put.c @@ -36,6 +36,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int oneone; /** @@ -267,7 +274,7 @@ testMultithreadedPoolPut () d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, &done_flag, - MHD_OPTION_THREAD_POOL_SIZE, 4, + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (1024*1024), MHD_OPTION_END); if (d == NULL) diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c @@ -43,6 +43,13 @@ #include <windows.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + #define POST_DATA "name=daniel&project=curl" static int oneone; @@ -273,7 +280,7 @@ testMultithreadedPoolPost () cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, NULL, - MHD_OPTION_THREAD_POOL_SIZE, 4, + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, MHD_OPTION_END); if (d == NULL) diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c @@ -37,6 +37,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + #define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" #define LOOPCOUNT 1000 @@ -242,7 +249,7 @@ testMultithreadedPoolPost () cbc.size = 2048; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, NULL, - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; for (i = 0; i < LOOPCOUNT; i++) diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c @@ -39,6 +39,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int oneone; struct CBC @@ -290,7 +297,7 @@ testMultithreadedPoolPost () cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, NULL, - MHD_OPTION_THREAD_POOL_SIZE, 4, + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL, MHD_OPTION_END); if (d == NULL) diff --git a/src/testcurl/test_process_headers.c b/src/testcurl/test_process_headers.c @@ -37,6 +37,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int oneone; struct CBC @@ -250,7 +257,7 @@ testMultithreadedPoolGet () cbc.pos = 0; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 21080, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); diff --git a/src/testcurl/test_put.c b/src/testcurl/test_put.c @@ -36,6 +36,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int oneone; struct CBC @@ -240,7 +247,7 @@ testMultithreadedPoolPut () d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, &done_flag, - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); diff --git a/src/testcurl/test_put_chunked.c b/src/testcurl/test_put_chunked.c @@ -37,6 +37,13 @@ #include <unistd.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + struct CBC { char *buf; @@ -250,7 +257,7 @@ testMultithreadedPoolPut () d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 11081, NULL, NULL, &ahc_echo, &done_flag, - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c @@ -39,6 +39,13 @@ #include <sys/socket.h> #endif +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int oneone; @@ -436,16 +443,16 @@ main (int argc, char *const *argv) return 2; errorCount += testGet (MHD_USE_SELECT_INTERNALLY, 0, 0); errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION, 0, 0); - errorCount += testGet (MHD_USE_SELECT_INTERNALLY, 4, 0); + errorCount += testGet (MHD_USE_SELECT_INTERNALLY, CPU_COUNT, 0); errorCount += testExternalGet (); #ifndef WINDOWS errorCount += testGet (MHD_USE_SELECT_INTERNALLY, 0, MHD_USE_POLL); errorCount += testGet (MHD_USE_THREAD_PER_CONNECTION, 0, MHD_USE_POLL); - errorCount += testGet (MHD_USE_SELECT_INTERNALLY, 4, MHD_USE_POLL); + errorCount += testGet (MHD_USE_SELECT_INTERNALLY, CPU_COUNT, MHD_USE_POLL); #endif #if EPOLL_SUPPORT errorCount += testGet (MHD_USE_SELECT_INTERNALLY, 0, MHD_USE_EPOLL_LINUX_ONLY); - errorCount += testGet (MHD_USE_SELECT_INTERNALLY, 4, MHD_USE_EPOLL_LINUX_ONLY); + errorCount += testGet (MHD_USE_SELECT_INTERNALLY, CPU_COUNT, MHD_USE_EPOLL_LINUX_ONLY); #endif if (errorCount != 0) fprintf (stderr, "Error (code: %u)\n", errorCount); diff --git a/src/testcurl/test_start_stop.c b/src/testcurl/test_start_stop.c @@ -28,6 +28,13 @@ #include <curl/curl.h> #include <microhttpd.h> +#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 +#undef CPU_COUNT +#endif +#if !defined(CPU_COUNT) +#define CPU_COUNT 2 +#endif + static int ahc_echo (void *cls, @@ -75,7 +82,7 @@ testMultithreadedPoolGet (int poll_flag) d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, 1081, NULL, NULL, &ahc_echo, "GET", - MHD_OPTION_THREAD_POOL_SIZE, 4, MHD_OPTION_END); + MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 4; MHD_stop_daemon (d);