Archive

Archive for the ‘.net 3.5’ Category

xVal

18 January 2009 Steve Leave a comment

xVal is a validation framework for ASP.NET MVC applications. It makes it easy to link up your choice of server-side validation mechanism with your choice of client-side validation library, neatly fitting both into ASP.NET MVC architecture and conventions.

http://xval.codeplex.com/

Categories: .net 3.5, ASP.net 3.5

IronSpeed

26 December 2008 Steve Leave a comment

Iron Speed Designer builds database, forms, and reporting applications for .NET – without hand-coding. Quickly create visually stunning, feature-rich Web 2.0 applications that are easy-to-customize and ready-to-deploy. Iron Speed Designer accelerates development by eliminating routine infrastructure programming, freeing you to focus on our business logic.

Increasingly, developers, CTOs, IT business analysts are turning to a new, breakthrough approach for rapidly developing robust web applications: Application Generation.

Iron Speed Designer can be downloaded from http://www.ironspeed.com

UFrame: goodness of UpdatePanel and IFRAME combined

29 May 2008 Steve Leave a comment

UFrame combines the goodness of UpdatePanel and IFRAME in a cross browser and cross platform solution. It allows a DIV to behave like an IFRAME loading content from any page either static or dynamic. It can load pages having both inline and external Javascript and CSS, just like an IFRAME. But unlike IFRAME, it loads the content within the main document and you can put any number of UFrame on your page without slowing down the browser. It supports ASP.NET postback nicely and you can have DataGrid or any other complex ASP.NET control within a UFrame. UFrame works perfectly with ASP.NET MVC making it an replacement for UpdatePanel. Best of all, UFrame is implemented 100% in Javascript making it a cross platform solution. As a result, you can use UFrame on ASP.NET, PHP, JSP or any other platform.

<div class=”UFrame” id=”UFrame1″ src=”SomePage.aspx?ID=UFrame1″ >
<p>This should get replaced with content from Somepage.aspx</p>
</div>

Introduction to 3-Tier Architecture

30 April 2008 Steve 1 comment

Introduction

As a developer, the .NET framework and Visual Studio present many choices for choosing the right architecture, from placing the data access code directly in the UI through datasets and data source controls, to creating a data access layer that talks to the database, all the way to creating an n-tier architecture approach that consists of multiple layers, and use data-transfer objects to pass data back and forth.

If you’ve ever wondered why you should use layers and what the benefits are, this article is for you. This article delves into the use of layers and how they can benefit any application.

What is a Layer?

A layer is a reusable portion of code that performs a specific function. In the .NET environment, a layer is usually setup as a project that represents this specific function. This specific layer is in charge of working with other layers to perform some specific goal. In an application where the presentation layer needs to extract information from a backend database, the presentation would utilize a series of layers to retrieve the data, rather than having the database calls embedded directly within itself. Let’s briefly look at the latter situation first.

Two-Tier Architecture

When the .NET 2.0 framework became available to the world, there were some neat features that allowed the developer to connect the framework’s GUI controls directly to the database. This approach is very handy when rapidly developing applications. However, it’s not always favorable to embed all of the business logic and data access code directly in the web site, for several reasons:

  • Putting all of the code in the web site (business logic and data access) can make the application harder to maintain and understand.
  • Reusing database queries in the presentation layer often isn’t done, because of the typical data source control setup in the ASP.NET framework.
  • Relying on the data source controls can make debugging more difficult, often due to vague error messages.

So in looking for an alternative, we can separate the data access code and business logic into separate “layers”, which we’ll discuss next.

The Data Layer

The key component to most applications is the data. The data has to be served to the presentation layer somehow. The data layer is a separate component (often setup as a separate single or group of projects in a .NET solution), whose sole purpose is to serve up the data from the database and return it to the caller. Through this approach, data can be logically reused, meaning that a portion of an application reusing the same query can make a call to one data layer method, instead of embedding the query multiple times. This is generally more maintainable.

