Database Sessions Improved Perfomance
Description
I don't mark it as a bug, because it's not a bug per se but DatabaseSession is unusable in current state if you have > 10ms latency
each set/create/remove send a persist call in DatabaseSessionManager, on each request there is easily > 10 calls to either of them and if you are running db not locally or not on the same close network each call is easily in 10s of ms, slowing down the response by 200-500ms
now I rolled out my own session manager because of that and I added response parser that simply persists the state if it has to, some operations set some value then remove it later on within the same requests so persistence in that case is not needed. Not sure if thats the best way to do so, but wasnt able to get middleware working for that. My first idea was middleware that will run as last in the chain but even with priority juggling I wasnt able to do so
Redis/Valk support would be nice too ;)
Benefits
Remove pointless calls to db within the same request
Add redis/valk support
now I rolled out my own session manager because of that and I added response parser that simply persists the state if it has to, some operations set some value then remove it later on within the same requests so persistence in that case is not needed
I'd love to merge a PR for that!
Redis/Valk support would be nice too ;)
Agree, and it's just a matter of doing it, I've created an issue for it: #1700. I'll see whether I or someone else gets to it fits.
@brendt i created some wip pr https://github.com/tempestphp/tempest-framework/pull/1704 thats what i kinda have on my project
use it maybe as some idea but dont merge as I didnt test it or anything and I personally dont use github much so have no idea how half of the things work here
basically session cache works as in memory cache map sessionid->session I store original values to know if it should persists in a db/file/redis or whatever then SessionResponseProcessor should run just last in chain on response, to persist it to the storage if needed
edit: something like stateless sessions might be worth considering too, we have now that appname_session_id cookie, we can pass as value whole session there as jwt for example