Changeset 4890:173cd5458281 in nginx


Ignore:
Timestamp:
10/23/12 09:08:41 (4 years ago)
Author:
Andrey Belov <defan@…>
Branch:
default
Convert:
svn:c3fe7df1-7212-e011-8a91-001109144009/trunk@4891
Message:

Core: the "auto" parameter of the "worker_processes" directive.

The parameter will set the number of worker processes to the
autodetected number of available CPU cores.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/core/nginx.c

    r4783 r4890  
    2222static char *ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd,
    2323    void *conf);
     24static char *ngx_set_worker_processes(ngx_conf_t *cf, ngx_command_t *cmd,
     25    void *conf);
    2426
    2527
     
    7072    { ngx_string("worker_processes"),
    7173      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
    72       ngx_conf_set_num_slot,
    73       0,
    74       offsetof(ngx_core_conf_t, worker_processes),
     74      ngx_set_worker_processes,
     75      0,
     76      0,
    7577      NULL },
    7678
     
    13301332    return ccf->cpu_affinity[ccf->cpu_affinity_n - 1];
    13311333}
     1334
     1335
     1336static char *
     1337ngx_set_worker_processes(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     1338{
     1339    ngx_str_t        *value;
     1340    ngx_core_conf_t  *ccf;
     1341
     1342    ccf = (ngx_core_conf_t *) conf;
     1343
     1344    if (ccf->worker_processes != NGX_CONF_UNSET) {
     1345        return "is duplicate";
     1346    }
     1347
     1348    value = (ngx_str_t *) cf->args->elts;
     1349
     1350    if (ngx_strcmp(value[1].data, "auto") == 0) {
     1351        ccf->worker_processes = ngx_ncpu;
     1352        return NGX_CONF_OK;
     1353    }
     1354
     1355    ccf->worker_processes = ngx_atoi(value[1].data, value[1].len);
     1356
     1357    if (ccf->worker_processes == NGX_ERROR) {
     1358        return "invalid value";
     1359    }
     1360
     1361    return NGX_CONF_OK;
     1362}
Note: See TracChangeset for help on using the changeset viewer.