Performance issue cause of listofDatabases command in mongodb

I’m facing slowness in mongodb because of the listDatabase command fired by the monitoring tool . Can any of you please suggest why the listDatabase command takes more time and sometimes it hangs when concurrency increase
listdatabase_strace.log (49.8 KB)
. Any inputs so that I can check further.

Command: strace -i -t -f mongo --quiet --eval "rs.slaveOk() , printjson(db.adminCommand({'listDatabases':1}))"

MongoDB Version : 3.2.1 - We know, this is a very old version and on it to upgrade .
Total Database count = ~1000

Strace logs :

[pid  9403] 13:01:48 [00007ffa738fb68c] futex(0x2f4644c, FUTEX_WAIT_PRIVATE, 5, NULL <unfinished ...>
[pid  9405] 13:01:48 [00007ffa738fedac] sendto(3, "b\0\0\0\2\0\0\0\0\0\0\0\332\7\0\0admin\0listDataba"..., 98, MSG_NOSIGNAL, NULL, 0) = 98
[pid  9405] 13:01:48 [00007ffa738fec2c] recvfrom(3,
"\205\355\0\0K\223I\7\2\0\0\0\333\7\0\0", 16, MSG_NOSIGNAL, NULL, NULL) = 16
[pid  9405] 13:04:22 [00007ffa738fec2c] recvfrom(3, **"p\355\0\0\4databases\0A\355\0\0\0030\0005\0\0\0\2name\0"..., 60789, MSG_NOSIGNAL, NULL, NULL) = 60789**
[pid  9405] 13:04:22 [0000000001049787] mmap(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa6a3ff000
[pid  9405] 13:04:22 [0000000001049787] mmap(0x7ffa6a300000, 1044480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffa6a300000

Attaching strace logs :

Hi @Vinay_Jaiswal

This issue was discussed in SERVER-3181 and was fixed in 3.2.13 and newer, where you have the option to list database names only by using:

db.adminCommand( { listDatabases: 1, nameOnly: true} )

since it was determined that when listing a large number of databases, calculating the sizes was quite time consuming.

If the monitoring tool you’re using does not permit changing the listDatabases command to show only the names, you might want to raise this issue with the creator of that tool, since it’s a pretty big performance hit if there are a lot of databases like in your case.

Best regards
Kevin

1 Like

@kevinadi Thank you for the quick response and will check with our mon team to incorporate the required changes in our source code.

Quick query : How are we solving to get db size metrics considering large databases count ?

Since the nameOnly parameter is only added in MongoDB version 3.2.13 and newer, unfortunately you would have to upgrade to it.

The last release in the 3.2 branch is 3.2.22 in Dec 2018, but please consider upgrading to a supported MongoDB version. At this time of writing, it means at least the 4.2 series.

Best regards
Kevin

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.