Presentation is loading. Please wait.

Presentation is loading. Please wait.

Philadelphia Area SharePoint User Group www.PhillySharePoint.org Memory Management in SharePoint 2007 Development Matt Vignau RJB Technical Consulting.

Similar presentations


Presentation on theme: "Philadelphia Area SharePoint User Group www.PhillySharePoint.org Memory Management in SharePoint 2007 Development Matt Vignau RJB Technical Consulting."— Presentation transcript:

1 Philadelphia Area SharePoint User Group www.PhillySharePoint.org Memory Management in SharePoint 2007 Development Matt Vignau RJB Technical Consulting www.rjbtech.com matt.vignau@rjbtech.com

2 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Overview In C#.NET development we have the Garbage Collector No more destructors SPSite and SPWeb not always disposed Leaves growing used memory block Leads to problems

3 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Memory Leaks Build with each use of the code SPSite and SPWeb sites have ~2kB size wrappers Object sizes are closer to 1-2 MB One site with 15 webs accessed twice has used around 30 MB of system memory; for *one* user Can bring down entire farms

4 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 1 public void GetNavigationInfo() { SPWeb OurWeb = http://intranet.litwareinc.com; foreach(SPWeb OurWeb in OurWeb.GetSubWebsForCurrentUser()) { //Our Subsite code here }

5 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Memory Danger Signs Does the application pool refresh frequently when under load? –Memory reset threshold 800 megs -1.5 gigs Does the system perform poorly under heavy loads? Does the entire system crash or users receive “Page not available”? Does the system use custom webparts or third party webparts?

6 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 2 public void GetNavigationInfo() { SPWeb OurWeb = http://intranet.litwareinc.com; foreach(SPWeb OurWeb in OurWeb.GetSubWebsForCurrentUser()) { //Our Subsite code here OurWeb.Dispose(); }

7 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 3 pt 1 try { SPSite OurSiteObject; SPWeb OurObject; //our main code body here }

8 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 3 pt 2 catch { //Our exception handling code }

9 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 3 pt 3 finally { if(OurObject != NULL) { OurObject.Dispose(); } if(OurSiteObject != NULL) { OurSiteObject.Dispose(); }

10 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Breakdown Try-catch block allows for exception handling Finally block executes the dispose after the code block is complete to avoid problems No explicit calls to dispose necessary for SPContext initializations

11 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Using statements One of the most efficient means Single block usage with automatic disposal No additional call out to the dispose method is needed Cannot use method outbound transfer of object beyond the using block

12 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 4 using (SPWeb OurWeb = null){ //Our Code Here; }

13 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Caching Saves on memory Improves access time Is not thread-safe –IIS is multi-threaded Best for single-user applications

14 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 5 public void CacheData() { SPListItemCollection oListItems; oListItems = (SPListItemCollection)Cache["ListItemCacheName"]; if(oListItems == null) { oListItems = DoQueryToReturnItems(); Cache.Add("ListItemCacheName", oListItems,..); }

15 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Example 6 public void CacheData() { DataTable oDataTable; SPListItemCollection oListItems; lock(this) { oDataTable = (DataTable)Cache["ListItemCacheName"]; if(oDataTable == null) { oListItems = DoQueryToReturnItems(); oDataTable = oListItems.GetDataTable(); Cache.Add("ListItemCacheName", oDataTable,..); }

16 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Scalability Target scale can impact performance considerations Even with proper dispose, memory can grow Projected concurrent users are a factor in your design

17 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Scale Questions Pt 1 Is the data static, somewhat static (occasionally changes), or dynamic (often changes)? Is the data the same for all users or does it change? (Dependent on user account, department within the company, etc) Is the data easily accessible or does it require a long time to return the data?

18 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Scale Questions Pt 2 Is the data public or does it require a higher level of security? What is the size of the data? Is the SharePoint site on a single server or on a server farm?

19 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Links My Blog: http://blogs.rjbtech.com/MV/ MSDN Best practices: http://msdn2.microsoft.com/en- us/library/aa973248.aspx# Memory Pressure in MOSS: http://blogs.technet.com/stefan_gossner/archive/2007/11 /26/dealing-with-memory-pressure-problems-in-moss- wss.aspx Memory leak checking tool: http://blogs.rjbtech.com/RJB

20 www.PhillySharePoint.org Philadelphia Area SharePoint User Group Questions? Ask away!


Download ppt "Philadelphia Area SharePoint User Group www.PhillySharePoint.org Memory Management in SharePoint 2007 Development Matt Vignau RJB Technical Consulting."

Similar presentations


Ads by Google