mongodb : help needed to know for connection information - mongodb

I am using MongoDb as the Database for our WebApplication
Currently we are facing a issue in mongoDb which is "max connections 8000 exceeded"
To solve this problem we have decided to increase the connections to 20000
But not sure how to increase the connections in MongoDB .
Currently we have only this property called maxConnections whose vaue is 800 in our code
This is the stats collected from mongodb server
db.serverStatus().connections
{ "current" : 7000, "available" : 1000 }
We start the mongodb this way
mongod --config /etc/mongodb.conf
and inside the mongodb.conf we have
replSet = test
fork = true
port = 27017
I am not sure why the max conection is showing 8000 ?? where it is hardcoded ??
Could any body please tell me how to find why the connection size is 8000 in my case ??

Do you actually have over 8000 threads access this database concurrently? Perhaps you are instead just spinning up a ton of connections you don't actually need?
That said, the 8000 limit is probably coming from your system limits. ulimit will restrict the number of usable sockets, which will restrict the number of connections. See the mongod documentation for a complete explanation.
Your approach here, though, should probably be to make sure you're reusing connections rather than just creating tons of them, since it's extremely doubtful that you are actually running 8000 concurrent clients.

Related

MongoDB connection abnormal increase

I use mongodb client to connect Database like here. Notice, i only use one connect to DB, but when i start my application and check Mongodb connection by command.
db.serverStatus().connections
Before start app at 8 connection, after it increase more 20 connection. I miss something, any one help me to explain ?

My MongoDB CPU usage becomes 100 percent when doing multiple queries at a specific time

I am using MongoDB 3.4, facing the issue when do multiple request at a time.
For Example if I do 1000 request at 200 sec, at that time MongoDB CPU usage will be around 98 - 100 percent, and at that time CPU is completely choked and returns failure of system.
What should be the good approach for solving this. I used replica set which runs on :
primary: port 27017
slave: port 27018
arbiter: port 27019
System Configuration : Windows 10 (4 VCPU, 8GB Ram, 1 TB Harddisk)
Any suggestion/help will be really appreciated.

Mongo DB logs showing hundreds of open connections without any running operations

When I check my MongoDB logs (/var/log/mongodb/mongodb.log), it shows something like:
end connection 127.0.0.1:57132 (**651 connections now open**)
But I am not running so many processes. How are so many connections open? Is there a way to close all these connections?
I do run a cron job (from shell script) to query mongodb every minute. Is that what is causing so many open connections? Should I close the connection every time after querying?
When I run db.serverStatus().connections, I get:
{ "current" : 500, "available" : 319, "totalCreated" : NumberLong(1328754) }
I think that's too big a number. How do I handle this?
Mongo does not usually log information about connections unless they are somehow exceptional (in size of the results or time to perform them for instance). Is this a cluster? If so these connections are probably the normal result of the mongo boxes syncing to each other. If not try
netstat -ln|grep 27017
to see who's using your mongo.
Two reasons I have seen for high connection counts:
When using replication
The Java driver didn't close any connections one it had opened them. Could be controlled with a property

How to check application is reading from Secondary Node in MongodB?

I have a 3 member replica set. Read preference is set as "Secondary Preferred" How to check application is reading from Secondary Node in MongodB? Please suggest.
Firstly you can configure profiling. For that you need to start your mongodb servers with option --profile 2 and configure log file. It'll log all queries.
After that you can read log for each instance db. Simple example:
db.your_collection.profile.find({ns: "name_your_db.your_collection"})
Secondly you can use mongotop. You need to start it for each mongodb server.
For example:
mongotop -h server_ip:server_port seconds
mongotop -h 127.0.0.1:27017 5
It'll print every specified period of time log, where you can read how much time for read or write is taken for each collection.
Other means of determining whether queries are sent to secondaries:
Enable command logging in the driver, which should tell you which server each command was sent to.
Inspect server logs for connections being made or not made, then set minimum connection pool size to 0 so that a connection is only made when needed for a query, then run some queries.

Is there anyway to discover which ip addresses are connected to the db?

I can determine the current number of connections by
db.serverStatus().connections
but all that gives me is the current number of connections. Is there anywhay to determine which ips are connected and which connection number they have been assigned to?
From mongo shell, this will print client IP:port, along with connection ID:
db.currentOp(true).inprog.forEach(function(d){if(d.client)print(d.client, d.connectionId)})
Note: passing true to db.currentOp() shows all connections (including idle). The docs have more examples on filtering connections, see:
db.currentOp reference and currentOp output fileds with descriptions.
From mongo shell run db.currentOp() to show all active connections or db.currentOp(true) to show all connections.
It depends on your db engine, but one simple way you can do it with netstat, checking the port your database allows to connect, and if you have security concerns you can limit the ip addresses that connect in the configuration file. Most databases by default only allow localhost to connect to them.