C初心者がmemcached-1.4.5を追いかける。(22)
C初心者がmemcached-1.4.5を追いかける。(21)の続き
ソースはコチラにてDLしました。
getoptで受け取ったパラメータによって処理を行っている部分を追いかける。
memcached.c(4386行目あたり)
case 't': settings.num_threads = atoi(optarg); if (settings.num_threads <= 0) { fprintf(stderr, "Number of threads must be greater than 0\n"); return 1; } /* There're other problems when you get above 64 threads. * In the future we should portably detect # of cores for the * default. */ if (settings.num_threads > 64) { fprintf(stderr, "WARNING: Setting a high number of worker" "threads is not recommended.\n" " Set this value to the number of cores in" " your machine or less.\n"); } break;
"t:" /* threads */
settings.num_threadsに値を設定。
引数が、0以下の場合はエラー。
引数が64を超える場合ワーニングを出力。
struct settings { int num_threads; /* number of worker (without dispatcher) libevent threads to run */
static void settings_init(void) { settings.num_threads = 4; /* N workers */
初期処理では、settings.num_threads に4を設定している。