mem-leak in thread::send -async
Closed / Wont Fix987512ffffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-07-08 19:38:31
hi, I hope, this is a bug and is not work as designed :=)
this testscript confiscated over 9MByte Ram. the
call thread::send -async send 385 Bytes to the thread and
after 25000 calls, the thread use ~9300 KByte memory
(offset) ! after I release the thread, the memory will
not be freed. if I send the script without -async, all
memory will be
freed.
I have make the test with the current cvs snap-shot
changelog -> R1.2132, Wed Jul 7 22:05:56 2004
on a linux 2.6.7 i386 & ppc system, with & without
USE_THREAD_ALLOC in the CFLAG.
before som days, i have posted a problem in the
tcl-thread-list, i think, it is the same problem.
regards, joerg
set ::Thread {
proc TestProc {args} {
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
set x "xxxxxxxxxxxxxxxxxxxxxxxx"
return 0
}
TestProc
}
set thid [thread::create "thread::wait"]
for {set ni 0} {$ni < 25000} {incr ni} {thread::send
-async $thid $::Thread}
thread::send $thid -async "thread::release"
vwait forever
joergwendtplain2004-07-10 18:24:51
Logged In: YES user_id=1079782 can that reproduce somebody -- I have a big problem with a server, after 30h the process-memory is full (2 GByte). does someone have any note, workaround or tip for me ? ~joerg
vasiljevicplain2004-07-10 21:53:37
Logged In: YES user_id=95086 Let us first clarify this: thread::send $thid -async "thread::release" is wrong, hence you never release the thread actually. You should have written: thread::send -async $thid "thread::release" But, it is perfectly sufficient to call: thread::release $thid from the main thread, i.e. w/o posting an async event to the worker thread. Now, if you modify your test-bed and run again, the memory should be released. Each thread cleans-up its unserviced events on exit so I should not expect any problems there. Otherwise we'll have to dig into more deeply. Tell me what u get.
joergwendtplain2004-07-10 23:33:40
Logged In: YES user_id=1079782 sorry for my inadvertence, I work on this problem the last weeks ... I repeated the test (and go back to 8.4.6/2.5.2) 1. download the tar-files from sourceforge 2. compile with threads (testrun with & without USE_THREAD_ALLOC) 3. I have eliminated the bug in the script :-( 4. testing with thread::send -async $thid "thread::release" & thread::release $thid hm, the same result, the thread is down but the memory will not be freed ! the program starts with 1.5MB and ends with ~11 MB. that the resources of the threads with thread::release to be released is ok. but why not after the idel-script was finish ? the testrun with USE_THREAD_ALLOC need more memory - I think that am normal ! ~joerg
vasiljevicplain2004-07-11 16:25:54
Logged In: YES
user_id=95086
OK. All is clear now. You try this and watch the proc virtual size
with top utility:
time {
set thid [thread::create "thread::wait"];
for {set ni 0} {$ni < 25000} {incr ni} {
thread::send -async $thid$::Thread
}
thread::send -async $thid thread::release
}
Hit this command once, twice and so on and the process
memory will always stay at about 15 MB (on Linux).
DO NOT try "time {...} 100" for example because this will
fill the async event loop queue with tons of events. This
is not what we're testing. Just repeat the above time
command *by hand* several times in a row.
The thing with USE_THREAD_ALLOC is that allocated Tcl
memory is never freed. It is kept for process reuse in several
per-thread and global buckets. The idea is to put less strain
on the malloc's mutex, thus speeding up the whole thing.
So, technically speaking, there is no leak.
Now this little example does not reveal any problem actually.
We have yet to find out what is the real problem you're hitting.
It might be that your app loads some non-thread-safe and/or
memory leaking extensions. What extensions do you load,
if any? What is the pattern of your server app, i.e. what it does?
Can you sketch this in couple of lines?
The bottom line is that using USE_THREAD_ALLOC, your process
may grow over time, but should eventually settle down on some
pretty-much constant value. This value might be high, but it
should not break your VM. If this is not what you can afford,
try compiling without USE_THREAD_ALLOC. This will slow-down
the app for sure but will avoid the above. The thing is: you may
not even see that your app is slowed down. This depends entirely
on what your app is actually doing. It is worth a try.
vasiljevicplain2004-07-12 23:28:49
Logged In: YES user_id=95086 Any new insights?
joergwendtplain2004-07-13 01:46:34
Logged In: YES user_id=1079782 for the moment I still work on the tests (munich summer flu & and a typical monday :-( ) your example shows a confusing result. ~ 5% 1.5MB starts and ends with 1.5MB ~ 90% 1.5MB start and ends with 22MB ~ 5 % the rest ends between 3~80MB loop with hand-test & for loop with after to yours ask for the function of the application. it is a batch server ! the test-enviroment don't use any tcl-extention (only tcl & libthread). I removed all C-code for my tests und disable TCL_THREAD_ALLOC. principleal function: Main-Thread : scan a batch-queue Main-Thread : send batch-exeute cmd to Batch-Thread Batch-Thread: execute Batch-Job (Tcl-Script) Batch-Thread: send finish-sig to Main-Thread Main-Thread : scan batch-queue ..... I began to test systematically all used Tcl instructions .. for the moment file mtime and glob are in the my focus. ~joerg
nobodyplain2004-07-20 08:11:10
Logged In: NO
Just an observation... 385 bytes in $::Thread and 25,000 of
them on the async queue for that thread that's 9.2MB of
data sitting in the queue for your thread. That's not TCL
leaking memory. Tcl threads are cooperative and not
preemptive so none of those async requests are executed
until your [vwait].
I tried two variations of the testcase and didn't observe any
memory leaking... Here they are.
#1: throw a bunch of -async's and then release the thread
over and over.
for {set x 0} {$x < 2500} {incr x} {
set thid [thread::create {thread::wait}]
for {set ni 0} {$ni < 100} {incr ni} {
thread::send -async $thid $::Thread
}
thread::release $thid
}
puts "DONE"
---------------------------------------------------
#2: throw -async's at the thread every 10 milliseconds so it
can execute as we go.
set ::thid [thread::create {thread::wait}]
set ::requests 25000
proc issue {} {
if {[incr ::requests -1] != 0} {
if {($::requests % 1000) == 0} {
puts $::requests
}
thread::send -async $::thid $::Thread
after 10 [namespace code issue]
} else {
puts "DONE"
}
}
issue
thread::wait
vasiljevicplain2004-11-25 23:32:37
Logged In: YES user_id=95086 Closing as "Wont Fix" since there is nothing to fix really.
Log in (anonymous is fine) to add a comment.