But the question is how is the data returned? Multiple frameworks employ different techniques, and below is a summary:

  • ADO.NET – Built into the .NET framework, ADO.NET contains a mechanism to query data out of the database and return it to the caller in a connected or disconnected fashion. This is the most common approach to working with data, because it’s already readily available. See more at: http://en.wikipedia.org/wiki/ADO.NET.
  • Table Adapters/Strongly-Typed Datasets – Strongly-typed datasets and table adapters provide a similar means to querying the data through ADO.NET, but add strong-typing features, meaning custom objects are generated for you to work with. See more here.
  • Enterprise Library – Enterprise library Data Access Application Block provides a flexible way to connect to databases of multiple types, without having to know anything about that database, through an abstract approach. See more at: http://msdn2.microsoft.com/en-us/magazine/cc188705.aspx (read part one first).
  • LINQ-to-SQL – LINQ to SQL is an ORM tool that uses a DataContext object as the central point to query data from the database. See more here. (read parts one through eight first).
  • Auto-Generated Code – Tools like CodeSmith Studio automatically generate the code for you based upon a database schema. Simply writing a script to output the code you want to use and the backend is generated in a short amount of time. See more at: http://community.codesmithtools.c om/blogs/tutorials/archive/2006/02/13/nettiers.aspx.

Most (if not all) options above take advantage of the CRUD (create, read, update, or delete) operations that databases support, so all of that is available as shown above. There are plenty of resources online to help you get started. To see an overview of some of the options, please read this.

Business Layer

Though a web site could talk to the data access layer directly, it usually goes through another layer called the business layer. The business layer is vital in that it validates the input conditions before calling a method from the data layer. This ensures the data input is correct before proceeding, and can often ensure that the outputs are correct as well. This validation of input is called business rules, meaning the rules that the business layer uses to make “judgments” about the data.

However, business rules don’t only apply to data validation; these rules apply to any calculations or any other action that takes place in the business layer. Normally, it’s best to put as much logic as possible in the business layer, which makes this logic reusable across applications.

One of the best reasons for reusing logic is that applications that start off small usually grow in functionality. For instance, a company begins to develop a web site, and as they realize their business needs, they later decide to add a smart client application and windows service to supplement the web site. The business layer helps move logic to a central layer for “maximum reusability.”

Presentation Layer

The ASP.NET web site or windows forms application (the UI for the project) is called the presentation layer. The presentation layer is the most important layer simply because it’s the one that everyone sees and uses. Even with a well structured business and data layer, if the presentation layer is designed poorly, this gives the users a poor view of the system.

It’s best to remove as much business logic out of the UI and into the business layer. This usually involves more code, but in my mind, the excess time (which ranges from minimal to moderate, depending on the size of the application) pays off in the end.

However, a well-architected system leaves another question: how do you display it in an ASP.NET or windows application? This can be more of a problem in ASP.NET, as the controls are more limited to the type of inputs they can receive. If you use certain architectures, like passing datasets from the data to the presentation layer, this isn’t as much of a challenge; however, the challenge can come with business objects that support drill-through business object references.

Why Separating Logic Is Useful

You may wonder why it is important to move as much logic outside the presentation layer and into the business layer. The biggest reason is reuse: logic placed in a business layer increases the reusability of an application. As applications grow, applications often grow into other realms. Applications may start out as a web application, but some of the functionality may later be moved to a smart client application. Portions of an application may be split between a web site and a web or windows service that runs on a server. In addition, keeping logic helps aid in developing a good design (sometimes code can get sloppier in the UI).

However, there are some caveats to this: it takes a little longer to develop applications when most of the logic resides in the business layer. The reason is this often involves creating several sets of objects (data layer and access code, plus business objects) rather than embedding it in the application. The extra time that it takes to do this can be a turnoff for some managers and project leads, especially because it often requires you to be knowledgeable about object-oriented programming, more than most people are comfortable with.

