Discussion:
httpServer cache in clones
(too old to reply)
Karl Prinelle
2019-11-28 21:59:00 UTC
Permalink
Hi,

I'm using the httpServer and have a set of reference data that sits in a database (which is also the system store). For performance (and coding convenience!) reasons I'd like to avoid having to re-read this from the db each time I get a new http request.

The problem I'm hitting is that on each request the httpServer clones itself and then executes. That means all the cached data in the 'main' thread isn't available in the clone as it starts afresh.

I've tried task.setConfiguration("parm", object), but that's null on 'getConfiguration()' - fairly obvious I guess because each clone is it's own task.

I had hoped to get hold of the AL config and put my objects in that, but either I can't find the AL config, or what I am using isn't part of the clone.

I'm thinking towards serialising the objects and putting them in the java property store, but I'm not sure how that will perform & still will incur a load of marshalling/unmarshalling.

Does anyone have a suggestion about how to get an object (HashMap) into the AL such that it (or it's reference) can be included in the clone?

Thanks!
Karl Prinelle
2019-11-29 19:40:46 UTC
Permalink
Post by Karl Prinelle
Hi,
I'm using the httpServer and have a set of reference data that sits in a database (which is also the system store). For performance (and coding convenience!) reasons I'd like to avoid having to re-read this from the db each time I get a new http request.
The problem I'm hitting is that on each request the httpServer clones itself and then executes. That means all the cached data in the 'main' thread isn't available in the clone as it starts afresh.
I've tried task.setConfiguration("parm", object), but that's null on 'getConfiguration()' - fairly obvious I guess because each clone is it's own task.
I had hoped to get hold of the AL config and put my objects in that, but either I can't find the AL config, or what I am using isn't part of the clone.
I'm thinking towards serialising the objects and putting them in the java property store, but I'm not sure how that will perform & still will incur a load of marshalling/unmarshalling.
Does anyone have a suggestion about how to get an object (HashMap) into the AL such that it (or it's reference) can be included in the clone?
Thanks!
Update:

Solved it in terms of being possible.
This will create an object in the config and it persists. You can then use .getParameter() to obtain the map and update it, not needing to call .setParameter of course because it's an object reference which is nice.


if (main.getMetamergeConfig().getParameter("theMap") == null) {
main.getMetamergeConfig().setParameter("theMap", new java.util.HashMap());
task.logmsg("INFO", "CREATED NEW MAP");
} else {
task.logmsg("INFO", "MAP ALREADY EXISTS");
}
Franzw
2019-12-02 07:29:47 UTC
Permalink
Post by Karl Prinelle
Post by Karl Prinelle
Hi,
I'm using the httpServer and have a set of reference data that sits in a database (which is also the system store). For performance (and coding convenience!) reasons I'd like to avoid having to re-read this from the db each time I get a new http request.
The problem I'm hitting is that on each request the httpServer clones itself and then executes. That means all the cached data in the 'main' thread isn't available in the clone as it starts afresh.
I've tried task.setConfiguration("parm", object), but that's null on 'getConfiguration()' - fairly obvious I guess because each clone is it's own task.
I had hoped to get hold of the AL config and put my objects in that, but either I can't find the AL config, or what I am using isn't part of the clone.
I'm thinking towards serialising the objects and putting them in the java property store, but I'm not sure how that will perform & still will incur a load of marshalling/unmarshalling.
Does anyone have a suggestion about how to get an object (HashMap) into the AL such that it (or it's reference) can be included in the clone?
Thanks!
Solved it in terms of being possible.
This will create an object in the config and it persists. You can then use .getParameter() to obtain the map and update it, not needing to call .setParameter of course because it's an object reference which is nice.
if (main.getMetamergeConfig().getParameter("theMap") == null) {
main.getMetamergeConfig().setParameter("theMap", new java.util.HashMap());
task.logmsg("INFO", "CREATED NEW MAP");
} else {
task.logmsg("INFO", "MAP ALREADY EXISTS");
}
Interesting approach Karl, thanks for sharing :-)

Regards
Franz Wolfhagen

Loading...