Wednesday, June 16, 2010

SortedSet vs HashSet


HashSet<T> is very good at add and search operations. Any search operation (Contains, Remove, and similar operations) are O(1). That's great. However, on the minus side, the HashSet<T> is not a sorted collection. Therefore, enumerating the elements in a sorted order forces you to copy the items to a different collection (like a List<T>) and sort the resulting list. You could construct a LINQ query to order the elements, however internally that query will likely use some form of temporary storage to create the sorted sequence. That means every sort will be an expensive operation. Sort is typically an O(n ln n) operation, Also, because the HashSet<T> does not have a sort method, you'll also have increased memory pressure and time cost to copy the elements.

SortedSet is new to .NET 4.0 System.Collections.Generic namespace. SortedSet<T> has different characteristics. The sorted set ensures that the elements in the set are always in sorted order. Every Add operation places the new element in the correct location in the set. That means Add is an O(ln n) operation. The SortedSet<T> must perform a binary search to find the correct location for the new element. The search happens on any of the search actions (Contains, Remove, etc). Those operations also have an O(ln n) performance characteristic. That sounds like the SortedSet<T> is always slower than the HashSet<T>. No one would use it if it was always slower. SortedSet<T> is much faster for iterating the set in sorted order. It's already in the correct order, so the enumeration becomes an O(n) operation.

Conclusion
SortedSet<T> will typically be faster than HashSet<T> when the majority of your operations require enumerating the set in one particular order. If, instead, most of the operations are searching, you'll find better performance using the HashSet<T>. The frequency of insert operations also has an effect on which collection would be better. The more frequently insert operations occur, the more likely HashSet<T> will be faster.

Thursday, February 25, 2010

System.OutOfMemoryException on WCF Web Service

Recently ran into OutOfMemoryException from a .NET 3.0 WCF web service whenever the w3wp.exe reaches ~1.395 GB memory. WCF web service is hosted in IIS 6.0. After poking around, the problem was found...

IIS has limitations and warts when it comes to memory handling, and if your WCF service really must use more than 1.4 GB of memory on the server, then you need to host that WCF service yourself, in a console app, a NT Service, a Winforms app - whichever way to you choose to go.
Quick question though: how is your server going to handle 10 simultaneous requests if handling each request will use up 1.4 GB of memory....

Keep in mind that you don't get access to all memory if you're running in asp.net, it'll only allow you 2gigs with a standard configuration. Maybe you should farm this out to a windows service, or a console app.


See here: "Fact: In a standard setup your worker process always have 2GB Virtual memory available (no matter if you have 1, 2 or 4GB physical memory in the machine)."

http://jesperen.wordpress.com/2007/05/23/understanding-aspnet-memory/

In that case, I am going to check out
WCF streaming which allows you to substantially reduce the size of buffer memory needed on the server. Let me get back to this after I try WCF streaming out.

Tuesday, December 29, 2009

Apply FxCop Rules to Multiple Solutions

It's easy to apply FxCop into the projects with Visual Studio. You don't need to manually change each project settings using the project Properties dialogue. You can just copy and paste the settings to each .csproj file which is the MSBuild file.

The steps to applied the same FxCop rules to the multiple projects at the same time are:

  • Unload the projects in a batch.
  • Edit the csproj files in a batch. This will automatically check the .csproject files out. Past the following lines into the .csproj file in each configuration files.

<PropertyGroup Condition=" '$(Configuration)$(Platform)' == 'DebugAnyCPU' ">

<RunCodeAnalysis>true</RunCodeAnalysis>

<CodeAnalysisRules>-Microsoft.Design#CA1005;-Microsoft.Design#CA1011;-Microsoft.Design#CA1009;-Microsoft.Design#CA1019;-Microsoft.Design#CA1000;-Microsoft.Design#CA1006;-Microsoft.Design#CA1046;-Microsoft.Design#CA1035;-Microsoft.Design#CA1033;-Microsoft.Design#CA1014;-Microsoft.Design#CA1017;-Microsoft.Design#CA1018;-Microsoft.Design#CA1060;-Microsoft.Design#CA1034;-Microsoft.Design#CA1052;-Microsoft.Design#CA1057;-Microsoft.Design#CA1030;-Microsoft.Design#CA1003;-Microsoft.Design#CA1007;-Microsoft.Globalization#CA1301;-Microsoft.Globalization#CA1306;-Microsoft.Globalization#CA1305;-Microsoft.Globalization#CA1300;-Microsoft.Globalization#CA1309;-Microsoft.Interoperability#CA1403;-Microsoft.Interoperability#CA1406;-Microsoft.Interoperability#CA1413;-Microsoft.Interoperability#CA1402;-Microsoft.Interoperability#CA1407;-Microsoft.Interoperability#CA1404;-Microsoft.Interoperability#CA1410;-Microsoft.Interoperability#CA1411;-Microsoft.Interoperability#CA1405;-Microsoft.Interoperability#CA1409;-Microsoft.Interoperability#CA1415;-Microsoft.Interoperability#CA1408;-Microsoft.Interoperability#CA1414;-Microsoft.Interoperability#CA1412;-Microsoft.Interoperability#CA1400;-Microsoft.Interoperability#CA1401;-Microsoft.Mobility#CA1600;-Microsoft.Mobility#CA1601;-Microsoft.Performance#CA1812;-Microsoft.Performance#CA1824;-Microsoft.Portability#CA1901;-Microsoft.Portability#CA1900;-Microsoft.Security#CA2116;-Microsoft.Security#CA2117;-Microsoft.Security#CA2115;-Microsoft.Security#CA2102;-Microsoft.Security#CA2122;-Microsoft.Security#CA2114;-Microsoft.Security#CA2123;-Microsoft.Security#CA2108;-Microsoft.Security#CA2107;-Microsoft.Security#CA2103;-Microsoft.Security#CA2118;-Microsoft.Security#CA2109;-Microsoft.Security#CA2119;-Microsoft.Security#CA2106;-Microsoft.Security#CA2112;-Microsoft.Security#CA2120;-Microsoft.Security#CA2126;-Microsoft.Security#CA2124;-Microsoft.Security#CA2127;-Microsoft.Security#CA2128;-Microsoft.Security#CA2129;-Microsoft.Usage#CA2227;-Microsoft.Usage#CA2212;-Microsoft.Usage#CA2219;-Microsoft.Usage#CA2228;-Microsoft.Usage#CA2240;-Microsoft.Usage#CA2229;-Microsoft.Usage#CA2238;-Microsoft.Usage#CA2239;-Microsoft.Usage#CA2242;-Microsoft.Usage#CA2230</CodeAnalysisRules>

