We got the same issues when logging in too. ( https://moodle.org/mod/forum/discuss.php?d=319839 )
For 100 users logging in at the same time (load test using JMeter), some are getting "Error reading from database" errors, "503 service unavailable" errors, and "500 internal server error" after logging in. And the login time for each user range from 30 - 90 seconds.
We got a lot more courses in our system (over 4,100 courses) and 500 users. However, we do not enroll all the users to the courses. We are using guest access for all courses, and using enrollment for some specific courses (depends on the students' department) only.
We also tried to remove the navigation to all courses in the Navigation Block , remove the Courses Block , remove the Available Courses Block from Dashboard to see whether it will help speed up the login process. But no, we still faced the same errors as before.
We have no idea how we can support hundred of users logging in at the same time when we are having quiz for the class.