문제

I have been using SubSonic 2 for ~5 years now and have loved it. However, for the past six months I've been toying with the idea of moving either to SubSonic 3 or to a similar ORM tool. Since my company uses plenty of Telerik's tools, I thought I'd try OpenAccess. After getting it configured, I figured I'd try an extremely basic task of loading up a RadGrid with information from our Users table (~30 records).

So, within the Grid's OnNeedDataSource event I have the following:

var start = System.Environment.TickCount;
context = new EntitiesModel();
rgUsers.DataSource = (from u in context.Users select u);
var stop = System.Environment.TickCount;
var elapsed = stop - start;
litTelerik.Text = string.Format("This process took <b>{0}</b> milliseconds", elapsed);

After building that and running the page, it spits back that it took 1607 ms. However, after refreshing the page it comes back as 0 seconds. (Why?)

I then put in the SubSonic code:

var start = System.Environment.TickCount;
rgUsers.DataSource = new UserCollection().Load();
var stop = System.Environment.TickCount;
var elapsed = stop - start;
litTelerik.Text = string.Format("This process took <b>{0}</b> milliseconds", elapsed);

I run the code for the first time and it says it took 171 ms. After refreshing the page, it reports that it took 60-70ms.

So, my question is: Why does OA take considerably longer to load on the first visit, but zero seconds to load on each page refresh? Whereas SubSonic is considerably faster on the first visit, but takes ~65ms on each page refresh?

I apologize if this is a "basic" question or if I'm not testing performance adequately. If there's any way to improve this method, I'd greatly appreciate any advice.

Thanks, Andrew

도움이 되었습니까?

해결책

OpenAccess has an internal Database object that is created the first time you create an OpenAcccessContext. It basically calculates all of the defaults, creates caches, initializes other infrastructure objects, etc.. As soon as it is created it is stored in an internal static dictionary (with the connectionID being the key).

Every other context created, would use that internal object and wouldn't have the overhead at all. That being said 1600 ms is a bit high, you might consider changing the mapping type (xml is optimal, performance wise).

An optimization would be to make sure that the model is initialized in the application start handler. The following code should do the trick.

void Application_Start(object sender, EventArgs e)
{
    var modelInfo = new EntitiesModel().Metadata;
}

EDIT: As a follow up, it says 0 ms, and that is not actually the query execution time. What the query return is an IQueryable that is later executed. You have to call ToList() in order to get real data.

다른 팁

The reason could be that opening a database in OpenAccess takes a longer time than in SubSonic. Try to perform a trivial operation like getting a count just to open the database before you measure the load time. Do the same in SubSonic too.

context = new EntitiesModel();
context.Users.Count();
var start = System.Environment.TickCount;
rgUsers.DataSource = (from u in context.Users select u);
var stop = System.Environment.TickCount;
var elapsed = stop - start;
litTelerik.Text = string.Format("This process took <b>{0}</b> milliseconds", elapsed);

Thomas

Don't know if this is off-topic, but I've been using and contributing to SS2 and SS3 over the last few years. I've just completed an overhaul and added an MsAccessProvider to SS2, and Enum generators to SS2 and SS3 (these are committed and live at the project page).

I've also put together my own caching framework for SS3 which allows automated selective caching of data (as generic dictionaries) from tables in the database referenced by any unique index. I was able to cache lookup data for template based generation of web pages and improve response from about 2 minutes with SS3 LINQ lookups to a fraction of a second. (I haven't released this publicly)

I'm just not sure where to post this stuff so as to get the attention of users of SS. My commits to the source and closing of open issues have generated precisely zero response.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top