Wednesday 21 September 2011

SPUserCodeService and ResourceMeasures

ResourceMeasures Gets the collection of measures for regulating the resource usage of services in the Microsoft SharePoint Foundation farm.

With this class you can have full control over the measures. That means you can disable them or just adjust the value you think are more appropriate for your farm. I will say it is dangerous to play around with these properties because it gives you a really powerful weapon.

For the time being these are the measures we can access, disable/enable or just assign a particular value:

  1. AbnormalProcessTerminationCount
  2. CPUExecutionTime
  3. CriticalExceptionCount
  4. InvocationCount
  5. PercentProcessorTime
  6. ProcessCPUCycles
  7. ProcessHandleCount
  8. ProcessIOBytes
  9. ProcessThreadCount
  10. ProcessVirtualBytes
  11. SharePointDatabaseQueryCount
  12. SharePointDatabaseQueryTime
  13. UnhandledExceptionCount
  14. UnresponsiveprocessCount

I am going to show you two simple snippets two show you how these works.

- This example disables CriticalExceptionCount:

Microsoft.SharePoint.Administration.SPUserCodeService _spUserCode = Microsoft.SharePoint.Administration.SPUserCodeService.Local;
_spUserCode.ResourceMeasures["CriticalExceptionCount"].ResourcesPerPoint = 0;
_spUserCode.Update();


- This example assigns a limit of 50 to the CPUExecutionTime:

Microsoft.SharePoint.Administration.SPUserCodeService _spUserCode = Microsoft.SharePoint.Administration.SPUserCodeService.Local;
_spUserCode.ResourceMeasures["CPUExecutionTime"].AbsoluteLimit = 40;
_spUserCode.Update();


Conclusion: Before playing around with these values, I highly recommend to back up the server. That is my conclusion… so good luck!

No comments: