c# - NHibernate - first query is painfully slow -
database table (postgresql) containing 10000 rows:
create table test ( id bigserial not null, text text, constraint test_pkey primary key (id) )
classes:
public class test { public virtual int id { get; set; } public virtual string text { get; set; } } public class testmap : classmap<test> { public testmap() { table("test"); id(x => x.id, "id"); map(x => x.text, "text"); } }
here how query database:
using (isession session = sessionbuilder.opensession()) { stopwatch s = new stopwatch(); s.start(); var result = session.queryover<test>().where(test => test.text == "aaa").list(); s.stop(); console.writeline(s.elapsedmilliseconds); // >150ms s.restart(); var result2 = session.queryover<test>().where(test => test.text == "bbb").list(); s.stop(); console.writeline(s.elapsedmilliseconds); // ~4ms }
why first query takes long? there way speed up?
quite caching. have no indexes can query, full table scan way either answer. first 1 fill buffers , caches, either db (possibly won't table scan) o/s cache or disk pages. second query benefit pages being cached @ level.
craig's suggestion subtle spin on caching & priming - first time tends incur bit of hit , need find out what. in web apps can bit of priming before app accepts requests. if more of batch thing can't disguise warm-up may have live or ditch nhibernate.
take advice & measure what's going on in hibernate too.
Comments
Post a Comment