From: <php...@li...> - 2006-07-22 18:57:17
|
Hi I'm looking at the possibilities to keep certain Java objects (in my case Lucene index searchers, query filters) persistent between client calls. I looked at the java_session() function, but this is not possible as I it interferes with the session functions of the application in which I'm using the php-java bridge. I also suspect serializing (sometimes larger) objects is beyond the scope of session variable too. So my question is if any of you could shed some light or point me in a good direction to look for the best solutions. I am currently exploring the idea of using a Java cache framework like Apache Jakarta JCS but maybe I'm looking to far ... Any input is very much appreciated Best regards Paul -- http://walhalla.wordpress.com |
From: <php...@li...> - 2006-07-24 16:26:50
|
Hi Paul, > to keep certain Java objects (in my > case Lucene index searchers, query filters) > persistent between client calls. I usually use a factory class: public class FooFactory { private static final Object foo=createFoo(); public Object getFoo() { return foo; } } This works because the JVM keeps the class Name=>Class bindings in a weak hash map and classes usually aren't gc'ed unless the VM runs short of memory. The above method can't be used if all nodes of a (weblogoc- or tomcat-) cluster should refer to the same foo instance or if there's no persistent VM at all(for example if lucene and the bridge classes have been compiled to native code and are started for each request). > I also suspect > serializing (sometimes > larger) objects is beyond the scope of session > variable too. Depends on how long you want to keep the data and how expensive it is to create. If the data is really expensive I would use the JPersistenceAdapter, serialize the data and store it on the master node, on the web server or in a database and deserialize it when the next request comes in. Regards, Jost Boekemeier ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de |
From: <php...@li...> - 2006-07-24 20:42:20
|
Hi Jost Thank you very much for your explanations On 7/24/06, php...@li... <php...@li...> wrote: > Hi Paul, > > > to keep certain Java objects (in my > > case Lucene index searchers, query filters) > > persistent between client calls. > > I usually use a factory class: > > public class FooFactory { > private static final Object foo=createFoo(); > public Object getFoo() { > return foo; > } > } > > This works because the JVM keeps the class Name=>Class > bindings in a weak hash map and classes usually aren't > gc'ed unless the VM runs short of memory. That could be part of the solution, like a lucene indexreader for a dedicated application. But in my case, I want to build an easy to distribute/deploy PHP component requiring only the minimim work of installing your php-java bridge as a stand-alone service (or for those who can within tomcat or the likes). > The above method can't be used if all nodes of a > (weblogoc- or tomcat-) cluster should refer to the > same foo instance or if there's no persistent VM at > all(for example if lucene and the bridge classes have > been compiled to native code and are started for each > request). > That is not the case for me, I did not explore the option of compiling to native code yet (but will do, curious about the performance with respect to a VM install) > > I also suspect > > serializing (sometimes > > larger) objects is beyond the scope of session > > variable too. > > Depends on how long you want to keep the data and how > expensive it is to create. If the data is really > expensive I would use the JPersistenceAdapter, > serialize the data and store it on the master node, on > the web server or in a database and deserialize it > when the next request comes in. Ah, that's interesting! The data (lucene filters and sort objects mainly) is rather expensive to create (roughly 50 to 200 msec per instance for a "typical" index which has a few tens to a few hundred fields and 100k records) The main problem with JPersistenceAdapter is that I should find a way to get this working in a PHP4 contextto which I'm tied now ... and which does not look trivial now Thank you very much again, I learned a lot andn admire your work on the php-java bridge! Best regards Paul -- http://walhalla.wordpress.com |
From: <php...@li...> - 2006-07-27 01:47:07
|
Hi, > dedicated application. But in my case, I want to > build an easy to > distribute/deploy PHP component requiring only the > minimim work of > installing the memory cache is the easiest solution I can think of. A file cache requires much more work, every node has to serialize the data to java.io.tmpdir (that's the only directory to which J2EE or SEL has write access) and make sure that all other nodes don't update or read the cache while one node updates the data. If the data doesn't fit into memory or into java.io.tmpdir, you'll need a decicated cache daemon which listens on some port, updates its database regularily and answers requests from the nodes. Users could start this daemon, if they want to: java -jar luceneCacheDaemon.jar If a Socket(daemonPort) fails during startup of a node you could revert to memory cache: public class fooFactory { private static Foo foo; private static final Socket cacheDaemon; static { try { cacheDaemon = new Socket(DAEMON_PORT); } catch (IOException e) {/*ignore*/} } public static synchronized foo getFoo() { if(foo!=null) return foo; if(cacheDaemon!=null) return foo=getFoo(cacheDaemon); return foo = createFoo(); } } > to native code yet (but will do, curious about the > performance with > respect to a VM install) Starting a native lucene .so costs about 100 to 150 ms. Regards, Jost Boekemeier ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de |
From: <php...@li...> - 2006-08-09 19:23:15
|
Hi Jost After some tests I went for a java cache implementation with ehcache. In this way I did not have to write Java, but more importantly it is easier to to cache dynamically generated java objects (like query filters which are different for each user) -- even persistent if I use the disk cache when the JVM stops. Now I need to upgrade the bridge to 3.1.7 and install it in a J2EE server (still running the bridge with a stand-alone JVM) Best regards Paul -- http://walhalla.wordpress.com |
From: <php...@li...> - 2006-08-10 15:46:17
|
Hi Paul, > implementation with ehcache. thanks for the pointer. Especially its multicast features sound interesting. > Now I need to upgrade the bridge to 3.1.7 and > install it in a J2EE > server (still running the bridge with a stand-alone > JVM) I hope this isn't a big problem. But it was difficult to maintain two separate implementations, the standalone component and the J2EE component. Regards, Jost Boekemeier ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de |