uschindler commented on PR #816:
URL: https://github.com/apache/lucene/pull/816#issuecomment-1111248678

   > What is unclear is whether this is the reason why some users have been 
seeing this threadlocal behavior, or if it's something that can generally 
happen due to the fact that Elasticsearch often handles lots (possibly in the 
order of 10k) of segments per node, which translates into as many threadlocals 
for stored fields and term vectors.
   
   That's another issue: You should only create ThreadLocals at some "central" 
places in your code (e.g. a central one in IndexReader or similar) and use it 
as per-thread holder for everything you need to remember. You should not have 
thousands of objects with separate threadlocals. The problem with that is: 
every thread has a weak map keyed by ThreadLocal (`Map<ThreadLocal,Object> 
locals`. The setter in Threadlocal calls it like 
`Thread.currentThread().locals.set(this, value)`, same for get). So when the 
ThreadLocal objects come and go, the Thread's map collects instances of 
ThreadLocals not yet garbege collected. Actually this is why they are so fast 
and it is really clever, because this map is only accessed from inside the 
thread's context so no locking is needed. But the downside is that it is 
somehow "inverse". The reference goes from Thread to ThreadLocal, so it must be 
weak. And this requires cleanup.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to