practical limit for the number of databases in mongodb - mongodb

Can anyone say are if there is any practical limit for the number of databases in mongodb? I've started to have serious problems when I passed 120 databases. Simple things like :
> show dbs
Mon Feb 10 16:35:32 DBClientCursor::init call() failed
Mon Feb 10 16:35:32 query failed : admin.$cmd { listDatabases: 1.0 } to: 127.0.0.1:27017
Mon Feb 10 16:35:32 Error: error doing query: failed src/mongo/shell/collection.js:155
Mon Feb 10 16:35:32 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:35:32 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
>
Mon Feb 10 16:36:01 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:36:01 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
>
Mon Feb 10 16:37:01 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:37:01 reconnect 127.0.0.1:27017 ok
and
> getMemInfo()
{ "virtual" : 32, "resident" : 7 }
Mon Feb 10 16:39:00 DBClientCursor::init call() failed
Mon Feb 10 16:39:00 query failed : admin.$cmd { replSetGetStatus: 1.0, forShell: 1.0 } to: 127.0.0.1:27017
> shell
Mon Feb 10 16:39:38 ReferenceError: shell is not defined (shell):1
Mon Feb 10 16:39:38 trying reconnect to 127.0.0.1:27017
Mon Feb 10 16:39:38 reconnect 127.0.0.1:27017 ok
Yet the log file stayed enigmatic

What version of mongodb are you running on what host?
Here is a test on CenOS 6.5, mongodb 2.2 x86_64 direct from EPEL
Here is a sample python script that creates 1000 databases
from pymongo import MongoClient
mc = MongoClient()
for i in range(5000):
print i
mc['db%s'%(i)].test.insert({"test":True})
output:
...snip...
506
Traceback (most recent call last):
File "overload_mongo.py", line 6, in <module>
mc['db%s'%(i)].test.insert({"test":True})
File "/usr/lib64/python2.6/site-packages/pymongo/collection.py", line 357, in insert
continue_on_error, self.__uuid_subtype), safe)
File "/usr/lib64/python2.6/site-packages/pymongo/mongo_client.py", line 929, in _send_message
raise AutoReconnect(str(e))
pymongo.errors.AutoReconnect: [Errno 104] Connection reset by peer
There it is, looking at the log
ERROR: Uncaught std::exception: boost::filesystem::basic_directory_iterator constructor: Too many open files: "/index/bauman/db/_tmp/esort.1392056635.506/", terminating
The good ole too many open files problem
If you are on a enterprise linux platform, you can drop this file into /etc/security/limits.d/mongodb.conf and start a new session
mongodb hard nofile 99999
mongodb soft nofile 99999
mongodb hard nproc 99999
mongodb soft nproc 99999
I dont know how to achieve a similar result on windows.
The 'problem' lies in that MongoDB wants to memory map every single database file, so you need your hostOS to allow it to do so.
Same code as above
python overload_mongo.py
Output
...snip...
995
996
997
998
999
All better

Related

Mongo shell closes immediately

When I launch the mongo shell it closes immediately. There is no error. It was working fine (yesterday). My MongoDB server is running perfectly, and my application is connecting to it fine. I can't even launch the shell without connecting to a database:
C:\mongodb\bin> mongo --verbose
MongoDB shell version: 2.4.7
Fri Mar 27 10:35:38.425 versionArrayTest passed
connecting to: test
Fri Mar 27 10:35:38.472 creating new connection to:127.0.0.1:27017
Fri Mar 27 10:35:38.472 BackgroundJob starting: ConnectBG
Fri Mar 27 10:35:38.487 connected connection!
bye
Fri Mar 27 10:35:38.487 freeing 1 uncollected class mongo::DBClientCursor objects
Fri Mar 27 10:35:38.487 freeing 1 uncollected class mongo::DBClientWithCommands objects
Fri Mar 27 10:35:38.487 freeing 1 uncollected class mongo::BSONHolder objects
Similarly when connecting with no db:
C:\mongodb\bin> mongo --nodb --norc --verbose
MongoDB shell version: 2.4.7
Fri Mar 27 10:37:00.513 versionArrayTest passed
bye
Any and all thoughts on how to connect gratefully received.
As, mongod service has stopped; you need to go in the task manager-> Services Tab
-> search for MongoDB
-> Right click and click start.
You will find mongod shell is working as it was working previously.
I hope this helped!

No Primary during config change for slaveDelay from 86400 to 0

