-
Should I initialize the database cursor once per each Apache thread, or should I initialize one in every function available to HTTP clients?
-
What happens when the client terminates the connection (i.e. user closes the browser tab)? Does the server-side function that was processing the request continue normally until it returns, or does it get terminated immediately without getting a chance to close all the transactions?
Should I initialize the database cursor once per each Apache thread, or should I
Share
Cursors are expensive resources.
Generally…
Open them just when you need them.
Close them as soon as you are done with them.
Cursor-per-thread may tie up resources needlessly. Sometimes you have so much database activity that cursor-per-thread might be higher performance. This is rare. If you think that cursor open-close is slowing things down you need to measure the difference between per-function and per-thread to see what’s really going on.
The server has no idea what is going on in the browser. Zero. Each request from the browser is a separate, unique, disconnected event.
If the browser “closes”, that doesn’t mean anything. It only means that the server doesn’t get any further requests.
If the server was trying to download a response, then the socket crashes and the server eventually stops trying.
If the server wasn’t processing anything, it’s still not processing anything.