Wednesday, October 2, 2013

Sandbox fail due to ProcessCPUCycles

If your sandboxed code is breaking due to the process cpu cycles, you will need to do 2 things:

1) Optimization

  • Try to reduce unneeded operations.
  • Try to reduce the amount of data requested/transmitted.
  • Optimize CRUD operations.
  • Follow the good practices.



2) Increase the ProcessCPUCycles value. My suggestion is to double the original value as starting point. Keep in mind that the ProcessCPUCycles may differ between environments, so if you have a pre-production, maybe you will need to set different values in production.

This is the PS code that you will need to run.

$spCodeService = [Microsoft.SharePoint.Administration.SPUserCodeService]::Local
$cycles = $spCodeService.ResourceMeasures["ProcessCPUCycles"]
$cycles.AbsoluteLimit = 2000000000000 # VALUE
$cycles.Update()



Regards.

Sandbox too busy........

To resolve this, you should increase the default values. You will need to apply changes increasing 1 by 1... there's not a reliable way to know what are the exact values.
Execution Tiers Properties:
An execution tier is represented by the SPUserCodeExecutionTier class. Each execution tier is distinguished from the other tiers by four properties:

    ·         MaximumWorkerProcesses: This property represents the maximum number of sandboxed worker processes that can run in the tier. The default is 1. Setting this property to more than 1 causes an additional sandboxed worker process to be created (on the server that is handling the request) in the following circumstances: No existing sandboxed worker process in the tier has an application domain that is assigned to thesandboxed solution, and all existing sandboxed worker processes in the tier have reached their maximum level of application domains.
    ·         MaximumConnectionsPerProcess: This property represents the maximum number of allowed connections from a Microsoft ASP.NET worker process (w3wp.exe) to a sandboxed worker process in the tier. The default is 1.


Script to update Tier Information:
You can change the values using this PS Script  from the SharePoint console:

$uc=[Microsoft.SharePoint.Administration.SPUserCodeService]::local
$Tier = $uc.Tiers("")
$Tier.MaximumWorkerProcesses = 5
$Tier.MaximumConnectionsPerProcess = 10
$Tier.Update()


Leandro Araguas