We have 6 node clusters. Three hidden nodes, two nodes to 24 hours delay.
ecset01:PRIMARY> cfg.members[5].slaveDelay = 0
0
ecset01:PRIMARY> rs.reconfig(cfg)
Mon Jan 12 11:30:15.802 DBClientCursor::init call() failed
Mon Jan 12 11:30:15.804 trying reconnect to 127.0.0.1:27017
Mon Jan 12 11:30:15.804 reconnect 127.0.0.1:27017 ok
Mon Jan 12 11:30:16.007 DBClientCursor::init call() failed
Mon Jan 12 11:30:16.008 JavaScript execution failed: Error: DBClientBase::findN: transport error: 127.0.0.1:27017 ns: admin.$cmd query: { authenticate: 1, nonce: "fe555b6fcb676ba7", user: "admin", key: "a2d59cbc51cf8c61b4cb45b7f4f8db80" } at src/mongo/shell/query.js:L78
>
Mon Jan 12 11:30:20.139 trying reconnect to 127.0.0.1:27017
Mon Jan 12 11:30:20.139 reconnect 127.0.0.1:27017 ok
ecset01:SECONDARY>
I like to know how to change slaveDelay =0 without impacting Primary.
You cannot. Reconfiguring the replica set can cause the primary to step down, causing a new election. The election will be brief if the replica set is healthy and you are only changing the delay, but you should still try to change configurations on your replica set during a maintenance window.

Setup mongodb for mongo-connector

Did I use the right setup for mongo-connector? I followed this steps here.
PS C:\mongodb\bin> mongod --port 27017 --dbpath C:\data\db --replSet rs0
Then I start C:\mongodb\bin\mongo.exe and typed rs.initiate() and rs.conf(). If I check the status I get two errors:
rs0:PRIMARY> rs.status()
Sat Jan 25 19:19:47.788 Socket say send() errno:10053 An established connection
was aborted by the software in your host machine. 127.0.0.1:27017
Sat Jan 25 19:19:47.803 Error: socket exception [SEND_ERROR] for 127.0.0.1:27017
at src/mongo/shell/query.js:78
Sat Jan 25 19:19:47.803 trying reconnect to 127.0.0.1:27017
Sat Jan 25 19:19:47.819 reconnect 127.0.0.1:27017 ok

Executing a JavaScript in MongoDB

I am trying to execute a Java script file in MongoDB at port 5930. Mongo can listen to the Database on that port:
./mongo localhost:5930
connecting to: localhost:5930/test
Server has startup warnings:
Wed Dec 18 13:15:58.906 [initandlisten]
Wed Dec 18 13:15:58.906 [initandlisten] ** WARNING: /proc/sys/vm/overcommit_memory is 2
Wed Dec 18 13:15:58.906 [initandlisten] ** Journaling works best with it set to 0 or 1
Now when I execute test.js at port 5930 but I get the following error:
./mongo test.js
connecting to: test
Wed Dec 18 13:22:56.011 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed
The test.js has the following line:
conn = new Mongo("localhost:5930);
How can I run the script at port 5930? and Why did the script always try to execute from the default port (27017)?
Thanks
Mongo tries to connect itself to the local database automatically, before it looks at your script.
Connect to a local Mongo database running on an alternate port with this mongo command line:
mongo --nodb test.js
And have your code open the connection (which you already do).

error during mongo db.shutdownServer()

I got the following error when I try to shutdown mongodb in my VM Ubuntu.
I am running 12.10 Ubuntu headless server.
The current Mongodb Shell Version is 2.0.6
use admin
switched to db admin
> db.shutdownServer()
Tue Dec 10 14:17:03 DBClientCursor::init call() failed
Tue Dec 10 14:17:03 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1
server should be down...
Tue Dec 10 14:17:03 trying reconnect to 127.0.0.1
Tue Dec 10 14:17:03 reconnect 127.0.0.1 ok
Tue Dec 10 14:17:03 Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
Tue Dec 10 14:17:03 SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [1] server [127.0.0.1:27017]
Tue Dec 10 14:17:03 DBClientCursor::init call() failed
Tue Dec 10 14:17:03 query failed : admin.$cmd { getlasterror: 1.0, w: 1.0 } to: 127.0.0.1
Tue Dec 10 14:17:03 Error: error doing query: failed shell/collection.js:151
What should I do?
My reason for trying to shut it down is because I want to update to mongo 2.2.
Please advise.
Although the messaging is confusing, this is actually expected behaviour if you shutdown via the mongo shell. Since you ran the db.shutdownServer() command through the mongo shell it can no longer connect to the server and this is essentially indicating the shell has been disconnected.
The mongo shell tries to automatically reconnect when you hit enter, which results in the messages like "trying to reconnect ...".
There is an open issue to improve this behaviour/messaging if you'd like to upvote/watch it: SERVER-5467.