tags:

views:

819

answers:

3

I am having a Web application sitting on IIS, and talking with [remote]Service-Machine. I am not sure whether to choose TCP or Http, as the main protocol.

more details:

  1. i will have more than one service\endpoint
  2. some of them will be one-way
  3. the other will be two-ways
  4. the web pages will work infront of the services
  5. we are talking about hi-scale web-site

I know the difference pretty well, but I am looking for a good benchmark, that shows how much faster is the TCP?

+1  A: 

You could always benchmark it.

In general, if what you want to accomplish can be easily done over HTTP (i.e. the only reason you would otherwise think about using raw TCP is for a possible performance boost) you should probably just use HTTP. Sure, you can do socket programming, but why bother? Lots of people have spent a lot of time and effort building HTTP client libraries and servers, and they have spent waaaaaay more time optimizing and testing that code than you will ever be able to possibly spend on your TCP sockets. There are simply so many possible errors that you would have to handle, edge cases, and optimizations that can be done, that it is usually easier and safer to use a library function for HTTP.

Plus, the HTTP specs define all kinds of features (and clients/servers implement, which you get to use "for free", i.e. no extra implementation work) which makes any third-party interoperability that much easier. "Here is my URL, here are the rules for what you send, here are the rules for what I return..."

Adam Batkin
Caveat -- if it's a conversation though, HTTP may not be efficient - multiple requests in HTTP through opening a TCP connection each time is expensive and I've seen servers starve of resources as the underlying TCP connections aren't closed cleanly. Yes, HTTP/1.1 supports keeping a connection open for more requests, but it's not clear if this other service supports this.
Chris J
That's true, though if the other server does support it, that's one of those "free" optimizations. As for connections not being closed cleanly, that's a bug in the library, and would be a serious problem, but the again the "roll-your-own" case would need to be wary of every possible situation that might result in the same resource starvation.
Adam Batkin
I am not sure what do you mean in implementing?! it is damn simple to just use WCF and net.tcp if it will be faster (and create Java proxies if needed)or maybe we have the implementation for java ...so it is already implemented and tested,just need to decide, isn't it?
rabashani
+2  A: 

The question you really need an answer for is "will TCP or HTTP be faster for my application". The answer is that it depends on the nature of your application, and on the way that you use TCP and/or HTTP in your application. A generic HTTP vs TCP benchmark won't answer your question, because the chances are that the benchmark won't match your application behaviour.

In theory, an optimally designed / implemented solution using TCP will be faster than one that uses HTTP. But it may also be considerably more work to implement ... depending on the details of your application.

There are other issues that might affect your choice. For example, you are less likely to run into firewall issues if you use HTTP than if you use TCP on some random port. Another is that HTTP would make it easier to implement a load balancer between the IIS server and the backend systems.

Finally, at the end of the day it is probably more important that your system is reliable, maintainable and (maybe) scalable than it is fast. A sensible strategy is to implement the simple version first, but have plans in your head for how to make it faster ... if the simple solution is too slow.

Stephen C
+5  A: 

HTTP is a layer built ontop of the TCP layer to some what standardize data transmission. So naturally using TCP sockets will be less heavy than using HTTP. If performance is the only thing you care about then plain TCP is the best solution for you.

You may want to consider HTTP because of its ease of use and simplicity which ultimately reduces development time. If you are doing something that might be directly consumed by a browser (through an AJAX call) then you should use HTTP. For a browser to directly consume TCP connections without HTTP you would have to use Flash or Silverlight and this normally happens for rich content such as video and/or audio.

As for benchmarks, this is the only thing I found. See page 5, it has the performance graph. Note that it doesn't really compare apples to apples since it compares the TCP/Binary data option with the HTTP/XML data option. Which begs the question: what kind of data are your services outputting? binary (video, audio, files) or text (JSON, XML, HTML)?

In general performance oriented system like those in the military or financial sectors will probably use plain TCP connections. Where as general web focused companies will opt to use HTTP and use IIS or Apache to host their services.

Darwyn