5 steps to optimizing wcf services
DESCRIPTION
Presentation by Punit Ganshani on 5 quick steps to Optimizing your WCF servicesTRANSCRIPT
5-steps to Optimizing WCF servicesPunit Ganshani
Punit GanshaniPunit Ganshani is a Technology Evangelist practising application design & development on C#, WCF, WP8, WinRT and Open Source. He is an open-source contributor on CodePlex, has several applications on Windows Phone Store, author of a book, and 18+ whitepapers in international magazines.
Twitter - @ganshani@codetails
LinkedIn -Connect
SlideShare –View Presentations
Blog Sites – www.ganshani.com www.codetails.comOpen Source –CodeInject, Workflow Extractor, dI.Hook
Choose the right binding
Source: http://weblogs.asp.net/blogs/spano/WCFBindings.JPG
Step 1
Choosing the Encoder
Default encoderText• BasicHttpBinding and WsHttpBinding• Uses XML UTF-8 encoding
Interoperable formatMTOM• More optimized transmission of binary blobs• Not base-64 encoded, hence faster
Default encoder w/binary formatBinary
• NetTcpBinding and NetNamedPipeBinding• Avoids base64 encoding and use Session Encoders• Uses a dictionary-based algorithm to avoid data
duplication
Step 2
Which Encoder?
▪ Supports the right binding
▪ Size of the message▪ Choose one that shortens your message▪ Smaller the size of message, faster it will be transferred
▪ Check the CPU load▪ Encoding takes time and CPU cycles
▪ Keep it Simple Stupid (KISS)▪ Remove redundant attributes / properties from message▪ Keep it binary if possible
▪ Interoperable▪ MTOM – check for interoperability with non-WCF services
Step 2
Session Encoders.. Build / reuse
▪ Binary encoder has Session Encoders▪ Builds a dictionary based on pattern of
messages▪ Uses dictionary and analysis pattern for
encoding▪ Optimizes speed as time goes by
▪ Other encoders▪ Build your own session encoder
Step 2
Compress after encoding
▪ A right encoder reduces message size by 4-5 times
▪ But the shorter the message, the better▪ WAS/IIS Hosted Service: Use IIS compression ▪ Others: Uses GZip and Deflate mechanisms
for all outgoing/incoming messages
▪ For custom compression, hook the encoder and apply compression techniques
Step 3
Cache
▪ Register your dependencies, and locate them when required
▪ Consider caching data,▪ In memory Cache -
▪ Ideal for small sized application hosted on a single instance/server
▪ WAS/IIS Hosted Services: Use ASP.NET Caching Services or Runtime Caching
▪ Self hosted: Use Enterprise Library
▪ App-Fabric:▪ Ideal for distributed hosted applications▪ Overcomes several problems such as sticky
sessions, component-dependent caching, dirty cache and cache-synchronizing
Step 4
Small things, big difference
▪ Load Balance:▪ Increases scalability▪ Increases performance
▪ Use GPU for data computing:▪ Accelerator by Microsoft▪ CUDA by NVIDIA
Step 5