Why do I get IPC delays on 20% busy machine

一曲冷凌霜 提交于 2019-12-06 21:34:24

Ok I think TCP is fine here and I still believe that you're going to have similar performance between named pipes and a local socket in this scenario (I'd be very interested to see benchmarks though). One thing I noticed though is your ReceivedCallback is calling EndReceive and then doing a bunch of work prior to calling BeginReceive again. This means that you could still be receiving data on the socket (quite likely since there's no latency on localhost) but you're not actually handling it. What you should consider is having socket.BeginReceive() be the first call after EndReceive() (and check for errors, connection closed, etc.) so that you don't have anything stacking up while you're processing data. Obviously you'll need to copy the buffer out first or use a buffer pool (I'd go with a buffer pool, personally) so that you don't clobber your data, but not having a pending BeginReceive() call and sitting there processing data will add some artificial latency since you're getting the data very quickly but you're just ignoring it. I've seen this type of thing happen before with web objects where deserialization of very large objects was being handled by the callback so I wouldn't be surprised if that was the case here. I'd say that's the next thing you should try and see if that changes the latency. It's entirely possible that I am incorrect but I think that refactoring your code as I've recommended here is worth your time to see if it fixes the issue.

Mutiple errors here.

First, TCP. Nothing against TCP but it is not low latency per default ant totally the wrong technology for anything on a single machine.

Switch to named pipes - that will use shared memory under the hoods. You also get rid of any lookup on the same machine.

http://msdn.microsoft.com/en-us/library/bb546085(v=vs.110).aspx

has sample code. properly coded you can approach the speed of RAM.

That said, you also should not send text around - dream up some binary coding or you waste time encoding and decoding.

You should not use DateTime for benchmarking performance because it is not accurate.

http://blogs.msdn.com/b/ericlippert/archive/2010/04/08/precision-and-accuracy-of-datetime.aspx

If the question you want to ask is about how long some operation took, and you want a high-precision, high-accuracy answer, then use the StopWatch class. It really does have nanosecond precision and accuracy that is close to its precision.

Remember, you don’t need to know what time it is to know how much time has elapsed. Those can be two different things entirely.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!