clkao / plv8js-migrated

Automatically exported from code.google.com/p/plv8js
Other
0 stars 0 forks source link

memoize prepared plans (no plv8.end_proc?) #83

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We have a case where we have two usages for our functions: either a single call 
(create customer) or multiple calls (create customerS) through another 
higher-level procedure) in the same transaction/session.

To optimize performance, we would like to memoize the prepared plans in the 
same session so they get reused in such loops.

We do this by creating a start_proc plv8_init() which exposes a new plv8 
function that takes the plan name, plan and types, prepares it (if plan name 
has not already been created) and returns it.

The documentation says that we need to call free() on each PreparedPlan. Based 
on that, we would like to have a point (perhaps plv8.end_proc) where we can 
iterate through memoized plans and call their free() when the session finishes.

The (ugly) alternative is to create an additional proxy top-level function for 
single-calls and multiple-calls with the free on the PreparedPlan and have a 
private function where the memoized prepared plan is done.

If this sounds reasonable (if not, why not?), these are our questions:

1) why is there a plv8.start_proc but no corresponding plv8.end_proc? and 
perhaps plv8.start_transaction and plv8.end_transaction hooks?
2) do we really need to call free on the prepared plans? since they are only 
valid per session, don't they get cleaned up once the session ends anyway?

Original issue reported on code.google.com by rnga...@gmail.com on 2 Jan 2014 at 10:46

GoogleCodeExporter commented 9 years ago
The thing is we don't really have such "end" point even in the internal backend 
code.  plv8 itself had some issue regarding "persistent" handle management and 
I was looking for a hooking point where multi-function call ends but no luck.  
We have a hook point at the end of transaction but it's not clear if you want 
it or end of the session across multiple transactions.

1) The above is pretty much the answer.  If you know about linux shared library 
mechanism, it may or may not have "unload" hook though "load" hook is designed.
2) Yes, the portal memory is a process-local so if you are ok to leave it 
alone, it's fine.  When you disconnect from the session, it goes away.  plv8 
does not have much power outside of function anyway.

Original comment by umi.tan...@gmail.com on 15 Jan 2014 at 5:02