Although embedding code in the UI is easier, in most cases I don’t believe it’s the best approach. A layered approach is often a better approach because it pays dividends down the road. This is because as more and more code is developed, the following happens:

  • Code is copied and pasted frequently, or code is reused in classes that could easily be moved to a business layer.
  • Code that is very similar is often copied and pasted with slight modification, making duplication harder to track down.
  • It’s harder to maintain; even though applications with business objects are larger applications, they usually are structured better.
  • Code is harder to unit test, if unit testing is available at all. Web applications and windows forms projects are hard to use unit testing with.

A good architecture is often harder to implement, but is easier to maintain because it often reduces the volume of code. This means that hours spent supporting an application are reduced.

Distributed Applications

Using a separation of layers can aid in development of distributed applications. Because the code is broken up into layers, a layer that facilitates the use of remoting or web services can be added to the project, with a minimal amount of work.

Development Techniques

When developing a business object architecture, it’s good to know about the many design patterns that are out there. There are many websites, blogs, and books related to the subject of design patterns. One of the more well-known books on the subject is titled “Design Patterns,” whom the authors are often referred to as the Gang of Four.

Another useful development technique is called Refactoring, or improving the quality of your code by making small changes to the way it works. This involves moving code into a method, or moving a method from one object to another, in a systematic, logical way. Martin Fowler has written a great book on this subject, called “Refactoring, Improving the Design of Existing Code.” There are plenty of books on the subject; this one is the source that helped me to understand refactoring the most.

There are also tools on the market that can help you refactor in a faster way. One of those tools is Resharper by Jet Brains, which looks for a lot of code patterns and refactors them in a way that is useful. Some of the other refactoring tools that I heard about are Refactor Pro by DevExpress (free for VB.NET and ASP.NET), Visual Assist X by Whole Tomato Software, and Just Code by OmniCore.

PowerCommands for Visual Studio 2008

14 March 2008 Steve Leave a comment

Collapse Projects
This command collapses a project or projects in the Solution Explorer starting from the root selected node. Collapsing a project can increase the readability of the solution. This command can be executed from three different places: solution, solution folders and project nodes respectively.

Copy Class
This command copies a selected class entire content to the clipboard, renaming the class. This command is normally followed by a Paste Class command, which renames the class to avoid a compilation error. It can be executed from a single project item or a project item with dependent sub items.

Paste Class
This command pastes a class entire content from the clipboard, renaming the class to avoid a compilation error. This command is normally preceded by a Copy Class command. It can be executed from a project or folder node.

Copy References
This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes.

Paste References
This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node.

Copy As Project Reference
This command copies a project as a project reference to the clipboard. It can be executed from a project node.

Edit Project File
This command opens the MSBuild project file for a selected project inside Visual Studio. It combines the existing Unload Project and Edit Project commands.

Open Containing Folder
This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node

Open Command Prompt
This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively.

Unload Projects
This command unloads all projects in a solution. This can be useful in MSBuild scenarios when multiple projects are being edited. This command can be executed from the solution node.

Reload Projects
This command reloads all unloaded projects in a solution. It can be executed from the solution node.

Remove and Sort Usings
This command removes and sort using statements for all classes given a project. It is useful, for example, in removing or organizing the using statements generated by a wizard. This command can be executed from a solution node or a single project node.
Note: The Remove and Sort Usings feature is only available for C# projects since the C# editor implements this feature as a command in the C# editor (which this command calls for each .cs file in the project).

Extract Constant
This command creates a constant definition statement for a selected text. Extracting a constant effectively names a literal value, which can improve readability. This command can be executed from the code editor by right-clicking selected text.

Clear Recent File List
This command clears the Visual Studio recent file list. The Clear Recent File List command brings up a Clear File dialog which allows any or all recent files to be selected.

Clear Recent Project List
This command clears the Visual Studio recent project list. The Clear Recent Project List command brings up a Clear File dialog which allows any or all recent projects to be selected.

Transform Templates
This command executes a custom tool with associated text templates items. It can be executed from a DSL project node or a DSL folder node.

Close All
This command closes all documents. It can be executed from a document tab.

Difference between ASP.NET Server Controls and HTML Server Controls

