im trying to work with mongodb from java. the problem is that I run out of connections really quick in this one usecase I have.
I open a mongoclient, run the query and then call mongoclient.close()
this is repeated for my need 7000 times. Creating the client 7000 is not performance wise and this is NOT the question.
but after 500 times getting the connection simply stalls and I can see from the monitor that there are 500 open connections. But I call “close()” every time so why is getting the connection the 501th time a issue?
its unused, its closed, it should be back in the pool for then next use.
the connectionstring has added info on max times but that also does nothing to release or close unused connections
if you have a application where it makes sense (most will) where you
create the mongoclient
loop
query
close mongodb client
then thats fine and best performance and so on. this is for any database the samme.
I need to
in loop
create a mongodb client
query once
close the client
so again. the client is created and it will create a connection pool even not just one connection.
BUT BUT BUT I do CLOSE it so it should release all connections.
waaaayyyy better performance on any system if you only create the connection/pool once of cause, so gain thats not the question.
the question is why does is not even work on mongodb. why are the connections/pool not released so I can create a new one if thats what I want or need.