HTTPListener vs Native HTTP performance
Quick Background: I understand that HTTPListener uses http.sys kernel driver which supposedly makes it a great performer. However, when doing some performance benchmarks between a managed http server and a native vc++ server I am seeing approx 15 MB/s increase on the native side. Test setup is two lab machines freshly formatted with 1gb nics. On the native side I am seeing about 110 MB/s which is close to 100% of the nic minus overhead, when using HTTPListener I am seeing ~94 MB/s (max 100).
The t开发者_Python百科ests are apples to apples,
- both send the same payload (~120 mb)
- I am using the same managed client app to test both servers
- For Managed I have disabled Nagle (But tested both ways, result is the same)
- I run a batch of tests and calculate the throughput, interesting note is that the Managed std deviation is higher, i.e. the results are not as consistent compared to the native.
Overall I expect that I should be able to get close to the 110 MB/s of the native server via HTTPListener, 15 MB/s seems pretty costly.
Questions: 1. Are there other optimizations for managed that I am missing? 2. What are some potential bottlenecks, I looked at the HTTPResponseStream via reflector, looks like there is some marshaling going on, but no glaring issues, In fact when using chunking it produces an identical chunk array as my native server.
Any ideas are appreciated,
The fact that it uses Http.sys doesn't mean that there isn't a native-to-managed transition. From the above-mentioned MSDN article:
HTTP.sys provides connection management, bandwidth throttling, and Web server logging.
By virtue of the fact that you are running managed code, you have interop (native to managed, not to be confused with COM interop), you have garbage collection, etc. It's never going to be as fast as a pure native c++ implementation.
EDIT: To make this clearer, you are still running a .NET process, you are just hooking into IIS in kernel mode, not in user mode. A great article on this is here: http://www.west-wind.com/presentations/howaspnetworks/howaspnetworks.asp
精彩评论