<PropertyGroup>

Load the projects again in a batch.

Undo the .sln file if the solution file has been checked out by visual studio.

Tuesday, December 22, 2009

To-do list in TFS Project Migration

I can think of at least two reasons why project migration is not avoidable in TFS 2008.

  1. You want to rename your project. For complicated reasons, renaming is not supported in TFS. So the only you can achieve this is to create a new project then migrate everything.
  2. You want to change the process template you used in TFS project. Changing the template is not supported in TFS 2008 either.

Migrating the team project, you can easily think of three parts.

  1. Source control code
  2. Work Items
  3. SharePoint Documents

However there are other things you need to consider too.

  1. TFS groups and membership
  2. TFS security settings
  3. TFS queries

Some of these items are manual processes.

  • Like work items migration, you need to use TFS query to get the work items you need, then export to excel then import to the new TFS project.
  • SharePoint Documents.
  • TFS queries
  • TFS security settings.

Some of these items you can accomplish using scripts.

  • Group membership migration. I found one good tool you can utilize to migrate group membership in CodePlex
  • Source code migration. You can simply use TF.EXE to compose a batch file.

Before the migration you should consider to stop TFS SQL server's transaction log jobs. Then migrate. Restart the SQL transaction log job. Re-index the database to achieve the ultimate performance.

Tuesday, October 20, 2009

Manual Remove Visual Studio 2005

I have problem to remove the Visual Studio 2005. It complains about the
vs_setup.msi could not be found in c:\program files\microsoft visual studio
8.

I also tried to remove it from DVD, which was not successful as well.

(1) Rename the Visual Studio directories to something else (ie. add REMOVE
to the folder name)

(2) rename the following Register entry using REGEDIT (use with care!)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0 (ie. change
\8.0 to \8.0REMOVE)

(3) Download the Windows Install Clean Up utility at:
http://support.microsoft.com/default.aspx/kb/290301

Use this software to 'clean up' anything with Visual Studio in the
name.

(4) Reinstall the Visual Studio software


You must install Windows Installer Cleanup Utility - msizap.exe.
http://support.microsoft.com/default.aspx/kb/290301

Friday, October 09, 2009

Team Build Tray

There are many ways to monitor the team builds status. The greatest one I found is the Team Build Tray, which is pretty similar to the CruiseControl one I have used before. So far this tool is the most satisfied one I have used.
URL: http://teambuildtray.codeplex.com/

There are other tools other there in codeplex. But I just don't see how they will be used in a common development environment.

http://buildmonitor.codeplex.com/

is supporting Twitter and USB build light.

http://tfsalert.codeplex.com/

is not useful and I haven't seen any place to set where the TFS is.

Sunday, September 27, 2009

Conference - Houston TechFest 9/26/2009

The conference was held in University of Houston main campus. It was such a great free conference. Highly recommend it to other tech folks in Greater Houston Area. Below are the sessions I have attended to give some ideas to have the complete list, you can go to the following link.

http://houstontechfest.com/

Session 1: Preparing for Your Organization’s SharePoint Future in SharePoint 2010

by Erin O’Connor

  • Ribbon Styled
  • Visio 2010 Added
  • Silverlight
  • BDC changed to two-way BCS
  • Performance Point to bring BI
  • Firefox, Safari and IE compatible. No support IE 6 anymore
  • Offline workspace support
  • Only support 64 bits server
  • SPaaS

Session 2: Microsoft Dynamics xRM by Daniel Hunter

  • xRM 4.0 demo

Birds of a feather – Staying Alive: Social Media Tips for Techies

Session 3: What’s new in C# 4.0

  • Optional Parameters
  • Named Parameters
  • Dynamics (same as object, however it defer the binding in runtime).

Session 4: VSTS/TFS 2010 (Mike Azocar, and Mike Moles)

  • Best improvement: QA, Architecture, and Gated Check-in
  • Branch Visualization
  • Work Item Tracking
  • Work Item Hierarchy (even working in Excel)
  • Track change set across branches
  • Rolling tests, Test impacted test cases (Unit Tests Improvement)
  • QA: Historical Debugging – No repro
  • QA: Test and Lab Manager
  • Built on WPF
  • Catch a bug earlier will save cost by multiple times
  • Build Controller with WF

Session 5: Best practices on Developing and Customizing Web Parts

  • Recommend using built-in web parts such as DataForm and DataView
  • MVP – Model, View, and Presenter

Final Session: Prize Drawing

  • I won a Resharper license worthy of the market value $199.00.

Be A Developer That Uses AI

Developers will not be replaced by AI, they'll be replaced by developers that use AI. Generative AI tools are revolutionizing the way de...