views:

291

answers:

3

I have to write an application that is essentially a proxy server to handle all HTTP and HTTPS requests from our server (web browsing, etc). I know very little C++ and am very comfortable writing the application features in C#.

I have experimented with the proxy from Mentalis (C# socket proxy) which seems to work fine for small webpages but if I go to large sites like tigerdirect.ca and browse through a couple of layers it is very slow and sometimes requests don't complete and I see broken images and javascript errors. This happens with all of our vendor sites and other content heavy sites.

Mentalis uses HTTP 1.0 which I know is not as efficient but should a proxy be that slow? What is an acceptable amount of performance loss from using a proxy? Would HTTP 1.1 make a noticeable difference?

Would a C++ proxy be much faster than one in C#? Is the Mentalis code just not efficient? Would I be able to use a premade C++ proxy and import the DLL to C# and still get good performance or would this project call for all C++?

Sorry if these are obvious questions but I have not done network programming before.

EDIT In response to Joshua's question: I don't necessarily need to write the core proxy server myself as long as there is a good implementation out there but like I said I have been experimenting with Mentalis which isn't performing that well. The final application needs to install on a Windows PC/Server from a single installer with 0 manual configuration.

I can write all the necessary registry edits in the installer as I have done that before in C#.

UPDATE I took Aaronaught's advice and looked into improving Mentalis' code. I fix a problem so it works with HTTP 1.1 allowing it to work with Chrome and Firefox (Safari 4 on Windows crashes the proxy though for some reason).

When I tested in FireFox and Chrome I discovered the performance problems were not there which implied it was an IE problem not a problem with the proxy. After resetting the browsing history settings the problem went away.

Thanks everyone!

+1  A: 

C++ is not an easy language to learn. Combine that with lack of networking experience and you are in a totally new territory. If you want to explore - fine, you'll make all the mistakes and learn a lot. If, on the other hand, you need to deliver something by some date - go with whatever you are comfortable with at the moment.

Nikolai N Fetissov
Thanks Nikolai, that is what I want to do if C# can handle the task.
modernzombie
+7  A: 

How you actually design and code the application is going to make infinitely more of a difference than the platform you choose.

If you design the server efficiently, it will be efficient. If you design it inefficiently, it will be inefficient. There's no clear advantage to choosing C++ over C# or vice versa... unless you'd have to learn the entire language from scratch, which is a huge negative (hard to come up with a good design when you barely know the tools).

Things you'll probably have to understand for this type of application:

  • I/O completion ports
  • Thread pools and multi-threading in general
  • Networking protocols (including HTTP, FTP, TCP, etc.) - especially for error handling
  • Certificates and signing/encryption (for SSL/HTTPS)
  • ...

Honestly, you're talking about a non-trivial undertaking here. I don't mean to sound overly negative but what makes you think you can do a better job without an extensive knowledge of the underlying networking protocols and proxy design? Why not take a look at the Mentalis Proxy source code instead and see if you can improve it, rather than trying to write your own from scratch? Surely the former would be easier than the latter.

Anyway, a socket is a socket; .NET sockets are not much more than paper-thin wrappers over Windows sockets, so performance is not going to be noticeably different in C++.

Aaronaught
+1 For very pragmatic advice. As Isaac Newton once said *"If I have been able to see further than others, it is because I have stood on the shoulders of giants."*
ChaosPandion
A: 

If you want to write a really fast, clean, down-to-the metal server, go with C++ or plain C.

C++ is not an easy language, and is easy to mis-use. C++ requires the discipline to actually read and contemplate difficult books. Used right, it is the best systems programming language available.

If performance is not an issue, you may use fluffier tools such as C#.

Experienced Joe