使用java获取mongoDB中的打开连接数 [英] Get the number of open connections in mongoDB using java

查看:91
本文介绍了使用java获取mongoDB中的打开连接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序需要打开大量连接(Mongo)。我收到错误:

My program requires a large number of connections to be open (Mongo). I get the error :


打开的连接太多,无法再打开

Too many connections open, can't open anymore

$在819个连接后b
$ b

。我已经知道我们可以增加这个限制。但这不是我的想法。我正在考虑关闭MongoClient对象,然后在800个连接后再次创建一个新对象。

after 819 connections. I already know we can increase this limit. But that's not what I have in mind. I'm thinking of closing the MongoClient object, and then creating a new one again after 800 connections.

我的想法是,使用新的mongoClient对象,所有连接都将是关闭,当我再次开始/创建它时,连接将再次打开,直到800.
因此没有给出错误。 (如果这种方法完全错误/不会给出所需的结果,请告诉我。)

My thinking is that with a new mongoClient object all the connections will be closed and when I start/create it again, the connections will be opened again until 800. Thus not giving the error. (Let me know if this approach is totally wrong/ won't give the required results.)

为此我需要知道ATM打开的连接数量。有没有办法使用java获取此信息?

For this I need to know the number of connections opened ATM. Is there any way to get this information using java?

推荐答案

您可以使用 db.serverStatus()命令。它有一个连接子文档,其中包含总/可用连接信息。

You can get connection information by using the db.serverStatus() command. It has a connections subdocument which contains the total/available connections information.

有关更多信息:

  • Documentation of server status
  • Details of connections block

这篇关于使用java获取mongoDB中的打开连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