25 January 2008 Steve Leave a comment

Advantages:

1. ASP .NET Server Controls can detect the target browser’s capabilities and render themselves accordingly. No issues for compatibility issues of Browsers i.e page that might be used by both HTML 3.2 and HTML 4.0 browsers code is written in the Server Controls.

2. Newer set of controls that can be used in the same manner as any HTML control like Calender controls. Without any need of Activex Control without bringing up issues of Browser compatibility).

3. Processing would be done at the server side. In built functionality to check for few values(with Validation controls) so no need to choose between scripting language which would be incompatible with few browsers.

4. ASP .NET Server Controls have an object model different from the traditional HTML and even provide a set of properties and methods that can change the outlook and behavior of the controls.

5. ASP .NET Server Controls have higher level of abstraction. An output of an ASP .NET server control can be the result of many HTML tags that combine together to produce that control and its events. Example Gridview or Form control.

Disadvantages:

1. The control of the code is inbuilt with the web server controls so you have no much of direct control on these controls

HTML Server Controls

Advantages:

1. The HTML Server Controls follow the HTML-centric object model. Model similar to HTML

2. Here the controls can be made to interact with Client side scripting. Processing would be done at client as well as server depending on your code.

5. A HTML Server Control has similar abstraction with its corresponding HTML tag and offers no abstraction.

Disadvantages:

1. You would need to code for the browser compatibility.

2. The HTML Server Controls have no mechanism of identifying the capabilities of the client browser accessing the current page.

about value and reference type

3 January 2008 Steve 1 comment

In value type based variables holds memory on stack and hold fixed space for example integer in dot net hold 4 bytes.

In reference type based variables holds memory at managed heap. Reference type variables hold dynamic space. The space hold by reference type can be vary.

When reference is to assign to variable. Only reference is stored in variable. Where this reference is refer actual memory is stored in heap where actual value or data is placed.

Stack is small area of memory where fixed no of space is reserved . for example integer , double always contain same area of memory. So they placed in stack.

While heap is dynamic memory where variable for example string can hold 2 bytes or it contain all available of physical memory

Performance Comparison of Windows Communication Foundation (WCF) with Existing Distributed Communication Technologies

26 December 2007 Steve 1 comment

Windows Communication Foundation (WCF) is a distributed communication technology that ships as part of the .NET Framework 3.0. This article concentrates on comparing the performance of WCF with existing .NET distributed communication technologies. A prerequisite for this article is sufficient understanding of WCF. For an architectural overview of WCF please read “Windows Communication Foundation Architecture Overview” and to learn how to build services using WCF standard bindings please read “Introduction to Building Windows Communication Foundation Services” at http://msdn.microsoft.com/en-us/library/.

Goals

The goal of this article is to provide performance comparisons between WCF and other existing .NET distributed communication technologies. These technologies are:

  • ASP.NET Web Services (ASMX)
  • Web Services Enhancements (WSE)
  • .NET Enterprise Services (ES)
  • .NET Remoting

The scenarios and data presented in this article quantify the underlying cost of the different technologies. This data is useful in understanding the relation between these technologies and can be helpful in planning migrations between the technologies. However, care should be taken in the conclusions drawn from the data presented in this article. The limiting performance factor in a well-designed Service Oriented Architecture (SOA) solution is most likely the service implementation itself and not the cost of the underlying communication technology. One must measure each application to determine the performance characteristics of that application. Note that this article does not address performance best practices when using WCF. Rather, it endeavors to provide sufficient information to enable you to make informed performance decisions when you are using an existing .NET distributed communication technologies as a basis.

Comparisons

All data presented in this article was collected using the same hardware configuration: four 2-way client systems were used to drive a server that was configured as a Uni or Quad processor. Two 2 GB cards were employed to guarantee that the network was not the bottleneck for any of the scenarios. See Figure 14 for details of the topology employed.

The number of client processes used on the client systems was sufficient to ensure that the CPU on the server was completely saturated. The data collected and presented reflects the average of the multiple convergent runs and care was taken to make sure all data was highly repeatable and sustainable.

