Question

I have just found out that compression has been added to WCF, supporting Deflate and GZip compression schemes. The documentation seems very vague on the operation details.

I was wondering if someone has detailed information on how the compression works.

Is it done on a per-message basis (each message is handled and compressed independently of the previous messages?) Or perhaps it is done (or can be configured) in an adaptive fashion? (the next message takes advantage of compressibility information gathered from the previous ones?)

Basically I would like to know if enabling this new compression feature can benefit a chatty application that transmits small chunks of real-time data that is known to be VERY compressible if grouped, but compresses VERY poorly if handled in isolation. The real-time constraint unfortunately doesn't allow us grouping several messages to aid the compression process.

Was it helpful?

Solution

No

WCF Compression is done using a custom message encoder. It's basically the same concept behind the Gzip Message Encoder included in WCF Samples.

You can take a look on System.ServiceModel.Channels.MessageEncoder. Basically, A majority of the encoding work takes place in read/write methods (Streaming/Message, Async/Sync, ...) There is also a very specific optimisation for session, but I don't think this will help you.

Not specific to WCF, using Gzip reduce on average, content encoding saved 75% off of text files (HTML, CSS, and JavaScript) and 37% overall. Gzipping is only beneficial for larger resources. Due to the overhead and latency of compression and decompression, you should only gzip files above a certain size threshold (a few KB); Gzipping files below can actually make them larger.

So, Compression is mostly useful if network bandwidth is a bottleneck (sending large messages or where bandwidth is constrained). In the case where the CPU is the bottleneck, compression will decrease throughput. As for every optimizations, appropriate testing must be done in a simulated environment to find out if this benefits the application.

If the service is Web-hosted in IIS, a service can be configured to send a compressed response using the dynamic compression module (using HTTP headers Content-Encoding) without using WCF stuff

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top