Help with linq classes

Help with linq classes

Postby Trixz » Tue 29 Sep 2009 09:52


I'm new to LINQ and I have a application and have tried to layer the application. There have been many issues and I'm not sure I think that LINQ should be used with layers at all... not the way I do it anyway... :)

Anyway... I now got some trafic to the pages and instantly the w3wp got a major cpu % and memory. I'm guessing that some of my code is leaking memory and when i did a dump i see that the following classes are overrepresented in total memory

Code: Select all

mainly the first 2.

I'm guessing this is the queries run in the context, and that they are not released, but could you explain the exact meaning of the diffrent Query types?

I also have alot of connection and context objects (equal number of object). Since I use connectionpooling, I thought that when I created a new context, the pooling should not create a new conenction object, but instead use one of the old.
Posts: 31
Joined: Thu 30 Apr 2009 07:59

Postby AndreyR » Tue 29 Sep 2009 11:59

What version of dotConnect are you using?
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby Trixz » Tue 29 Sep 2009 12:06

Sorry, forgot... Devart dcOracle-090806v5.25.39
Posts: 31
Joined: Thu 30 Apr 2009 07:59

Postby AndreyR » Wed 30 Sep 2009 12:51

Thank you for the information.
We are investigating the performance question, I will post here about the results.
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby Trixz » Thu 01 Oct 2009 07:47

Ok, spent some time googling my problems.

This is how I did it.
I had a data class to retrieve all data. I created an instance of that and there i did

private MyContext context = new MyContext(ConnectionString);

Each page generated it's own instance of this object, so a new context was created each time.

When the page died, the object die, but the context seems to live on.

If i try to create a new context in each function, I get the same result. And if i try a

Code: Select all
using(MyContext context = new MyContext(ConnectionString))
   // my code

I get the context removed with lazy loadings....

So then I did a LoadOption to load Order -> OrderDetails -> Product, but it seem there only possible to do this in one step.

And, the ways to do this in many step results in many many sql to the server (not tested, just googled confirmed)
Posts: 31
Joined: Thu 30 Apr 2009 07:59

Postby Trixz » Fri 02 Oct 2009 12:27

Ok, I how have resolved the problem described above. I had to create a helper class and create a new context at page start, and, more important, on unload, call Dispose() on the object.

Now the memory is fixed... there is of course a new problem.
The CPU is still high and if I take a dump and run !finalizequeue (Windbg) i find that generation 2 has lots of objects
Code: Select all
generation 0 has 475 finalizable objects (03bee37c->03beeae8)
generation 1 has 15 finalizable objects (03bee340->03bee37c)
generation 2 has 2854 finalizable objects (03beb6a8->03bee340)
Ready for finalization 0 objects (03beeae8->03beeae8)

If I look at what these objects is i get this
Code: Select all
6c12433c      335         4020 System.Reflection.Emit.DynamicResolver+DestroyScout
5d5c50b4       28         4144 System.Data.DataColumn
05c49308      132         5280 Devart.Data.Linq.EntityEntry`2[[SYSteam.Bonnier.Entity.Artiklar, EntityData],[Devart.Data.Linq.Key`2[[System.String, mscorlib],[System.Double, mscorlib]], Devart.Data.Linq]]
04f19770      129         5676 Devart.Data.Linq.EntityEntry`2[[SYSteam.Bonnier.Entity.Webtext, EntityData],[System.Guid, mscorlib]]
6c124220     2084        83360 System.Reflection.Emit.DynamicResolver
Total 3344 objects

I guess it is any dynamic lamda/linq queries that result in this, or?

This data is with almost no load to the server.
Is there any way to take off the work of gc and reduce the number of objects in gen 2?

What i figure the relation should be 1 gen 2 for 10 in gen 1, and 1 gen 1 for 10 in gen 0... (1:10:100)

What do you thing is generating all the dynamicResolver classes?
Posts: 31
Joined: Thu 30 Apr 2009 07:59

Postby Trixz » Mon 05 Oct 2009 12:46

From microsofts analytics

According to the difference between !runaways in the 3 dumps, it's clear that ALL the CPU is burned by the task running on those threads.
All of them are running the same page: /AgentWebb/agent/Default.aspx. This page seem to be long to be executed, some of the thread has been processing the page for 20 seconds at the time of the dump.
All of the threads, at the time the CPU is burned, are performing the same task: LinQ operations on an Oracle remote database.
Those tasks, and those module, are the once burning CPU.

Here is what i'm using...

Code: Select all
60470000 6054c000   Devart_Data_Oracle   (deferred)             
    Image path: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\agentwebb\10e627e6\e56c91f0\assembly\dl3\73700de8\dc1ff914_3635ca01\Devart.Data.Oracle.DLL
    Image name: Devart.Data.Oracle.DLL
    Using CLR debugging support for all symbols
    Has CLR image header, track-debug-data flag not set
    Timestamp:        Wed Aug 05 11:20:20 2009 (4A794ED4)
    CheckSum:         000E07C2
    ImageSize:        000DC000
    File version:
    Product version:
    File flags:       0 (Mask 3F)
    File OS:          4 Unknown Win32
    File type:        2.0 Dll
    File date:        00000000.00000000
    Translations:     0000.04b0
    CompanyName:      Devart
    ProductName:      dotConnect for Oracle
    InternalName:     Devart.Data.Oracle.dll
    OriginalFilename: Devart.Data.Oracle.dll
    FileDescription:  Devart.Data.Oracle
    LegalCopyright:   Copyright © Devart 2006-2009
    Comments:         Oracle Data Provider

but I've could not stick around for an answer from you so I've now upgraded to the lates devart. yesterday, the problem still existed.

Today, I increased the minimum connection pool to 30, so that isn't the problem.

From ms:
Unfortunately I cannot tell if the problem is directly in the Devart libraries or in the way your code use it, and I cannot dig on this because Microsoft does not own this modules.

Can you please update me on this issue since it is important for us and our client

Edit: I have question the ms if it really is the agent page. all the controls there are also executed on another page that are "heavier". The /agent/Default.aspx he is reffering to is a pretty simple page and I can't find anything out of the ordinary.
Posts: 31
Joined: Thu 30 Apr 2009 07:59

Postby AndreyR » Tue 03 Nov 2009 15:23

We have made some performance imporovements in the latest Beta build.
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Return to LinqConnect (LINQ to SQL support)