MongoDb C # driver slow for first request after application start

I am testing MongoDB (3.0) with a C # driver and I noticed something strange.

I started testing db localy and then created a test console application. There I do this to initialize the driver:

var client = new MongoClient();
var database = client.GetDatabase("test");

      

So far so good, but then I tried to get data based on id (indexed by default), so I added the following:

var collection = database.GetCollection<BsonDocument>("myData");
var filter = Builders<BsonDocument>.Filter.Eq("id", "F1234");
var result = collection.Find(filter).ToListAsync().Result;

      

To get the average time consumption, I added some code to measure the time for the request (by decorating it with two DateTime.Nows and then subtracting them - dirty, I know) and put all the code in a loop. Also, I let each display of the iteration time in the console

Now, every time I press F5, the first iteration takes about 150ms, but the next iterations take about 1ms on average. The important thing is that this has nothing to do with the cache, because each iteration can ask for a different ID, and the result is exactly the same. Also, I can re-initialize MongoClient with every iteration, but it always behaves as I described.

Every first request after launching the application takes longer.

I need to know if this is indeed caused by some initialization inside MongoClient (maybe some static classes are initialized with the first request?), Or if this could happen at any time when the application starts up.

Note : I've also tried replacing the Thread.Sleep request to make sure it's not a .NET issue. This is not the case. It really is "collection.Find" and takes longer from the first use.

Thank!

Note after a while

So, after a while, I found out that every CRUD operation needs a "warm-first-request". Sometimes every CRUD operation for every collection. It's strange. I am posting this so others will know :-)

+3
performance c # mongodb driver mongodb-.net-driver


source to share


No one has answered this question yet

Check out similar questions:

2847
Improve SQLite performance per second per second?
1299
How can I query MongoDB with "how"?
1250
Replacing 32-bit loop counter with 64-bit values ​​leads to crazy performance deviations
3
MongoDB performance is slower with C # driver, not command line
3
MongoDB C # driver fast on take (1) but slow to type (2)
2
MongoDB C # cursor performance issue
1
Slow MongoDB query over index
1
MongoDB C # performance
0
MongoDB Counter Query Performance
0
How to optimize a C # mongodb query in large datadases?



All Articles
Loading...
X
Show
Funny
Dev
Pics