All the comparisons in article are throughput comparisons and as such higher the value achieved, the better it is. In all the graphs, the higher bars reflect better performance.

This article focuses on the server throughput of the .NET distributed communication technologies. This is defined as the number of operations for each second that these technologies can sustain. An operation is a request and reply message with little processing done by the service. As mentioned in the introduction, but reiterated here as it is critically important, it is expected that the business logic will dominate the cost of a service in a well constructed SOA solution. By leaving out business logic processing at the service, only the cost of the messaging infrastructure is measured.

The message payloads used are different based on the comparison scenario and are explained for each comparative technology.

ASP .NET Web Services (ASMX)

In this section the performance of ASP.NET Web services is compared with the performance of WCF. The scenario is request/reply between the client and the service. This is the typical message exchange pattern for both technologies. The request message in this scenario is required to send an integer. The reply message is comprised of an array of 1, 10 or 100 objects, each object being approximately 256 bytes long. The WCF object is an instance of a strongly typed data contract.

The signature of the function used to generate the message payload (objects) at the service is described in the following:

Order[] GetOrders(int NumOrders);
{
            Order[] orders = new Order[numOrders];
            for (int i = 0; i < numOrders; i++)
            {
                Order order = new Order();
                OrderLine[] lines = new OrderLine[2];
                lines[0] = new OrderLine();
                lines[0].ItemID = 1;
                lines[0].Quantity = 10;
                lines[1] = new OrderLine();
                lines[1].ItemID = 2;
                lines[1].Quantity = 5;
                order.orderItems = lines;
                order.CustomerID = 100;
                order.ShippingAddress1 = “012345678901234567890123456789″;
                order.ShippingAddress2 = “012345678901234567890123456789″;
                order.ShippingCity = “0123456789″;
                order.ShippingState = “0123456789012345″;
                order.ShippingZip = “12345-1234″;
                order.ShippingCountry = “United States”;
                order.ShipType = “Courier”;
                order.CreditCardType = “XYZ”;
                order.CreditCardNumber = “0123456789012345″;
                order.CreditCardExpiration = DateTime.UtcNow;
                order.CreditCardName = “01234567890123456789″;
                orders[i] = order;
            }
            return orders;
}

IIS Hosted Interoperable Basic Profile 1.0 Web Service

This section compares the performance of ASMX and WCF while they are hosted in IIS 6.0. In both cases, no security is used. The WCF binding used is the BasicHttpBinding. This standard binding uses HTTP as the transport protocol. The Basic Profile specification can be found at http://www.ws-i.org/Profiles/BasicSecurityProfile-1.0.html. ASP.NET 2.0, part of the .NET Framework 2.0, provides CLR attributes to ensure conformance to the Basic Profile. For WCF the BasicHttpBinding provides the same level of guarantees.

As shown in Figure 1, WCF has improved performance over ASMX. Three different operation signatures (payloads) are shown in the graph. In each case an integer is passed from the client to the server and an array of objects (1, 10 or 100) is passed back to the client. WCF outperforms ASMX by 27%, 31% and 48% for 1, 10 and 100 objects in a message, respectively.

The graph in Figure 2 shows the throughput comparison of WCF and ASMX for the same scenario as Figure 1 but running on a quad processor. The throughput performance of WCF is better than ASMX by 19%, 21% and 36% for 1, 10 and 100 objects in a message, respectively. Note that the software used was not modified between the two configurations and a single service was exposed on the server. Comparing the data in the preceding two charts, the inherent scalability of the technologies can be noticed.

Figure 1

Figure 2

IIS Hosted Interoperable Basic Profile 1.0 Web Service using Transport Security

In this section, the performance of WCF is compared with the performance of ASMX with both operating over HTTPS. WCF uses the BasicHttpBinding for this scenario. Figure 3 shows the performance of WCF is better than ASMX when using transport level security. WCF outperforms ASMX by 16%, 18% and 26% for 1, 10 and 100 objects in a message respectively.

