Changeset 4352

Show
Ignore:
Timestamp:
11/18/09 13:34:39 (8 months ago)
Author:
phk
Message:

Add a parameter to set the workerthread stacksize.

On 32 bit systems, it may be necessary to tweak this down to get high
numbers of worker threads squeezed into the address-space.

I have no idea how much stack-space a worker thread normally uses, so
no guidance is given, and we default to the system default.

Fixes #572

Location:
trunk/varnish-cache/bin/varnishd
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/varnish-cache/bin/varnishd/cache_pool.c

    r4235 r4352  
    433433 
    434434static void 
    435 wrk_breed_flock(struct wq *qp) 
     435wrk_breed_flock(struct wq *qp, const pthread_attr_t *tp_attr) 
    436436{ 
    437437        pthread_t tp; 
     
    446446                if (qp->nthr >= nthr_max) { 
    447447                        VSL_stats->n_wrk_max++; 
    448                 } else if (pthread_create(&tp, NULL, wrk_thread, qp)) { 
     448                } else if (pthread_create(&tp, tp_attr, wrk_thread, qp)) { 
    449449                        VSL(SLT_Debug, 0, "Create worker thread failed %d %s", 
    450450                            errno, strerror(errno)); 
     
    477477{ 
    478478        unsigned u, w; 
     479        pthread_attr_t tp_attr;  
     480 
     481        /* Set the stacksize for worker threads */  
     482        AZ(pthread_attr_init(&tp_attr)); 
    479483 
    480484        THR_SetName("wrk_herder"); 
     
    482486        while (1) { 
    483487                for (u = 0 ; u < nwq; u++) { 
     488                        if (params->wthread_stacksize != UINT_MAX) 
     489                                AZ(pthread_attr_setstacksize(&tp_attr, 
     490                                    params->wthread_stacksize));  
     491 
     492                        wrk_breed_flock(wq[u], &tp_attr); 
     493 
    484494                        /* 
    485495                         * Make sure all pools have their minimum complement 
     
    487497                        for (w = 0 ; w < nwq; w++) 
    488498                                while (wq[w]->nthr < params->wthread_min) 
    489                                         wrk_breed_flock(wq[w]); 
     499                                        wrk_breed_flock(wq[w], &tp_attr); 
    490500                        /* 
    491501                         * We cannot avoid getting a mutex, so we have a 
     
    495505                        Lck_CondWait(&herder_cond, &herder_mtx); 
    496506                        Lck_Unlock(&herder_mtx); 
    497                         wrk_breed_flock(wq[u]); 
    498507                } 
    499508        } 
  • trunk/varnish-cache/bin/varnishd/heritage.h

    r4328 r4352  
    9494        unsigned                wthread_purge_delay; 
    9595        unsigned                wthread_stats_rate; 
     96        unsigned                wthread_stacksize; 
    9697 
    9798        unsigned                overflow_max; 
  • trunk/varnish-cache/bin/varnishd/mgt_pool.c

    r4216 r4352  
    191191                EXPERIMENTAL, 
    192192                "3", "requests per request" }, 
     193        { "thread_pool_stack", 
     194                tweak_uint, &master.wthread_stacksize, 64*1024, UINT_MAX, 
     195                "Worker thread stack size.  In particular on 32bit systems " 
     196                "you may need to tweak this down to fit many threads into " 
     197                "the limited address space.\n", 
     198                EXPERIMENTAL, 
     199                "-1", "bytes" }, 
    193200        { NULL, NULL, NULL } 
    194201};