Socket性能C ++或C# [英] Socket Performance C++ Or C#

查看:265
本文介绍了Socket性能C ++或C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个实质上是代理服务器的应用程序来处理来自我们服务器的所有HTTP和HTTPS请求(网络浏览等)。我知道很少C ++,并且非常舒服的在C#中编写应用程序功能。



我已经尝试了来自 Mentalis (C#套接字代理),似乎工作正常的小网页,但如果我去大型网站,如tigerdirect.ca,浏览一对夫妇的层,它是非常缓慢,有时请求不完成,我看到破碎的图像和JavaScript错误。这发生在我们所有的供应商网站和其他内容重的网站。



Mentalis使用HTTP 1.0,我知道这不是那么高效,但应该是一个代理慢?使用代理时,可接受的性能损失量是多少? HTTP 1.1会产生明显的差异吗?



C ++代理比C#中的代理要快得多吗? Mentalis代码是不是有效率?
我可以使用一个预制的C ++代理并将DLL导入C#并仍然获得良好的性能,或者这个项目调用所有的C ++?



如果这些都是明显的问题,但我以前没有做过网络编程。



EDIT 回答Joshua的问题:写自己的核心代理服务器,只要有一个很好的实施,但我喜欢我说我一直在试验Mentalis,这不是很好。最后的应用程序需要从Windows PC /服务器上安装一个安装程序0手动配置。



我可以写所有必要的注册表编辑安装程序,因为我有

更新我采用了Aaronaught的建议,并研究改进Mentalis的代码。我修复了一个问题,所以它工作与HTTP 1.1允许它使用Chrome和Firefox(Windows 4上的Safari 4崩溃代理虽然由于某种原因)。



当我在FireFox和Chrome中测试时,我发现性能问题不存在,这意味着它是一个IE问题不是代理的问题。重设浏览记录设定后,问题消失了。



感谢大家!

解决方案>



如果你有效地设计服务器,那么你的应用程序的设计和代码将比你选择的平台有更大的不同。将是高效的。如果你设计的效率低下,效率会低下。选择C ++超过C#没有明显的优势,反之亦然...除非你必须从头开始学习整个语言,这是一个巨大的负面(当你几乎不知道工具时,很难想出一个好的设计)。



这种类型的应用程式可能需要了解的资料:




  • I / O完成端口

  • 线程池和多线程一般

  • 网络协议(包括HTTP,FTP,TCP等)特别是错误处理

  • 证书和签名/加密(用于SSL / HTTPS)

  • ...



    • 老实说,你在这里谈论一个不平凡的事情。我不是想听起来过于负面,但是什么让你认为你可以做一个更好的工作,没有底层网络协议和代理设计的广泛知识?为什么不看看Mentalis Proxy源代码,看看你是否可以改进它,而不是试图从头写自己的?当然前者比后者更容易。



      无论如何,一个套接字是一个套接字; .NET套接字不只是在Windows套接字的纸薄包装,所以性能在C ++中不会有明显的不同。


      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!

      解决方案

      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++.

      这篇关于Socket性能C ++或C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