Workers ThreadPools breaks ThreadLocals
Description
Activity

Sanne Grinovero April 26, 2009 at 3:07 PM
I'm sorry we can't change this.

Sanne Grinovero April 14, 2009 at 7:26 PM
I think you should make your own backend, asking to stop Search from using additional threads is a huge limitation on scalability, and for sure it's not a bug.
You could copy the code from Search 3.0.1 default's backend and port only the patches you need; or it might just work as is.
Really I think the design should be to have one persistence context per database; If you are giving each client it's own database then 50mb is not much.
Another option is to use filters.. much better idea IMHO, and you'll have to mantain and manage only one index for your application.
If it gets too big or if you have "law" regulations, you can then use sharding to split the index and store them separately.
"Hibernate Search in Action" has quite some tips about this situations.

Grégoire Rolland February 3, 2009 at 2:30 PM
Hello,
I implements a webapp for multiple clients. Each customer must have his database. I use Hibernate Search to search my domain object.
I can deal with the databases, I implements a custom connection provider, based on ThreadLocal pattern. I want to do the same thing with HSearch.
The client request take this path :
1/ RequestFilter
Get Entity Manager Factory and get or reuse Entity Manager (reuse if there is no new conversation), bind this to the ThreadLocal.
2/ Pass-through client layer
3/ Pass-through business layer
4/ On the integration layer, inject the entity manager, founded in the thread local and do the work. Here the connection provider can choose the correct datasource, and the custom FSDirectory, the correct directory for index reading/writing.
The limitation is I can't use shared index reader and i can't upgrade Hibernate Search to 3.1.0.GA, which provide bugs fixes I need too.
I try to use multiple Entity Manager Factory, but due to huge memory footprint (about 50Mbytes each), it was not an option (or I don't know how to reduce it !!). But it's a problem for scalability.
I hope it's quite clear for you !
thanks ...

Sanne Grinovero January 31, 2009 at 10:51 AM
The threadlocals is quite a hack. Could you elaborate on what your use case is? We could find a better alternative.
Details
Assignee
UnassignedUnassignedReporter
Grégoire RollandGrégoire RollandComponents
Affects versions
Priority
Major
Details
Details
Assignee
Reporter

When Implementing multi-domains (multi-databases) FSDirectory based on thread local (to get the thread environment, database name, etc...), the threadpool used by workers "forgot" the thread local variables on the second call (for searching, indexing). Works great with 3.0.1 release, but not with 3.1.0.GA.