| By Hilton Giesenow | Article Rating: |
|
| May 18, 2004 12:00 AM EDT | Reads: |
16,908 |
Prior to .NET, DCOM existed as Microsoft's solution to remote object access. This technology leveraged the successful COM architecture to provide an infrastructure for remote communication. However, DCOM suffered from a variety of drawbacks and difficulties, and it ultimately led to Microsoft's spirited drive to develop Web services and their associated standards.
Unfortunately, in the pre-.NET age even these could be cumbersome and time consuming to develop, deploy, and access. The Remoting framework that .NET has brought (of which Web services can technically be seen as a subset, but will hereafter be dealt with separately) represents a tremendous leap forward in terms of customizability, availability, development speed, and ease of use for distributed communication.
XML Web Services and .NET Remoting are able to provide a solution to most of what one could ask of an RPC infrastructure. Both technologies are significantly easier to develop with, deploy, and consume than DCOM. Both are also able to tunnel through firewalls by relying upon standard protocols. The essential difference between the two lies in their interoperability: .NET (and Visual Studio.NET in particular) provides a superb environment and toolset for building interoperable, standards-based remote methods in the form of Web services. "Surely," one could ask, "we should always choose this option for developing remote components?"
From an initial architectural point of view, the answer is certainly yes. However, when we analyze the underlying technologies of each approach (as we'll do shortly), we begin to understand that this may not be so. The purpose of this article is to answer precisely this question, and to assess the speed costs associated with the Web services and various .NET Remoting configurations. To answer this, we will take both technologies to the racetrack and put them "head to head."
Our Object
To demonstrate the technologies that we'll be using, we will create a very simple object that exposes one method. This method selects a random sample of customers from the Northwind database (yes, I said "random" - we may not, in fact, encounter Alfreds Futterkiste in our results). We could develop a custom business object to pass back to the client, but this effectively undermines the purpose of an open, independent Web service. As a result, we will return our sample of 1000 records in a dataset.
To return a random result, we will use the NewID() T-SQL function, as in the following statement:
Select Top 1000 * From Customers Order By NewID()
The full object code can be seen in Listing 1, and it receives a database connection as its single argument. In addition, the class shall be used as in the Remoting example, with the only addition being that it now inherits from MarshalByRefObject. The full source code can of course be downloaded from http://www.sys-con.com/magazine/source.cfm?id=9. The dataset is returned is already serializable, so the class itself does not need to be specifically marked.
.NET Remoting
Remoting in .NET is remarkably customizable and extensible. The framework provides us with a variety of configuration options at each stage of the development process. A wealth of articles and books has been written on this technology and the references at the end of this article provide some rich resources and tutorials on how to build and implement Remoting. Figure 1 illustrates how the technology fundamentally operates. When a call is made from the client, a proxy is generated. The actual server object may or may not be instantiated at this point depending on whether the object is server- or client-activated. To compare properly to the Web service, our Remoting object will be a server-activated SingleCall (i.e., stateless) class. The call is passed through a formatting layer and a transport layer (referred to as "sinks") as well as additional custom layers. At the server, this process is reversed and the call is received by a host application. This in turn forwards the call to the underlying object. The object's specific method is called, and the resulting output is returned via the same route.
The formatter can serialize the call into either a binary or SOAP format and you can select either raw TCP or HTTP as a transport protocol. In fact, through writing your own sinks you can theoretically use any format or protocol. Finally, Remoting allows the host application to be of any kind of .NET project - a Windows service, a Web service, an ASP.NET application, or a .NET executable (graphical or command line). In our sample, we will develop a command line host as well as an ASP.NET host, to compare most fairly with a Web service. To directly analyze the speed options, the command line host will employ both the TCP-binary and HTTP-SOAP combinations. (Note: To execute the Remoting example, the command line exe must be running.) The ASP.NET option will operate similarly to the Web service and will employ HTTP-SOAP. For illustrative purposes, the various combinations will configure the Remoting settings in code, in an XML configuration file, and using a combination of both.
Web Services? What Are Those?
Web services have received such considerable hype in recent years that even the "if you haven't heard of them you must have been in a cave/up a mountain/down a hole" line is old. Nonetheless, it's worth revisiting their architecture in this comparison. Figure 2 illustrates this and we see that they rely on the arguments and return values serialized as XML within a SOAP message, all travelling aboard HTTP packets. In our sample we will copy the existing code into the Web service and prefix it with a requisite <webmethod()> tag.
Time Out
In attempting to analyze the speed of execution of the code, the first tests simply captured the start and end time of the call and subtracted the former from the latter. However, the results were rather peculiar, and further investigation revealed that this and similar methods would be unable to achieve a resolution below 15 milliseconds. As the final results will show, this was wholly unacceptable. Indeed, this perhaps clarifies why the .NET DateDiff function only supports timing to the second interval and not below. The solution, according to the MSDN library (see HOW TO: Use QueryPerformanceCounter to Time Code in Visual Basic .NET in the references), is the use of the QueryPerformanceCounter Win32 API call, for which an easy-to-use implementation was found on DevX.com (see Stopwatch — a High-Resolution code timer class in the references). This class is included in the sample code.
To The Race Track
We will be performing seven tests in our analysis that among them will assess a variety of remote configurations. For both the Web services and Remoting technologies, a local version running on the same machine as the client was tested, and these hosts were then copied to an empty test server elsewhere on the LAN for the subsequent tests. Also, the database in all of the tests was hosted on a third dedicated SQL Server box. The connection string and the number of calls performed in each test are both stored as constants in the sample app and are thus easy to adjust. However, to overcome any compilation or similar initial delays, the very first call to any object is ignored in calculating the timing. A description of each of the tests follows.
In this instance the compiled object is referenced and called directly from the client (i.e., a non-remoting example). This allows us to assess the viability of any form of remoting and also acts as a benchmark for the subsequent tests.
The object is now compiled within the framework of a Web service and hosted locally. The rationale behind this was that one might implement a business or data layer in this fashion to implement a service-oriented architecture (SOA) that's highly extensible. The Web service could be scaled later to another individual server or server farm.
The earlier Web service was simply moved remotely for this to an unused server.
The object is now hosted in a command-line TCP-binary combination on the local machine, as with the local Web service.
As before, this object is simply moved remotely.
The previous host is extended here using the App.Config settings file to allow the HTTP-SOAP combination to be tested as well.
The remoting object is now moved into an empty ASP.NET Web application to mimic as closely as possible the Web service operation.
Results
The results can be seen in Table 1. They proved very interesting indeed. The sample application, as discussed previously, allows us to vary the number of calls to each object. For fewer than 10 calls, the actual result for the first record of each dataset is displayed, as can be seen in Figure 3, but for greater than this only the final averages for each test are shown for conciseness. The direct (non-remoting) results, we can see, average about 0.27 milliseconds per call. What was fascinating was that all of the Remoting calls, regardless of host configuration or even physical location, were very close to this. At worst they rose as high as about 0.35 milliseconds for the HTTP-SOAP combination, and at best they actually averaged faster than the direct call (as we can see, for instance, with Local Remoting in this particular run). .NET Remoting, at its most fundamental level, provides us with the ability to cross AppDomains, regardless of their physical location. Consequently, these results are likely to occur because the hosts are effectively running as separate dedicated processes.
The results show that the local Web service operates statistically significantly slower than the Remoting calls. However, the actual time taken is still quite minimal considering the size of the result set. Nonetheless, this speed difference is startling when we move the Web service remotely, especially when compared to the IIS-hosted HTTP-SOAP Remoting configuration. Essentially, these two are performing very similar underlying operations, and the disparity is quite surprising. Network latency can't be the primary factor and neither can IIS hosting. In fact, the Web service overhead itself can be ruled out because the local version significantly outperforms the remote version. Research (see Performance Comparison: .NET Remoting vs. ASP.NET Web Services in the references at the end of the article) indicated that this might have related to the serialization speed of SOAP, but the local Web service and HTTP-SOAP Remoting object would then have suffered similarly. To verify this anyway, the object was changed to return only 10 results. This lowered the time taken across the board, but was unable to smooth the time difference dramatically. In fact, the author remains at a loss to explain this particular discrepancy, and would welcome any suggestions and opinions.
Summary
This article analyzed various remoting options and configurations available in .NET. We have seen that Remoting significantly outperforms Web services. It's also decidedly configurable and extensible, and not too difficult to work with. Its drawbacks are that it requires the client to have a local reference to the actual DLL itself and that it's not really interoperable beyond the Microsoft frontier. In addition, it requires a hosting application. However, it appears that the difference between the TCP-binary and HTTP-SOAP Remoting isn't at all as considerable as was initially expected, and as the existing industry media has implied. As a result, this configuration, which is more interoperable, should be hosted in IIS. In this way, we can leverage the various IIS security options as well as the host stability that IIS provides (such as application recovery, logging, and so on).
Web services, in contrast, are easier and quicker to develop and deploy, and they definitely interact more easily across platforms. However, they appear to suffer from a substantial speed overhead. The choice between the two technologies must ultimately lie with how interoperable the remote object needs to be. It is essential, however, that this be addressed with a future perspective in terms of the likely use of the object later. In addition, it will be interesting to see what impact WSE 2 and ASP.NET 2 may have here as well.
.NET References:
Dallas, A. (2002) Stopwatch - a High-Resolution code timer class (http://codeproject.com/vb/net/vbnetstopwatch.asp) Dhawan, P. (2002) Performance Comparison: .NET Remoting vs. ASP.NET Web Services (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadot netarch14.asp) Esposito, D. (2002) Design and Develop Seamless Distributed Applications for the Common Language Runtime (http://msdn.microsoft.com/msdnmag/issues/02/10/NETRemoting/default.aspx) Lhotka, R. (2001) Remoting and XML Web Services in Visual Basic .NET (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet10232001.asp) Microsoft HOW TO: Use QueryPerformanceCounter to Time Code in Visual Basic .NET (KB 306978) (http://support.microsoft.com/default.aspx?scid=kb;en-us;306978)
Acknowledgements to Alastair Dallas for the timer class.
Published May 18, 2004 Reads 16,908
Copyright © 2004 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Hilton Giesenow
Hilton Giesenow has over seven years of experience with Microsoft development tools and technologies. He's an active member of the South African INETA group, and he evangelizes .NET to everyone he meets.
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications



























