Saturday, August 6, 2011

Sandbox Solutions and Load Balancing schemes

Sandbox solution or User Solution as Microsoft Definition "A sandbox is a restricted execution environment that enables programs to access only certain resources and keeps problems that occur in the sandbox from affecting the rest of the server environment".

So Sandbox solution more secure,safer and the user who deploy the solutions has limitation to server resources for example you can't deploy a files to Servers like Visual Web Part, You can't execute SPWebApplication , SPSecurity , Reflection code (Connected Web Parts uses Reflection so you can't Implemented also)… and these solution deployed or stored at Site collection level .

Administrator Can monitors these solutions and gives them specific resources or can block these solutions.
These solutions run under specific process located under 14\UserCode\ folder not under w3c.exe process.


In this article I will explain the Sandbox solution and Load Balancing schemes which affect the execution of code in the servers.

If you go to Central Administration >> System Settings >> Manage user solutions
You will find the below options:

The first option means:
If you have two frontend servers with Microsoft Load balance configuration (NLB) and the user request a page which run sandbox solution code; if the NLB routed the request to one these server the code run in the same server which received the request so in this case all frontend servers must started Microsoft SharePoint Foundation Sandboxed code Service and if in case this service not started on the server which received the request; the code will not run and the user will get an error.

Second option:

If in case the service started in Frontend 1 server only and the NLB routed the request to Frontend 2; here the Sandbox process will route this request again to Frontend 1 and then run this code and the user will get the Response (this is known as solution affinity).


So for example I created a web part (not visual web part) with basic code like below:
public override void RenderControl(HtmlTextWriter writer)
        {
            base.RenderControl(writer);

            writer.Write("Hello Fadi From Sandbox Solution");
        }


And then I uploaded this solution to Site Settings >> Solutions and then activated and then I add this web part to a test page.



Now I stopped Frontend 1 from the NLB and then I requested the page which has sandbox solution code; sandbox process route the request to Frontend 1 to run the code and get the Response.

Note: try the first option with this an example and you will get an error because when the NLB route the request to Frontend 2 which the service in this server not started so the code will not run.
so the benifits with second option as microsoft wrote : "The more you isolate sandboxed solutions, the better your ability to protect the main part of your SharePoint Server 2010 site from code that might consume too many resources. You can increase isolation by using remote load balancing and by running the sandboxed solution service only on specific servers."

1 comment:

إسماعيل عنجريني (Ismaeel Enjreny) said...

Thank you Fadi, but can we did the same thing with Farm Solution, is it available to use NLB to execute the Farm Solution?