connections all go to master instead of seconaries

59 views
Skip to first unread message

Yanhong Wu

unread,
May 21, 2013, 11:07:53 AM5/21/13
to mongod...@googlegroups.com
Hi, 

I used mongodb in my django project. The mongod is in a relicaset, which is composed of a master with two secondaries. 

Server are running well, currently under very low reading and writing. 

However,  all my applications are connected on master,  while secondaries are the places where query are expected to go. 

Master now consumes 10% of 64G Memory, and the secondaries only less than 1%. 

I used netstat to grep connections, the grep result on an app server is: 

(27018 is the mongod port, 192.168.1.17 is the master server)

tcp        0      0 192.168.1.12:58852      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:4111       192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:50712      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:3904       192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:15353      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:3227       192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:39122      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:4875       192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:46359      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:32799      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:14236      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:50205      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:13210      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:43482      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:34671      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:10166      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:38286      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:46246      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:11244      192.168.1.17:27018      ESTABLISHED
tcp        0      0 192.168.1.12:48993      192.168.1.17:27018      ESTABLISHED


conf of django database: 

        'mongodb' : {
            'ENGINE' : 'django_mongodb_engine',
            'NAME' : 'images',
            'USER': 'user',
            'TEST_MIRROR': 'default',
            'PASSWORD': 'password',
            'HOST': 'mongodb://mongodb1:27018,  mongodb2:27018, mongodb3:27018',
            'OPTIONS' : {
                'replicaset': "articles_replicaset",
                'read_preference':ReadPreference.SECONDARY,
                'tz_aware' : True,
                'network_timeout' : 42
            }
        },

Pls let me know if any of my conf  mistakes.

Thanks in advance, 



--
wyh


Bernie Hackett

unread,
May 21, 2013, 12:24:21 PM5/21/13
to mongod...@googlegroups.com
django-mongodb-engine doesn't appear to support MongoReplicaSetClient (or even MongoClient).


You probably want to open a ticket in their bug tracker here:


Or ask on their mailing list here:



--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Yanhong Wu

unread,
May 21, 2013, 8:40:44 PM5/21/13
to mongod...@googlegroups.com

got you, many thanks. 

Yanhong Wu

unread,
May 23, 2013, 4:12:24 AM5/23/13
to mongod...@googlegroups.com
Hi Bernie, 

I found why django-mongodb-engine connects to mongodb master only, but I'm not clear  you mentions that django-mongodb-engine doesn't support MongoClient.

Please not that  Connection in your highlighted line is imported  from mongo_client, which is based on MongoClient: 

self.connection = Connection(host=host, port=port, **options)

So I think this connection is MongoClient connection. 


MongoClient connection connects to master server forever, except master is down when a new master should be elected. 


Please let me know if any misunderstandings. 

Thanks, 


--
wyh


Bernie Hackett

unread,
May 23, 2013, 10:13:41 AM5/23/13
to mongod...@googlegroups.com
Yes Connection inherits from MongoClient, but they use different default settings with considerable behavior changed. Connection is also deprecated.

To get the behavior you want (distributed reads) django-mongodb-engine has to optionally use MongoReplicaSetClient. Connection (and MongoClient) don't distribute reads.

Yanhong Wu

unread,
May 23, 2013, 12:02:29 PM5/23/13
to mongod...@googlegroups.com
exactly. 


Hope it could be merged. 
Reply all
Reply to author
Forward
0 new messages