Open tpolecat opened 3 years ago
I should add that this really means we need to redo the session pool, which is overly complicated at the moment.
How about ditching the session pool of skunk entirely and refer to dedicated solutions like https://www.pgbouncer.org/ instead?
Skunk closes prepared statements after
use
, which ensures that sessions don't build up an unbounded number of open statements on the server. This is good in principle, but it means that we have to do aParse
exchange for every prepared statement, even if an identical one was previously prepared on the sameSession
.An alternative way to do this would be to have an LRU cache from
Statement
toStatementId
on eachSession
.Parse
checks the cache first and if it's there we have no need to do further work.Parse
exchange and insert into the cache on success.On both access and insert there may be cache evictions, so each
Session
needs to track this set as well.Close
exchanges). This means aSession
returning to the pool may be unavailable for immediate use. We can pipeline these messages, which should be fast.A consequence here is that
.prepare
can now return anF[PreparedCommand[...]]
rather than aResource[F, PreparedCommand[...]]
(analogously for queries). This seems like a usability improvement to me but it will break everyone's code. As a first step we could just doResource.eval
to keep the API the same.Note that the
Describe
cache is per pool so we don't want to roll it into theParse
cache, which is per session. If we did this we would end up runningDescribe
exchanges for statements we already know are valid.