[CSHARP-822] driver v1.8.2 driver query slow Created: 14/Sep/13  Updated: 25/Aug/15  Resolved: 23/Sep/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.2
Fix Version/s: 1.8.3

Type: Bug Priority: Critical - P2
Reporter: CowVirus Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive Test.MongoDbDriver.zip    

 Description   

Realize the same function of the code. like this(run environment: cpu:E5300,Memory:4GB ,win2008R2 x64):

class Program
{
static void Main(string[] args)

{ UseMongoDbDriver1_5_0_Test(); UseMongoDbDriver1_8_2_Test(); Console.Read(); }

static void UseMongoDbDriver1_8_2_Test()
{
var client = new MongoClient();
var server = client.GetServer();
Stopwatch st = new Stopwatch();
st.Start();
var result = server.GetDatabase("Test").GetCollection("Product").FindAll().SetLimit(10).ToList();
st.Stop();
Console.WriteLine("Driver v1.8.2 QueryResult ToList ElapsedTime:

{0} ms", st.ElapsedMilliseconds);
//output: Driver v1.5.0 QueryResult ToList ElapsedTime: 1445 ms
}

static void UseMongoDbDriver1_5_0_Test()
{
MongoServer server = MongoServer.Create("mongodb://127.0.0.1:27017/Test");
MongoDatabase db = MongoDatabase.Create("mongodb://127.0.0.1:27017/Test");
using (server.RequestStart(db))
{
Stopwatch st = new Stopwatch();
var result = db.GetCollection("Product").FindAll().SetLimit(10).ToList();
st.Stop();
Console.WriteLine("Driver v1.5.0 Query Result ToList ElapsedTime: {0}

ms", st.ElapsedMilliseconds);
}
//output: Driver v1.5.0 QueryResult ToList ElapsedTime: 0 ms
}
}

that maybe a bug. driver v1.5.0 query result faster than v1.8.2 ?



 Comments   
Comment by Githook User [ 25/Aug/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-822: added in check to not fetch the next batch when it is not required.
Branch: v1.8.x
https://github.com/mongodb/mongo-csharp-driver/commit/82e6c70fca0db4b733c41ae05bdab511deeb25e8

Comment by Craig Wilson [ 23/Sep/13 ]

This has also already been fixed on master due to some refactoring in the master branch.

Comment by auto [ 19/Sep/13 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-822: added in check to not fetch the next batch when it is not required.
Branch: v1.8.3
https://github.com/mongodb/mongo-csharp-driver/commit/82e6c70fca0db4b733c41ae05bdab511deeb25e8

Comment by Craig Wilson [ 19/Sep/13 ]

@CowVirus,

Thanks for the report. We have reproduced this result and have identified the problem. We'll be issuing a point release very soon to fix this. In the meantime, when you want to set a limit, you can use a negative number. For instance, FindAll().SetLimit(-10).ToList() will work correctly. Please keep an eye on this ticket for the fix which should come today and a 1.8.3 release to nuget and github.

Craig

Comment by CowVirus [ 18/Sep/13 ]

TestCase:

databaseName : Test chanage to test

Comment by CowVirus [ 18/Sep/13 ]

1. example document :
========================================================================
class TestCollection
{
public int Id

{ get; set; }

public string Name { get; set; }

}

class Program
{
static void Main(string[] args)

{ InsertTestCollections(); Console.Read(); }

static void InsertTestCollections()
{
IList<TestCollection> cols = new List<TestCollection>();
for (int i = 0; i < 200001; i++)
{
cols.Add(new TestCollection()

{ Id = i + 1, Name = Guid.NewGuid().ToString("N") }

);
if (cols.Count == 10000)

{ Inserts(cols); cols.Clear(); }

}
}

static void Inserts(IList<TestCollection> items)
{
var client = new MongoClient();
var server = client.GetServer();
var db = server.GetDatabase("test");
var result = db.GetCollection<TestCollection>("TestCollection").InsertBatch(items);
Console.WriteLine("insert TestCollection count:

{0}

", result.Sum(s => s.Ok ? 1 : 0));
}
}
========================================================================

2. my mongod is run on local

3. my mongodb setup ini:
=======================================================================
##dbPath
dbpath = D:\Develop\NoSql\MongoDb\v2.x\bin\Data
directoryperdb = true
port = 27017
master =true

    1. logPath
      logpath =D:\Develop\NoSql\MongoDb\v2.x\bin\Logs\MongoDb.log
      logappend = true
    1. Service Config
      serviceName=MongoDb-v2.x
      serviceDisplayName= MongoDb-v2.x
      serviceDescription = Mongodb LocalService
      =======================================================================

somebody say , The cause of the issue because of "Serializer ".
you can test more machine for the testcase, i tested many times the all result is slowly by driverv1.8.2.
thanks.

Comment by Craig Wilson [ 17/Sep/13 ]

When I run these on my local machine, I get 0ms for every single one of them. However, I don't know what data you are fetching (so I made up my own). So I have a couple further questions:

  1. Could you provide an example document that is stored in your database?
  2. Are you running mongod locally or on a different machine?
  3. What is your setup? Replica set, stand alone machine, sharded?
Comment by CowVirus [ 17/Sep/13 ]

hi,all.
I test the mongodb driver version :v1.5.0, v1.7.1,v1.8.2
on my machine the same code query result for the execution time(avg) result :
v1.5 : 2.39 ms
v1.7.1: 2.98 ms
v1.8.2 : 677.92 ms(slowly)

please download my attach files ,open my solution 's three project and test.
maybe that is really a performance issue for the driverv1.8.2
thanks.

Comment by CowVirus [ 17/Sep/13 ]

Thanks for your reply!
I'm sorry to my code that is incorrect ...and my apologize for the inconvenience this error may have caused you.
for the code is some pseudo code .
I'll check my TestCase and reconfirm this issue .

Comment by Craig Wilson [ 14/Sep/13 ]

In addition to not calling start in your 1_5_0 test method, you also aren't using the same code. In 1_5_0, you have a server.RequestStart(db) call which doesn't exist in your 1_8_2 test. If you want accurate, apples to apples comparisons, you need to be doing the exact same thing.

Comment by Robert Stam [ 14/Sep/13 ]

I don't see a call to st.Start() in your UseMongoDbDriver1_5_0_Test method... maybe that explains why it appears to take 0ms?

It's also not clear to me how you can use two different versions of the driver in the same program.

Generated at Wed Feb 07 21:37:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.