Sharepoint学习笔记—习题系列--70-576习题解析 -(Q102-Q104)
Question 102
You are designing a Windows application that accesses information stored on a SharePoint 2010 intranet site. The application displays employee information in a data grid sourced from a list on the Human Resources site. To filter and manipulate the employee details list, the design includes a class to cache the data that is accessed. The class keeps the SPWeb object open, but only retrieves data that is not already cached. You need to ensure proper memory utilization and resource management for the application. Which approach should you recommend?
A. Implement the class with the IDisposable interface and allow the .NET Framework garbage collector to automatically manage the SPWeb object disposal.
B. Implement the class with the IDisposable interface and explicitly dispose of the SharePoint SPWeb object when you are finished using it.
C. Implement the class as a fully managed .Net Framework object and allow the .NET Framework garbage collector to automatically manage the SPWeb object disposal.
D. Implement the class as a fully managed .Net Framework object and explicitly manage the SPWeb object using the ISPerformanceMonitor interface.
解析:
你开发了一个Windows应用程序去获取存储在Sharepoint 站点列表中的数据,此列表存储了公司员工信息,你的Windows应用程序将会在一个Data Grid控件中显示这些员工信息,为了便于对这些信息进行过滤和处理,你使用了一个类去缓存这些信息, 此类让SPWeb对象保持打开, 当Windows应用程序想查询某些数据,而这些数据在此缓存中找不到时才去访问Sharepoint站点列表资源,你需要确保内存的合理使用和应用程序对资源的合理管理。
本题涉及Sharepoint对象的创建与内存回收,我们知道,一些 SharePoint Foundation 对象(主要是 SPSite 类和 SPWeb 类对象)被创建为托管对象。但是,这些对象使用非托管代码和内存来执行其大多数工作。对象的托管部件比非托管部件小得多。因为较小的托管部件不会给垃圾收集器施加内存压力,所以垃圾收集器不会及时从内存中释放对象。如果对象使用大量非托管内存,则可能导致前面描述的某些异常行为。在 SharePoint Foundation 中处理 IDisposable 对象的调用应用程序在使用完这些对象后必须释放它们。不应该依赖垃圾收集器从内存中自动释放对象。所以,只有选项B符合要求。
选项A,依赖于垃圾收集器从内存中自动释放对象,所以不对。
选项C.D,都是创建完全的托管对象,而SPWeb与SPSite涉及非托管代码,所以也应该被排除。
因此本题答案应该选 B
参考
http://msdn.microsoft.com/en-au/library/ee557362(v=office.14).aspx
http://blogs.msdn.com/b/rogerla/archive/2009/01/14/try-finally-using-sharepoint-dispose.aspx
Question 103
You are asked to analyze a SharePoint 2010 system that is experiencing performance problems, especially under heavy loads. The system contains multiple custom Web applications and third-party Web Parts. The performance problems are exhibiting the following symptoms:
.The application pool recycles frequently.
.The system experiences slow client response times.
.The system experiences excessive page faults.
You need to identify a possible source of these performance issues and suggest a way to verify your analysis. What should you do?
A. Propose that the custom code in the third-party application is not disposing of its objects properly, and verify the theory by checking the Unified Logging Service (ULS) logs for entries related to the SPRequest object.
B. Propose that the paging file size is too large, and verify the theory by using the System Monitor to see if the % Usage counter for the paging file is 50% or less.
C. Propose that the application pool recycle setting should be changed to recycle less frequently and verify the theory by retesting the system to verify improved performance.
D. Propose that the application be moved to a server with a faster disk system that supports fault tolerance and retest the system to verify improved performance.
解析:
某个Sharepoint系统出现了运行效率问题,尤其是加载大量数据时就会显得很慢。此Sharepoint包含了若干用户开发的Web应用程序和第三方的Web Part控件,并且在运行时有如下现象:
现象1. 应用程序池频繁的被回收
现象2. 客户端运行反应很慢
现象3. 过多的页面报错
针对上述情况,你需要分析并找出解决办法。
从上述情况描述也符合Sharepiont内存泄露的情形,如果看了Question101,你会很容易定位到选项A为本题的正解。
选项B.设置Page File Size,它是虚拟内存的组成,对它的调整可以影响基于.net架构程序的运行效率。但此参数与本题所描述的应用程序池的运行问题毫无关系。
选项C.设置应用程序池回收频率不足以造成现象2与3的情况,所以排除。
选项D.在较慢的硬盘上运行不足以造成过多的页面报错以及应用程序池频率被回收的情况,所以排除。
因此本题答案应该选 A
参考
http://msdn.microsoft.com/zh-cn/library/ee557362(v=office.14).aspx
http://msdn.microsoft.com/zh-cn/library/ff647813.aspx
http://msdn.microsoft.com/zh-cn/library/aa720473(v=vs.71).aspx
Question 104
You are designing a SharePoint 2010 application. The code makes numerous calls to SPSite and SPWeb objects.The system and application performance is poor in the test environment. There is also a high level of memory use for IIS worker processes. You need to ensure that the application performance and high memory use issues are addressed. Which approach should you recommend?
A. Use the Resource Throttling settings in Central Administration to increase site resource thresholds.
B. Use the SPSite and SPWeb SharePoint 2010 Power Shell cmdlets.
C. Ensure that the Dispose method of SPSite and SPWeb is called throughout the code.
D. Ensure that the Close method of SPSite and SPWeb is called throughout the code.
解析:
你设计一个Sharepoint应用程序,在开发代码中多次调用了SPSite和SPWeb对象。当在开发环境中测试程序时发现它的运行效率很慢,而且你发现IIS工作进程对内存的占用率很高。你需要找出造成这种现象的具体原因。
如果看了Question101,这道题也很容易定位到选项C。
你可能对选项D存有疑问,为什么不能Close呢?我们知道,Dispose与Close都可以用于释放内存,但Close方法只能用在你先自行创建了SPSite对象,然后再去释放它。如果你是引用(Reference)了一个SPSite对象,你就不能通过Close方法去释放它。
所以我们通常推荐使用Dispose方法来代替Close方法,因为在Dispose方法中最终还是调用了Close方法,但它是通过IDisposable接口来实现的,所以.NET Framework的垃圾回收机制会调用 Dispose方法来释放与此对象相关的内存。
至于选项A是用来限制返回过多结果集以防止对Sharepoint系统效率造成冲击(如规定,List只能返回2500条记录)。它与内存的泄露无关。所以排除。
选项B则更与本题描述无关了,使用Power Shell命令行工具来使用SPSite与SPWeb对象与本应用程序对SPSite和SPWeb对象的使用并由此造成的内存泄露毫无关系,所以也被排除。
因此本题答案应该选 C
参考
http://msdn.microsoft.com/en-au/library/ee557362(v=office.14).aspx
http://jerryyasir.wordpress.com/2009/11/22/resource-throttling-in-sharepoint-2010/