Figure 4 shows that the performance of WCF is better than ASMX by 5%, 12% and 13% for 1, 10 and 100 objects in a message respectively for a quad processor scenario.

Figure 3

Figure 4

Web Services Enhancements (WSE)

In this section, the throughput of WCF is compared with the throughput of Web Services Enhancements. The comparison in this case is with WSE 2.0 but it should be noted that the performance of WSE 2.0 and 3.0 are similar for this payload. The method signatures and payload used for this scenario are identical to that employed in the ASMX scenarios (shown in Section 3.1).

IIS Hosted Interoperable Web Service using WS-Security

In this section, message level security using X. 509 certificates as the security credential is used. The WSHttpBinding is used in WCF, which implements the WS-Security 1.1 specification. The transport protocol used is HTTP and the message exchange pattern remains request/reply.

Figure 5 shows WCF is much more efficient than WSE. The throughput of WCF is nearly 4 times better than WSE. The main reason for this is that WSE uses the System.Xml.XmlDocument class to do message level parsing, thereby loading the full message into memory at once, while WCF uses a streaming System.Xml.XmlReader class that improves the performance significantly.

Figure 6 compares the throughput of WCF and WSE 2.0 for quad processors. These results are similar to the performance gain achieved by WCF over WSE for single processor scenario. WCF is nearly 4 times faster than WSE with full message security.

Figure 5

Figure 5 also illustrates the performance of another mechanism for securing messages in WCF: transport security with message credentials. This configuration combines transport-level security (HTTPS) and message-level credentials (for example, credentials in the SOAP message). To deploy this, WCF (Message Credentials) workload is using the BasicHttpBinding. The chart shows that the single processor scenario performance of WCF (Message Credentials) is better than WCF with WS Security by 129%, 166% and 277% for 1, 10 and 100 messages, respectively. The corresponding numbers for the quad processor scenario for WCF (Message Credentials) are even better and show an improvement of 126%, 156% and 248% for 1, 10 and 100 messages, respectively, over WCF (Message Credentials) for the uni processor scenario.

As can be seen from the chart, transport security with message credentials provides improved performance while still allowing rich message-level credentials. The message-level credentials include timestamp processing, canonicalization and signature processing. The message protection (signature, encryption, replay detection and other protection mechanisms) are still done at the transport byte stream level, below the individual message boundaries. There is a WS-Security header, but that only contains a timestamp, a security token and signature using that security token over the timestamp. Whereas, in the case where WCF uses full WS-Security, the message protection is done as a message-level transformation with signing and encryption done over the XML fragments for the headers and body. Also, the WS-Security header contains all the required security metadata as XML constructs. This extra XML-aware security processing and the larger size of the security header account for the performance difference. You have to consider the tradeoff between performance and security features available for the specific application that you might want to use this WCF setting in.

Figure 6

.NET Enterprise Services (ES)

In this section, the throughput of Enterprise Services (ES) is compared with WCF using two different service operation signatures and payloads. These are referred to as primitive and order messages. The primitive message is of a primitive type and this allows ES to execute its fast serialization path. The order message is a typical scenario that imitates a book order online and is approximately 512 bytes. The request/reply message exchange pattern is used for these comparisons.

The signature of the primitive payload is as follows:

string TransferFunds(int source, int destination, Decimal amount);

Here the service just returns a string “successful” or “failure”.

For the order message the following code service is used:

static public ProductInfo CreateProductInfo(int count)
{
            ProductInfo productInfo = new ProductInfo();

            productInfo.TotalResults = count.ToString();
            productInfo.TotalPages = “1″;
            productInfo.ListName = “Books”;
            productInfo.Details = new Details[count];
            for (int x = 0; x < count; x++)
            {
                productInfo.Details[x] = GetDetail();
            }
            return productInfo;
}

