Justin Smith Technical Evangelist Microsoft Corporation CON301
The Reward Transports, Serializers, and Encoders Client Options Service Options Streaming Common Questions
Comparable to the following managed technologies.NET Remoting System.EnterpriseServices System.Messaging Faster than following Web Services ASMX (ASP.NET Web Service) WSE Great performance vs competition
The Reward Transports, Serializers, and Encoders Client Options Service Options Streaming Common Questions
WCF supports several transports (default) TCP, HTTP, MSMQ, NamedPipes Can customize for others Each transport has it’s own considerations MEP, reach, interop, overhead
Message type == XML Infoset Serializers bridge object graphs to Infosets WCF ships with 3 possibilities for serializers DataContractSerializer (DCS) NetDataContractSerializer (NDCS) XmlSerializer Interop can dictate which one to use Each serializer has performance traits (demo)
Message type == XML Infoset Encoders bridge Infoset to wire format WCF ships with 3 encoders (.NET 3.0) Text, MTOM, Binary.NET Fx 3.5 introduces JSON encoder Interop often dictates which one to use Binary fast, not interoperable MTOM for large binary payloads w/interop Text for most interop Each has performance traits (demo)
Binary significantly faster than text Can easily add a non interoperable endpoint side by side with an interoperate one MTOM comparable to binary Big messages: big impact Protocols converge to comparable throughput Small messages: small impact Most time spent in the protocol overhead
The Reward Transports, Serializers, and Encoders Client Options Service Options Streaming Common Questions
Svcutil can create a proxy type for a service Implements IClientChannel Overhead required to instantiate this type ChannelFactory also works Which one to use: Scvutil type simpler to use, more overhead ChannelFactory harder to use, less overhead Misused frequently!
Dispose unused proxies Can fill the throttle: client hangs Can run out of resources: sockets Don’t create a new Proxy for every call If Channel is stateful, reuse the ChannelFactory “Increasing Middle-Tier Client Performance” Async, Async, Async ! Don’t measure with Tracing on
The Reward Transports, Serializers, and Encoders Client Options Service Options Streaming Common Questions
Services are asynchronous The CPU is a terrible thing to waste ServiceModel conservative limits MaxConcurrent: Sessions == 10 Calls == 16 InstanceContext set to PerCall Singleton and Multiple require synchronization Binding specifies idle timeouts Lazy client defense ReceiveTimeout
The Reward Transports, Serializers, and Encoders Client Options Service Options Streaming Common Questions
Transfer large data Rule of thumb: 1-3 MB, then stream HTTP, TCP, NamedPipe transports only Can stream data to a service, from a service, or both Set TransferMode on Binding type Use System.IO.Stream in contract Set MaxReceivedMessageSize Default 64k
Windows and WCF buffer content Even in a streaming scenario WCF offers Nagle knobs to control buffers ConnectionBufferSize The preferred size of the local buffer MaxOutputDelay The Max time to let data sit AllowOutputBatching Enable batching within WCF
The Reward Transports, Serializers, and Encoders Client Options Service Options Streaming Common Questions
Not disposing unused Proxy Creating a new Proxy for every call Using security when unnecessary (Web) default for NetTcp/NetPipe/WSHttp Using default values for ServerThrottle MaxConcurrent: Sessions == 10 Calls == 16 Streamed contract with Buffered binding Stream if necessary: memory usage, big payloads Buffered faster for smaller payloads
SvcConfigEditor (really!) Diagnostic Traces: SvcTraceViewer Performance Counters Microsoft Visual Studio 2005 Team Suite Performance Tools Netmon Netmon 3.0 publicly available on Xperf/ETW us/library/aa aspx
Don’t make assumptions: measure! Actual payloads have big impact Deployment can make a big difference Other applications competing for resources Network topology can cause delays (latency) Security (Active Directory, x509 & CRLs) Measure primarily end to end scenarios Use micro-benchmarks wisely
Transport NetPipe, NetTcp, BasicHttp, WSHttp Proxy Reuse ServiceChannel, reuse ChannelFactory. Security Transport, WS-* +MessageCredentials, Full WS-* Encoders Binary, MTOM, Text. JSON Compression, not built-in (GZipStream)
Hosting Self Host, Host in IIS Quotas/Throttles Increase but minimize Instancing/Concurrency Singleton/Multiple Transactions OleTx, WS-AT Queues Use Batching
© 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.