I’m writing a Scala app that will need to handle big spikes in load. I was quite surprised to see an exception that says the “Max number of threads (maxWaitQueueSize) of 500 has been exceeded”
500! Why on earth would I need 500 threads?
The documentation for Scala driver (which apparently uses the Java driver) says that it’s non-blocking and asynchronous. I’ve always thought that these two concepts are usually implemented by reusing a limited number of threads running on a thread pool of a particular size. Upon looking into the driver code I noticed that the mongo driver is creating a thread for each operation! How can that be efficient? Thread creation is after all, to the best of my knowledge, absurdly expensive.
I anticipate that for sure there is a reason why is this is implemented this way, so I’d love if you could enlighten me on the following questions:
- Why are you creating threads for each operation?
- How can I work around the problem of running out of threads upon big load spikes?
- Lastly, as I believe my understanding of the topic is limited, can you recommend me a resource for diving into details of performing async operations on the JVM