static Details GetDetail()
{
      Details details = new Details();
      details.Url =
“http://www.abcd.com/exec/obidos/ASIN/043935806X/qid=1093918995/sr=k
a-1/ref=pd_ka_1/103-9470301-1623821″;
      details.Asin = “043935806X”;
      details.ProductName = “Any Book Available”;
      details.Catalog = “Books”;
      details.ReleaseDate = “07/01/2003″;
      details.Manufacturer = “Scholastic”;
      details.Distributor = “Scholastic”;
      details.ImageUrlSmall =
“http://images.abcd.com/images/P/043935806X.01._PE60_PI_SZZZZZZZ_.jpg”;
      details.ImageUrlMedium =
“http://images.abcd.com/images/P/043935806X.01._PE60_PI_MZZZZZZZ_.jpg”;
      details.ImageUrlLarge =
“http://images.abcd.com/images/P/043935806X.01._PE60_PI_LMZZZZZZZ_.jpg”;
      details.ListPrice = “29.99″;
      details.OurPrice = “12.00″;
      details.UsedPrice = “3.95″;
      details.Isbn = “043935806X”;
      details.MpaaRating = “”;
      details.EsrbRating = “”;
      details.Availability = “Usually ships within 24 hours”;
      return details;
}

In these scenarios, the WCF service is self hosted and employs the NetTcpBinding.

Note   You can use IIS 7.0, which is shipped with Windows Vista for hosting TCP services. In this case, the performance achieved is slightly less than the self-hosted case.

Self-Hosted Request/Reply TCP Application

This section compares WCF with ES for two payloads previously discussed without any security. Figure 7 shows that sometimes ES is faster while other times WCF is faster. The performance of ES is better by 21% for the primitive message payload when the fast serializer can be used (possibly on a handful of primitive types like integers) but WCF outperforms it by 149% for order message payload.

Figure 8 shows the same benchmark and payload comparison on a quad processor. As WCF scales better than ES, WCF is faster than ES by 7% for primitive message even though ES can utilize its fast serialization path. For the order message, WCF is faster than ES by 104%.

Figure 7

Figure 8

Self-Hosted Secure Request/Reply TCP Application

In this section, the performance of WCF and ES are compared for the same message loads as the previous section (Section 3.3.1) with security enabled. Specifically, transport-level SSL security is employed and ASP.NET Role principle is used for the authorization. Figure 9 shows that the performance of ES on a uni processor is faster than WCF by 24% for the primitive message type while for the order message type, WCF is faster than ES by 69%.

Figure 10 shows that for quad processor, ES is better than WCF by 16% for the primitive message type and for the order message type WCF is faster by 37%.

Figure 9

Figure 10

Secure Transacted Request/Reply TCP Application

In the previous two sections (Sections 3.3.1 and 3.3.2), the work done by the service was doing little more than creating the objects that were returned to the client. In this section, the throughput of WCF is compared with .NET ES when the services that are implemented use a database transaction. Please note that the transaction used is not flowed but is created and utilized within the service. The purpose of this scenario is to demonstrate that any substantial service implementation dominates the cost of the infrastructure independent of the technology used to deploy it. Hence the comparison is done only for the single proc scenario and only for primitive message type.

In Figure 11, WCF performance is compared with the performance of .NET Enterprise Service for a primitive message payload. As expected, the throughput of this scenario is significantly lower than the previous scenario because transactions are being used. Also as expected, the performance of the two technologies is nearly identical with WCF having slightly better performance.

Figure 11

NET Remoting

This section compares the performance of WCF and .NET Remoting when communication is required across processes on the same machine. Three different sized payloads, each an array of bytes are used for this comparison. The following interface illustrates the service operation signature:

public interface IRemoteObject  {         [OperationContract]         byte [] GetRBytes(int NumBytes); }

The size of the message payload returned is determined by the “NumBytes” which for the data below is 128 bytes, 4k and 256k. The NetNamedPipeBinding is employed without any security for this scenario.

Request/Reply Named Pipe Application

The cross-process named pipe is used as the transport protocol along with request/reply as the message exchange protocol. As seen in Figure 12, WCF outperforms .NET Remoting by 29% and 30% for message payloads of 128 bytes and 4k bytes, respectively. As the payload grows in size, the performance of the technologies converge so that for the 256k byte array the performance is nearly identical.

