Pages

Showing posts with label Programming - Tips and Tricks. Show all posts
Showing posts with label Programming - Tips and Tricks. Show all posts

Sunday, November 17, 2013

SharePoint 2013: Optimize your development Environment

SharePoint 2013 demands more resources – especially more memory. When we need to setup a SharePoint 2013 environment we can optimize resource usage in the development server by provisioning/configuring required services as well as following some other guidelines listed in this post.

 

Search Service Applications

Search Service is EXTREMELY resource hungry. noderunner process (Search Service process for crawling/indexing) is widely known for it’s resources usage footprint. In case you don’t need search service in your development server, you can delete the service application or at least stop the service. If you need to use the search service from time to time, you can keep the search service application running but stop the search service. However, if you try to stop the search service from windows service, you will find the service will be started again by SharePoint. The correct way to stopping service is from Central admin as shown below:

image

 

If you need the search service components (crawling/indexing) on development server, you can reduce the performance level by running the following command in SharePoint PowerShell. More information available at http://technet.microsoft.com/en-us/library/ff608126.aspx.

Set-SPEnterpriseSearchService -PerformanceLevel Reduced

You can also control the noderunner memory consumption by changing ‘memoryLimitMegabytes’ in the config file “C:\Program Files\Microsoft Office Servers\15.0\Search\Runtime\1.0\noderunner.exe.config”. Please remember, changing the value to too low might cause the search service to fail.

 

 

Provision Required Service Applications only

If you install SharePoint using Installation wizard, different service applications are installed but you many not need all of these service applications. From Central admin you can delete unnecessary Service applications as well as stop services. As you can see below

 

 

Stop unnecessary Web Application

Even web application running in your development environment will create w3wp process (if a separate application pool is used) or at least use resources. So if you don’t nee a web application for time being, you can stop the web application as well as related application pool from IIS Manager.

 

 

Visual Studio IntelliTrace

If you use Visual Studio debugging in the server and your Visual Studio supports IntelliTrace and the feature is enabled, you can disable the option. That might improve your debugging experience. More information on how to enable/disable the feature can be found at: http://msdn.microsoft.com/en-us/library/dd264948(v=vs.100).aspx

 

Multiple Disk Drive

If you have configured multi-server farm, you can keep some servers in another disk drive. For example, I’ve a multi-server (4 servers – AD, SQL, WFE and App) farm and I’ve kept two servers in my external USB3 supported external drive. So rather than four server vying for the same disk access, two are vying for internal disk access and other two are vying for external disk.

Even if are running a single server farm, you can use an external SSD drive (or USB3) for better I/O throughput. Especially if you can move your database files in an external drive, you will experience much better performance.

 

Tracing Service

SharePoint uses a windows Service ‘SharePoint Tracing Service’ for logging. sometimes, like during deployment, you will find the log file is growing few hundreds megabytes in short time. So tracing service might take a bit role in performance. If you don’t need the log file for a period of time, you can disable the windows service. During development I usually disable the service and when I need to see the log file, I enable the service.

Tuesday, December 29, 2009

Use Visual Studio Conditional Compilation to manage development environment diversities

Large enterprise solutions may have different parts and each part may need different development/deployment environment. For example a project may have a part to work with third party web service. Now not all developers are interested for codes works with that web service. For faster/smooth development, developers who are not working with that web service may not want to interact with the service. Every time a developer run/debug the code and if the web service is invoked (which may kill time) then it’ll be annoying for developers who don’t work with that part of the code. So how we can fix this problem where people who are working with web service will invoke web service whereas people who are not working with web service will not invoke web service?

 

1. Create a new Configuration

In Visual Studio(VS) you can create custom configuration beyond DEBUG and RELEASE. Right click on the Solution in VS and click Configuration. In this configuration window select ‘New’ in the dropdown under ‘Active Solution Configuration:’. You’ll be prompted with the following window.

image 

Figure 1: Create Custom Configuration from Configuration Manager.

Now enter a meaningful name for the configuration and select the base configuration (DEBUG or RELEASE).

 

2. Create Conditional Compilation Symbol for the configuration

Make sure that the new configuration is selected for the solution. To make sure this open ‘Configuration Manager’ by right clicking on the solution. The following figure shows that the custom configuration is selected for the solution.

image

Figure 2: Select Custom Configuration from Configuration Manager

Now open the properties window of the project you want to work differently for this configuration. Select Build tab and enter a conditional symbol name (WSDEBUG_SYMBOL in the figure) as shown below:

image

Figure 3: Create a conditional symbol for custom configuration

FYI, here the conditional compilation symbol will be associated with configuration name. So this conditional symbol will be active only when you select that particular configuration under which the symbol created.

 

3. Use Conditional Compilation Symbol in code

Since conditional compilation symbol is associated with configuration name, whenever you’ll select any configuration any project/solution, any symbols defined in that project/solution will be active. Now code block which needs to be conditional compiled can be put in a condition below:

#if WSDEBUG_SYMBOL
     Console.WriteLine("This is WSDEBUG");
#else
     Console.WriteLine("This is not WSDEBUG");
#endif

In the above code block, if you select any configuration that has any conditional compilation symbol named “WSDEBUG_SYMBOL” defined then first condition will be executed either else condition will be executed. Now you can write your code inside custom compilation section. So all you need to do is to change your configuration from DEBUG to your custom one (as like WSDEBUG).

 

Conclusion

One nice thing about VS is that it doesn’t keep track of the project’s configuration, user selected for a project/solution, inside project or solution. Rather it keeps this information in a file named like “yourproject.csproj.FileListAbsolute.txt”. So as long as you don’t keep this file in source control,different user’s configuration for project/solution will be kept locally. So if developer dev1 change project or solution’s configuration to WSDEBUG, then no other developer’s local settings will be affected.

So the solution is now that if you need different settings than others then create your own configuration and conditional compilation symbol. Then use that symbol for conditional compiling. Since your project/solution preference is kept locally, every time you’ll open the solution you’ll find your custom configuration selected whereas other developers will be using their own configurations. So the final answer to the question I had asked at the top of the post is “developers who wants to work with web service may select their custom configuration to use whereas developers who don’t want to work with web service may use default DEBUG configuration”

Thursday, December 24, 2009

Path.Combine like support for URLs

.NET framework has Path.Combine for combining two paths into one. This is great one as we don’t need to care about if first path ends with slash (/) or not. Today I needed functionality to combine two Uri into one. I needed to combine URLs in different places so having a unified solution would be better. At first I searched for any combine method in Uri. No Luck! Then after googling I have come to the following code snippet.

        public static string CombineUrls(string absoluteUrl,string 
             relativeUrl)
        {
            Uri absoluteUri=new Uri(absoluteUrl);
            return new Uri(absoluteUri, relativeUrl).ToString();
        }

Here the absolute Url is converted to an Uri object. Then another new Uri object is created combining this absolute Uri and relative Url.