Loris icon indicating copy to clipboard operation
Loris copied to clipboard

[Core] Allow parallel handling of requests from same session

Open driusan opened this issue 4 years ago • 3 comments

This adds a session_write_close() call to the end of NDB_Client, after the last reference to $_SESSION has been made. This causes PHP to release the lock it holds on the session file which prevents further incoming requests from being handled. After this point in NDB_Client all of our session related state should be read from the PSR request, not the superglobal.

PHP by default holds a lock on the session until it is closed in case there is a write to the superglobal. However, this prevents other requests from the same session from reading the variable (which is where our login state is stored) until the end of the request, when the lock is released. Closing it explicitly releases the lock and allows us to handle multiple requests from the same user in parallel instead of in series.

driusan avatar May 10 '21 18:05 driusan

I think I found write operations on $_SESSION['State'] that occur after session_write_close

  1. https://github.com/aces/Loris/blob/c38f1c1ea4bef8112882e0bf48c81a1c13337fc3/php/libraries/NDB_Menu_Filter.class.inc#L324
  2. https://github.com/aces/Loris/blob/c38f1c1ea4bef8112882e0bf48c81a1c13337fc3/php/libraries/NDB_Menu_Filter.class.inc#L332

xlecours avatar May 12 '21 12:05 xlecours

Thanks.. that looks like dead code, but I think it might actually be why the MRI Violations tests are failing, since MRI Violations hasn't been converted to React yet. Gonna have to think about if there's an easier way to do this than rewriting the module for this PR..

driusan avatar May 12 '21 13:05 driusan

I think since MRI violations is the last module in https://github.com/aces/Loris/projects/8 I might as well just do it and then delete that code in this PR.

driusan avatar May 12 '21 13:05 driusan

This is cool !

ridz1208 avatar Nov 29 '22 19:11 ridz1208

Approving. noticeable difference in request speed. currenlty working on CBIGR biobank

ridz1208 avatar Dec 19 '22 15:12 ridz1208

Note: Talked to @cmadjar before skipping the tests and we agreed to rely on manual testing the mri violations module for now, because of the significant performance implications for other modules (biobank, eeg, etc)

driusan avatar Dec 19 '22 15:12 driusan