Using protobuf in WCF services
Asked Answered
R

3

17

My asp.net web pages are on IIS web server and it communicates with WCF services(sitting on windows 2008 app server) using basic HTTP binding. The performance of my wcf services doesnt seem to be that good and I want to improve the same.Also, I need to balance on scalability as my site will be having a very high traffic.

HTTP compression,throttling are some of the ways am aware of but have not tried them yet.. Can i use protobuf API...Please suggest...

Ruyter answered 25/4, 2009 at 22:10 Comment(0)
S
28

The short answer is "yes"...

The protocol buffers spec itself doesn't provide an RPC stack, but some have been added outside the spec.

Firstly, protobuf-net has hooks for WCF, allowing you to mark operations on your service contract as ProtoBehavior. This then swaps the regular DataContractSerializer to use protobuf-net serialization. However, there are some caveats:

  • your data-members must have explicit Order (e.g. [ProtoMember(Order = 1)]), since it uses these numbers as the field identifiers (protocol buffers uses numeric fields)
  • it works best with assembly/class sharing (of the service contract etc), since this custom behavior is not exposed on "mex"

When used with the basic http transport, this is also compatible with MTOM (if enabled) for maximum througput. Performance of non-trivial messages is largely proportional to their size; you can get an idea of protobuf-net's sizes here.

Alternatively, I'm also working on a bespoke RPC stack. The current build has a working stack over http, but I also plan to enable it on raw TCP/IP when I get chance. I haven't had chance to write it up yet, but I can provide examples on request. Note that to use it most conveniently, you'll want the 3.5 "extensions" dll, too.

Any questions, add a comment or e-mail me (see my profile).

Sandal answered 26/4, 2009 at 12:5 Comment(1)
what if the message is a primitive data type? does it still replace the behavior? for example, if you are returning a double array, is it sent as serialized bytes? and do you need assembly sharing in this case? Also, you are saying it works best with assembly sharing. So how does it behave if the client doesn't know about PortoMember order?Imperative
C
2

You could also take a look at using a TCP based binding if the WCF service does not need to be exposed outside of the internal network.

Carol answered 25/4, 2009 at 22:24 Comment(0)
P
0

See protobuf-net.

protobuf-net is a .NET implementation of this, allowing you to serialize your .NET objects efficiently and easily. It is compatible with most of the .NET family, including .NET 2.0/3.0/3.5, .NET CF 2.0/3.5, Mono 2.x, Silverlight 2, etc.

Pyretotherapy answered 25/4, 2009 at 22:13 Comment(3)
thanks for your answer...may i know if you have already used protobuf and how much performance improvement is seen?Ruyter
Actually Marc, the author of that library is somewhere on StackOverflow. I'll email him and point him to the question :)Pyretotherapy
To clarify, I'm only the author of "protobuf-net"; "protocol buffers" is credit to some very smart people at Google.Sandal

© 2022 - 2024 — McMap. All rights reserved.