apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Garrett Rooney" <roo...@electricjellyfish.net>
Subject Re: APR threads consume a large amount of virtual memory
Date Fri, 30 Jun 2006 21:38:58 GMT
On 6/30/06, Ivan Ristic <ivan.ristic@gmail.com> wrote:
> I have noticed that my multithreaded APR program consumes a *very*
> large amount of virtual memory per thread and I can't think of a
> reason why. I am running Debian 3.1  (latest kernel 2.6.8-3-686) and I
> tried the test program below with both the APR 0.9.x that comes with
> Debian and with the latest APR 1.2.x version.
>
> In both cases I end up with around 800 MB of virtual RAM for 100 threads:
> 20385 ivanr     16   0  802m  956 1800 S  0.0  0.4   0:00.02 test
>
> Am I doing something wrong or is this a bug? Any help is greatly appreciated!
>
> void* APR_THREAD_FUNC thread_worker(apr_thread_t *thread, void *data) {
>     apr_thread_exit(thread, 0);
> }
>
> int main(int argc, const char * const argv[]) {
>     apr_pool_t *pool;
>     int i;
>
>     apr_app_initialize(&argc, &argv, NULL);
>     atexit(apr_terminate);
>
>     apr_pool_create(&pool, NULL);
>
>     for(i = 0; i < 100; i++) {
>         apr_thread_t *thread = NULL;
>         apr_thread_create(&thread, NULL, thread_worker, NULL, pool);
>     }
>
>     apr_sleep(1000 * 1000 * 1000);
> }

If you look at apr_thread_create, you'll see that each call to it
creates a new subpool inside the pool you pass.  That seems likely to
be the cause of your memory usage...

Not sure how easy it is to avoid that, I haven't looked too closely at
what it's being used for.  Might be possible to fix though.

-garrett

Mime
View raw message