Forum OpenACS Development: ns_set + memory leak

Collapse
Posted by Patrick Heissenberger on
Run following code on a page or in the developer shell:

for { set n 0 } { $n<10000 } { incr n } {
  set setid [ns_set create]
  ns_set put $setid key [string repeat "dummy data" 500]
}

During runtime the system will create 10000 'ns_set' objects and memory consumption of the process will increase by approximately 80mb.

But at the end of the request, the memory is not freed. Instead it is reused, because if you run the code block again, the memory consumption keeps constant. If you run the code block a third time and change the for condition to $n<20000 then the memory allocation will be constant for the first 10000 iterations and increasing again for iteration 10001 to 20000.

Is this kind of memory pool an intended behavior? Will the memory be freed later?

Beside that, shouldn’t functions which are use ns_set's call 'ns_set free'? The function db_0or1row doesn't free the ns_set. This could result in an out of memory problem if you are calling the function within a request often enough.

Collapse
2: Re: ns_set + memory leak (response to 1)
Posted by Brian Fenton on
Hi Patrick

as far as I know, that is expected behaviour. I don't think the memory gets freed later.

Good point on the "ns_set free" - I don't know the answer I'm afraid.

Brian

Collapse
3: Re: ns_set + memory leak (response to 1)
Posted by Eduardo Santos on
Hi Patrick,

I don't see this as a bug. You see, the whole idea of a multithread system is that you can reuse memory space without the need to create another thread. In my studies about the performance in AOLServer, I could see that the create/destroy proccess for a thread costs a lot of resources, especially I/O. So, it's a good idea if you can keep a thread alive to reuse later.

By the way, think about a large web site. If you are seeing a high memory peak, it's because the traffic is getting higher (thinking about it simply, of course), and it's not going to reduce instantly. So, it's much probably the memory space keeps alocated to nsd, until another request comes to use that area.

You see: I don't think it as a bug. It seems more like a strength in AOLServer to me.