I am writing an application which is storing a lot of objects into MongoDB via Spring Data's MongoTemplate
. In order to avoid synchronization, I am creating a separate MongoTemplate
for each thread. In fact, each thread get's it's own just about everything to avoid synchronization.
The application processes events generated while users interact with a web page. So, events from a specific user needs to be processed sequentially while events across multiple users can be processed in parallel. The application currently consists of N pipelines and a load balancer which distributes the events to a pipeline based on a hash/mod of userId. At the end of the pipeline, data is written to MongoDB using Spring Data MongoDB Template.
This single process is able to process 2500 events/second. However, I am observing significant (at the rate of 2500 events/second any blocking becomes rather significant) contention between threads. All in the area of ClassTypeInformation accessing the synchronized CACHE.
Unfortunately, MongoTemplate
uses ClassTypeInformation
which stores a cache in a synchronized map. So, no matter how I try, writing data to MongoDB always hits this contention between my worker threads.
I think ClassTypeInformation
should be converted into a bean so that one can be provided if user so desires. Allowing for this, would remove the contention between multiple threads.
Does anyone know why this was implemented as a static as opposed to a normal Spring bean? Are there any plans to make this change?