i'm hoping can give me insight oddity. don't know if there's leak of kind or way of using mongodb wacky wrong. copied code mongodb csharp ecosystem tutorial. started messing it, noticed time perform query gradually rising. i'm using c# 4.5, mongodb 2.4.5, , running windows 7.
the time perform initial query took approx 33 ms, each iteration of loop gradually increases. each time run code, query time starts @ approx 33 ms increases 61 ms. if use id starts @ 15 ms , increases 34 ms. tried using both linq , native eq style syntax query object , had similar increasing results. have expected time increase , decrease each iteration, not increase. i'm pretty new mongodb, first time saw 2 days ago insight finding out happening or what's wrong way i'm using code appreciated. (why did -- happened notice off chance same query getting slower , got curious)
using system; using system.diagnostics; using mongodb.bson; using mongodb.driver; using mongodb.driver.builders; namespace snippets { public class entity { public objectid id { get; set; } public string name { get; set; } } class program { static void main(string[] args) { stopwatch sw = new stopwatch(); var connectionstring = "mongodb://localhost"; var client = new mongoclient(connectionstring); var server = client.getserver(); var database = server.getdatabase("test"); var collection = database.getcollection<entity>("entities"); var entity = new entity { name = "x" }; collection.insert(entity); var query = query<entity>.where(e => e.name == "x"); (int = 0; < 100; i++) { sw.start(); var item = collection.findone(query); sw.stop(); console.writeline("{0:0} ms", sw.elapsedmilliseconds); } collection.remove(query); } } }
of course getting slower, because need index on collection on name since query collection.findone(query); filtering on name field.
Comments
Post a Comment