Permalink
Browse files

auto detect the number of cpus

Summary: Instead of relying on -t to run on greater than 4 cpu systems, auto detect the number of active processors

Reviewed By: ttung

Test Plan: ran memcached on 8 core machine, 9 threads created.  ran on 4 core machine, 5 threads created.

Revert: OK
  • Loading branch information...
1 parent 9d001bf commit 702558756225f784a8b27412e94656cd6448931b ps committed Nov 5, 2008
Showing with 30 additions and 1 deletion.
  1. +20 −0 src/configure.ac
  2. +10 −1 src/memcached.c
View
@@ -150,6 +150,26 @@ fi
AC_C_SOCKLEN_T
+AC_DEFUN([AC_C__SC_NPROCESSORS_ONLN],
+[AC_CACHE_CHECK(for _SC_NPROCESSORS_ONLN, ac_cv_c__sc_nprocessors_onln,
+[
+ AC_TRY_COMPILE([
+ #include <unistd.h>
+ ],[
+ sysconf(_SC_NPROCESSORS_ONLN)
+ ],[
+ ac_cv_c__sc_nprocessors_onln=yes
+ ],[
+ ac_cv_c__sc_nprocessors_onln=no
+ ])
+])
+if test $ac_cv_c__sc_nprocessors_onln = yes; then
+ AC_DEFINE(HAVE__SC_NPROCESSORS_ONLN,,[do we support sysconf(_SC_NPROCESSORS_ONLN)?])
+fi
+])
+
+AC_C__SC_NPROCESSORS_ONLN
+
dnl Check if we're a little-endian or a big-endian system, needed by hash code
AC_DEFUN([AC_C_ENDIAN],
[AC_CACHE_CHECK(for endianness, ac_cv_c_endian,
View
@@ -166,10 +166,19 @@ static void settings_init(void) {
settings.managed = false;
settings.factor = 1.25;
settings.chunk_size = 48; /* space for a modest key and value */
- settings.num_threads = 4 + 1 /* N workers + 1 dispatcher */;
settings.prefix_delimiter = ':';
settings.detail_enabled = 0;
settings.reqs_per_event = 1;
+
+#ifdef HAVE__SC_NPROCESSORS_ONLN
+ /*
+ * If the system supports detecting the number of active processors
+ * use that to determine the number of worker threads + 1 dispatcher.
+ */
+ settings.num_threads = sysconf(_SC_NPROCESSORS_ONLN) + 1;
+#else
+ settings.num_threads = 4 + 1; /* N workers + 1 dispatcher */
+#endif
}
/*

0 comments on commit 7025587

Please sign in to comment.