We have the same problem, when more than 250 students try to login simultaneously to take a test. The message is 'Cannot obtain session lock for sid: xxx within 720. It is likely another page has a long session lock, or the session lock was never released.' Database Max Connections is set to 600. We use Redis session manager, $CFG->session_handler_class = '\core\session\redis'; and $CFG->session_redis_acquire_lock_timeout = 720;
I would appreciate some advice where the message comes from, is it a database lock or a Redis lock? As far as I can see the Moodle server or Redis server is not overloaded (<50% of CPU).
I can also add that we experienced the same limitations with $CFG->session_handler_class = '\core\session\database'; in config.php, but if I remember the error message did not mention the long session lock.