SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 
        
Home       Members    Calendar    Who's On


««12345»»»

Memory pressure when calling a C# assembly Expand / Collapse
Author
Message
Posted Friday, September 11, 2009 6:51 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 4:15 AM
Points: 2,069, Visits: 2,040
Last thing (can't believe I didn't mention this before):

If it is VAS pressure/fragmentation (it almost always is, especially if you can last for 3 weeks before a reboot), use the VASummary view in this awesome article by Slava Oks.

I used to use it on our old 32-bit servers - I recorded the results every five minutes and knocked up a very quick SSRS report on the log table.

This is a great way to show total VAS space and the largest available contiguous VAS fragment over time. The shape of the graph can help you isolate the cause, or at least predict when the next reboot would be required.

In one case, it turned out to be the CLR being loaded (though disabled!) because we were calling sp_browsereplcmds which calls a system CLR function. The 100MB VAS required by CLR killed a production server more than once...



The quality of the answers is directly proportional to the quality of the question.
Post #786310
Posted Friday, September 11, 2009 9:20 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 16, 2009 3:25 PM
Points: 1,148, Visits: 1,973
Paul's last post stirred up my memory too!

Here is some code (probably similar to the one Paul just posted) that returns all VAS fragments (sorted by size, at bottom are the largest ones).

Taken from http://social.msdn.microsoft.com/forums/en-US/sqlnetfx/thread/cc1b3e43-0db8-4e75-b5ab-bc2a4c93b12b/

-- from http://social.msdn.microsoft.com/forums/en-US/sqlnetfx/thread/cc1b3e43-0db8-4e75-b5ab-bc2a4c93b12b/
-- MemToLeave values for instance of SQL Server:
-- [Total avail mem, KB] : total memory assigned to MemToLeave
-- [Max free size, KB] : free memory available to MemToLeave
;WITH VAS_Summary AS
(
SELECT
[Size] = VAS_Dump.Size,
Reserved = SUM(CASE(CONVERT(INT, VAS_Dump.Base)^0) WHEN 0 THEN 0 ELSE 1 END),
Free = SUM(CASE(CONVERT(INT, VAS_Dump.Base)^0) WHEN 0 THEN 1 ELSE 0 END)
FROM
(
SELECT
CONVERT(VARBINARY, SUM(region_size_in_bytes)) [Size],
region_allocation_base_address [Base]
FROM
sys.dm_os_virtual_address_dump
WHERE
region_allocation_base_address <> 0x0
GROUP BY
region_allocation_base_address

UNION

SELECT
CONVERT(VARBINARY, region_size_in_bytes) [Size],
region_allocation_base_address [Base]
FROM
sys.dm_os_virtual_address_dump
WHERE
region_allocation_base_address = 0x0
) AS VAS_Dump
GROUP BY [Size]
)
--Get size of all free mem. areas
--http://www.sqlservercentral.com/Forums/Topic624152-386-2.aspx?Update=1
--
SELECT
CAST(Size AS BIGINT)/1024 AS [Free size, KB]
FROM
VAS_Summary
WHERE
Free <> 0;


Post #786481
Posted Friday, September 11, 2009 9:25 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 4:15 AM
Points: 2,069, Visits: 2,040
Yep. Same code. It's very popular


The quality of the answers is directly proportional to the quality of the question.
Post #786487
Posted Friday, September 11, 2009 10:37 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 13, 2009 11:25 AM
Points: 16, Visits: 86
I agree. I have been running that code. The issue just happened again. During this issue the results of the above query was

Total avail mem, KB Max free size, KB
51716 8704

We were forced to restart our sql server service. After the restart the values were:

Total avail mem, KB Max free size, KB
154256 45632

We are now functional again. It took 11 days for the error to reappear. This is a type of memory fragmentation , yes?

Also during this issue I was not able to run a simple function that calls the C# assembly. It errored with the following error:

Msg 10314, Level 16, State 11, Line 1
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65537. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error:
System.IO.FileNotFoundException: Could not load file or assembly 'colleague, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException:
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)

It seems that 8074KB should be plenty of memory to run a simple function...
Post #786559
Posted Friday, September 11, 2009 10:48 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 16, 2009 3:25 PM
Points: 1,148, Visits: 1,973
danielmanke (9/11/2009)

It seems that 8074KB should be plenty of memory to run a simple function...


How many times is this function being executed though?
That would contribute to the mem utilization you are seeing.

Also, are you seeing messages in your ERRORLOG to the effect of "Appdomain being unloaded"?
Here is an interesting link:

http://social.msdn.microsoft.com/Forums/en-US/sqlnetfx/thread/e5ca2988-df87-4ce4-8fb7-b338a81a390e
Post #786567
Posted Friday, September 11, 2009 11:10 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 4:15 AM
Points: 2,069, Visits: 2,040
That is *extreme and soon to be fatal* fragmentation. I used to consider a reboot when we got down below 50MB contiguous.

8MB is not a big block - and who's to say how long it lasted? Remember that SQL Server itself uses the multi-page allocator too.

In addition, if the function required workspace or dependent classes needed to be loaded...well.

Anyway, can we just agree that 8MB contiguous in the entire 2GB user address space is not very much?

If you were on 64-bit, you would have 8TB (7TB on Itanium) of VAS.

Paul



The quality of the answers is directly proportional to the quality of the question.
Post #786582
Posted Friday, September 11, 2009 11:56 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 13, 2009 11:25 AM
Points: 16, Visits: 86
I think we can agree. But as you can see from my query, we are starting at less then 50MB of Max free space, KB. So my only option other then 64 bit servers is to try using the -g switch... say -g512? Will this switch increase the Max free space, KB value?

Daniel
Post #786615
Posted Friday, September 11, 2009 1:34 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:15 PM
Points: 18,300, Visits: 12,321
Jeff Moden (9/8/2009)
I can't help on the problem you're having, Daniel, but I am curious... what does the CLR do?


Heh... you can avoid all this memory problem stuff by avoiding the CLR to begin with. So, let me ask again... "What does the CLR do?"


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #786680
Posted Friday, September 11, 2009 8:37 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 4:15 AM
Points: 2,069, Visits: 2,040
danielmanke (9/11/2009)
I think we can agree. But as you can see from my query, we are starting at less then 50MB of Max free space, KB. So my only option other then 64 bit servers is to try using the -g switch... say -g512? Will this switch increase the Max free space, KB value?
Daniel

Hey Daniel, yes it will (but 512 is a lot - consider -g384 first). Being lazy by not reading back, but I am assuming you have AWE enabled? AWE will let SQL Server manage the buffer pool in a very VAS-efficient way, making higher values for -g more practical.



The quality of the answers is directly proportional to the quality of the question.
Post #786784
Posted Sunday, September 13, 2009 6:30 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, November 13, 2009 11:25 AM
Points: 16, Visits: 86
Yes, AWE is enabled... with about 20GB max server memory

Daniel
Post #786997
« Prev Topic | Next Topic »

««12345»»»

Permissions Expand / Collapse