Why are identical NHibernate queries an order of magnitude less executed in a WinForm project than an MSTest unit test?

I have an application that runs as a service in production, but we conduct manual testing using a simple graphical interface - almost nothing happens in it, it's just a shell with a text box for input.

I recently changed my database schema and updated my mappings to match, and then the GUI suddenly worked very slowly in a trivial case. After doing some logging and running it several times, it turned out that this request was the new bottleneck:

public void Refresh() { using (var session = _sessionFactory.OpenSession()) { _allFields = session.Query<FieldDefinition>().ToList(); } } 

Repeatedly 1:08 minutes were taken for this method (although there were only about 300 FieldDefinitions in the database). By this time, I was tired of manually restarting the GUI, so I wrote a unit test that performed the same case, but I could not reproduce the slowdown.

My test is called the same top-level object as a GUI with the same input. I expect this to work almost at the same time. But when launched in Visual Studio with MSTest, the same request took less than two seconds. This is 1 / 30th time. He did the same job, only much faster.

Things I checked to see if I can get them to work the same way:

  • Both approaches gave the same number of SQL statements.
  • This does not seem to be caused by JITter (several runs of the GUI without restarting it, same time again and again)
  • Isolating it so that it uses a new ISessionFactory for each Refresh has no effect
  • Disabling logging (log4net) had no effect

Changing the request to download the child file really worked ... view: after applying the patch, the WinForms application runs as fast as the unit test. Unit test speed has not changed significantly (tenths of a second).

The old query caused select n+1 problem: but the problem was present both in Winform starts and in MSTest. Because of this, only the WinForm application saw a significant slowdown.

How can I explain this? Why will only a WinForm application experience significant slowdown during a Select N + 1 request?

+4
source share
1 answer

I would say a profile, and then you find out.

0
source

All Articles