2

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.

1 Answers1

1

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

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
  • Thank you! I was about to begin writing some custom message passing that would among another things handle compression adaptability (adaptive arithmetic coding to be precise), but nothing is more frustrating than investing several hours into something and then finding out it was offered out of the box! –  Jul 02 '13 at 18:22
  • What I've found is that WCF Stream sends at most 64KB at a time. And it seems like I can take the first 64KB from the stream, deserialize it and use it. Which tells me that .NET is gzipping 64KB chunks which is actually pretty horrible. – Sal Jan 24 '17 at 19:31