In Figure 13, the corresponding data for quad processors is shown. The throughput of WCF is better by 38%, 18% and 28% for message payloads of 128 bytes, 4k bytes and 256k bytes, respectively.

Figure 12

Figure 13

When migrating distributed applications written with ASP.NET Web Services, WSE, .NET Enterprise Services and .NET Remoting to WCF, the performance is at least comparable to the other existing Microsoft distributed communication technologies. In most cases, the performance is significantly better for WCF over the other existing technologies. Another important characteristic of WCF is that the throughput performance is inherently scalable from a uni processor to quad processor.

To summarize the results, WCF is 25%—50% faster than ASP.NET Web Services, and approximately 25% faster than .NET Remoting. Comparison with .NET Enterprise Service is load dependant, as in one case WCF is nearly 100% faster but in another scenario it is nearly 25% slower. For WSE 2.0/3.0 implementations, migrating them to WCF will obviously provide the most significant performance gains of almost 4x.

Performance Test Machine Configuration

Figure 14

Figure 14 shows the machine configuration used is a single server and four client machines connected over two 1 Gbps Ethernet network interface. The server is a quad processor AMD 64 2.2 GHz x86 machine running Windows Server 2003 SP1. Each of the client machines are dual processor AMD 64 2.2GHz x86 machines running the same operating system as the server. The system CPU utilization is maintained at nearly 100%. All the scenarios that required hosting were done using an Internet Information Services (IIS) 6.0 server. For the single processor scenarios, the server is booted as a single processor machine.

Categories: .net 3.5, Technology

The Fastest Way To Compare Two Strings Equality

26 December 2007 Steve 1 comment

We usually use “==” for string comparing operations. But What if the code will work 10 million times. You must use the best comparing way for minimum time consuming.

We often works with strings when writing codes. Sometimes the case requires to control if two strings are equal or not. And then we usually use the “==” operator to control equality.
If (s1 == s2)
But What if the code will work 10 million times. You must use the best comparing way for minimum time consuming. Run the code below and see which one the best.
The “==” operator is the slowest, and the “s1.Equals(s2)” is the fastest. 
Stopwatch sw = new Stopwatch();
string 
s1 “Some text for testing”;
string 
s2 “Some text for testing.”;
sw.Start();
for 
(int 0(i <10000000)i++) {
    
if (s1 == s2) {
        
//  Do something
    
}
}
sw.Stop()
;
Console.WriteLine(“s1=s2 : ” + sw.Elapsed.TotalMilliseconds.ToString());

sw.Reset();
sw.Start();
for 
(int 0(i <10000000)i++) {
    
if (String.Equals(s1, s2)) {
        
//  Do something
    
}
}
sw.Stop()
;
Console.WriteLine(String.Equals(s1, s2) : ” + sw.Elapsed.TotalMilliseconds.ToString());
sw.Reset();

sw.Start();
for 
(int 0(i <10000000)i++) {
    
if (s1.Equals(s2)){
        
//  Do something
    
}
}
sw.Stop()
;
Console.WriteLine(s1.Equals(s2) : ” + sw.Elapsed.TotalMilliseconds.ToString());

The StringBuilder Object Memory Usage – Capacity

26 December 2007 Steve 1 comment

The StringBuilder class provides good performance for string operations with default attributes. And you can accomplish your string operations with in best memory performance adjusting StringBuilder Capcity property.

When you instantiate a new StringBuilder object, it’s capacity becomes 16 characters.

StringBuilder() sb= new StringBuilder();

And when you add some characters more then 16, it’s capacity raises 16, automatically. (32, 48 etc.)

If you are using some text with low amount of characters, you can instantiate a StringBuilder object with a capacity parameter.

StringBuilder() sb= new StringBuilder(6);

So the capacity of the object will become 6, 12, 18 etc. And the memory usage of the object becomes optimum for the case.