Implement caching of PostgreSql statements
After the recent improvement regarding limitation of max connected users ( #48 (closed)), there is still existing one thing that can help to improve performance a bit.
Currently, each new user request requires to build set of PostgreSql statements. Of course they are already cached on the PqLib side, library returns code PG_42P05 (already prepared), but based on benchmark results it's not absolutely cheap.
I think that make sense to cache them also on the application side.
Preliminary dev plan:
- Introduce map of
Statement
objects in theConnection
. - Method
Connection::prepare
should returnStatement
object (build new or get from map). - Refactor all existing usages of prepared statements
Update 01 Sep:
- Currently each new prepared statement has new name (can lead to degradation performance in time).
void Statement::Impl::buildStatementName() {
auto uid = oes::core::Guid::make();
std::stringstream ss;
ss << std::this_thread::get_id();
_statementName = "OES_" + uid.toStringNoDash() + "_" + ss.str();
}
- It is necessary to make deterministic generation names of statements.
- Need to avoid recreating statements with the same name (this will lead to abort transactions).
Edited by Pavel Kisliak