thetuningspoon Posted September 5, 2017 Share Posted September 5, 2017 I am having trouble with executing multiple AJAX requests at the same time. The response is very slow and seems to be synchronous instead of asynchronous. I am using jQuery's ajax() function, so I don't think there's any issue on the client side. I think it is an issue with Session locking/blocking. I read somewhere that SessionHandlerDB would resolve this issue, but enabling it has not improved the situation any. I just want to confirm whether or not SessionHandlerDB is designed to handle concurrent requests efficiently, so I know what to rule out. Link to comment Share on other sites More sharing options...
dragan Posted September 5, 2017 Share Posted September 5, 2017 I don't think it would resolve the issue. SHDB just saves to DB instead of the file-system. But PHP will still do one session request after another and probably uses db table locks instead of file locks (at least that's my guess). Are you using PW session functions or native PHP? Towards the bottom of this article there is PHP 7 option: session_start([ 'read_and_close' => true, ]); https://ma.ttias.be/php-session-locking-prevent-sessions-blocking-in-requests/ The author also mentions Redis (there's also a redis session handler db module for PW), but if you're not using it it won't be of much use... 3 1 Link to comment Share on other sites More sharing options...
thetuningspoon Posted September 5, 2017 Author Share Posted September 5, 2017 I did try turning off SessionHandlerDB and using php's session_write_close() and that didn't seem to help either. I think I also tried $session->close() (which just calls php's function). Moreover, there are a couple ajax requests which do need to be able to write to the session, so a blanket session_write_close if $config->ajax is true wouldn't solve my issue Edit: I am going to try Redis. Will let you know how it goes. Link to comment Share on other sites More sharing options...
thetuningspoon Posted May 22, 2018 Author Share Posted May 22, 2018 An update on this for others: Using Redis for sessions solved the problem for me. I had to make some changes to the module to get it to work right (if anyone wants my code, let me know). Today I happened to try migrating my project from using ProcessWire's default MyISAM database engine to using InnoDB (had to convert all tables and set $config->dbEngine in site/config.php). I was playing around with the demo version of my system (which is not using Redis). And interestingly enough, I THINK this (in combination with SessionHandlerDB) actually resolved the issue with simultaneous ajax calls! Perhaps this is because InnoDB has row-level locking instead of table-level locking? 3 Link to comment Share on other sites More sharing options...
netcarver Posted May 22, 2018 Share Posted May 22, 2018 @thetuningspoon I think you are on target here. There's a lot to be said for the InnoDB engine, and the row level locking vs table level should reduce contention and decrease latency with it. Redis, despite being single threaded, is writing to an in-memory key value store - so it's blindingly fast. I would be interested in seeing your updated code for the Redis session handler - if that's what you mean, as I need to update that module. 4 Link to comment Share on other sites More sharing options...
thetuningspoon Posted May 23, 2018 Author Share Posted May 23, 2018 @netcarver Thanks for chiming in. I just submitted a pull request on GitHub. Looks like I had submitted a bug report at the time, which this pull request resolves. I also added a password config option, and made some change to the read() method (but I don't remember what it's doing exactly). 4 Link to comment Share on other sites More sharing options...
netcarver Posted May 24, 2018 Share Posted May 24, 2018 Have merged your pull request, thank you. 4 Link to comment Share on other sites More sharing options...
markus_blue_tomato Posted January 25, 2019 Share Posted January 25, 2019 hi @thetuningspoon ! does the redis module still work for you? I got some strange issue with it and also with the native redis and memcached session_handler im PHP: https://github.com/processwire/processwire-issues/issues/798 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now