Taking 10 seconds to log in

Hi,

Logins on our site are taking a very long time consistently.

We use a package called konecty:user-presence which seems to be the culprit, but I’m still confused as to why things take so long.

Upsert on the user sessions collection is taking 5 seconds according to Kadira:

upsert on usersSessions 5005ms SHOW LESS
coll : usersSessions
func : upsert
selector : {"_id":"PCQP7X87RDPsJxC4C"}
updatedDocs : 1
insertedId : PCQP7X87RDPsJxC4C

How could this be if the selector is just an _id?

If you have a very large number of users, the update portion of your upsert is probably taking a long time to scan your collection. Be sure to properly index your Meteor.users collection.

There are a fair number of users. But isn’t the update only affected by the
selector, and since this is an _id, how could I improve performance?

Ah, good call. I’m not sure. Meteor should create an index on _id by default. It may be helpful to use Mongo’s explain on your query to make sure that the results are what you expect:

db.users.find({_id: "PCQP7X87RDPsJxC4C"}).explain()

Ideally, the returned cursor would be either an IDCursor, or some kind of BtreeCursor. If you’re seeing a BasicCursor, you’re scanning and should set up an index.

https://docs.mongodb.com/manual/reference/explain-results/
http://joshowens.me/how-to-optimize-your-mongo-database-for-meteor-js/

If indexes aren’t you issue, I’m afraid I can’t help. :frowning: