Spring mongodb connection pool limit
Spring Mongodb Connection Pool Limit
I had started to observe performance degradation in my app, when the traffic spikes up in very few minutes. The current connections of front facing Apache will spike up during this period of time. Upon investigation found that mongodb primary server experiences high loadavg during this time.
My mongo primary is CPU bound, as the entire working set fits comfortably in to the main memory. During the high loadavg, there were about 3000 active client connections, served by 4 cores. It is evident that 4 cores is struggling to deal with 3000 client connections at the same time. Just when I was thinking about increasing the no.of cores, I had came across this excellent article on pool sizing About-Pool-Sizing. Instead of scaling up the CPU, I decided to limit the pool size in each server. By default, Java Mongo driver can open 100 connections in a pool, but it can be customised with additional options in the connection string.
spring.data.mongodb.uri: mongodb://user:password@primary:27017,secondary_1:27017,secondary_2:27017/rpg_db?maxPoolSize=10&waitQueueMultiple=10
After this parameter tuning, loadavg went below 1 and the performance returned to normal even during the peak traffic.
Comments
Post a Comment