开发者

C# Sockets Send vs BeginSend Perfomance

So I understand that Send is Synchronous and BeginSend is Asynchronous. I've heard that the Sockets Send Method is faster for data transfer then BeginSend(Note: I am not talking about CPU Performance but only Send and Recieve packet latency). Can anyone tell me if this is true or not? The article I am referring to where I heard Synchronous Data Transfer goes like this down below.... If it is true, is there a way around it? Or is that just how it is going to be when using Asynchronous Data Transfer?

Thanks very much for you help.

Article Text:

Both of these forms of communication are a means of transmitting data. T开发者_JS百科he difference is in the format that the data is transmitted. Asynchronous communications is the method of communications most widely used for PC communication and is commonly used for e-mail applications, Internet access, and asynchronous PC-to-PC communications. Through asynchronous communications, data is transmitted one byte at a time with each byte containing one start bit, eight data bits, and one stop bit, thus yielding a total of ten bits. With asynchronous communications, there is a high amount of overhead because every byte sent contains two extra bits (the start and stop bits) and therefore a substantial loss of performance.

Synchronous communications is the more efficient method of communications. CQ's connectivity solutions communicate through the synchronous method of communications. Through synchronous communications, data is transmitted as frames of large data blocks rather than bulky individual bytes. One advantage of synchronous is that control information is easily inserted at the beginning and end of each block to ensure constant timing, or synchronization. Another advantage of synchronous is that it is more efficient than asynchronous. For example, a 56 Kbps dial-up synchronous line can carry 7000 bytes per second (56000/8) compared to a 56 Kbps dial-up asynchronous line which can only carry 5600 bytes per second (56000/10). When transmitting large amounts of information, this translates into a significant increase in speed and performance.


I've heard that the Sockets Send Method is faster for data transfer then BeginSend

Not true.

As for the article text. You are talking about two very different things. An asynchronous network connection and asynchronous methods in a computer program.


It is certainly not true. The article talks about Synchronous and Asynchronous in the context of Network Connection Types. However it has nothing to do with how data is sent using Sockets. In .Net, Synchronous and Asynchronous simply means how methods will block(Synchronous) and not-block(Asynchronous) and has nothing to do with data transfer speeds. The latency is the same across any Synchronous and Asynchronous method used.


The most crucial thing I'd say is that Synchronous Socket methods are lot easier to program and can be accomplished in a single wrapper function. (I am assuming that you will inherit from Socket class and add your custom error-handling, logging etc to wrap around Send and Receive)

In case of Asynchronous, you will need at least two functions and another class or struct (a StateObject) to keep track of what you intended to transmit.

You may certainly mask existence of a callback method using anonymous delegate technique but that does not change the fact that your code will be little bit more complicated to understand (and maintain)

I have not been able to accurately time functions but I've seen that for smaller byte sizes (<4K), synchronous seem to be faster and for larger blocks (> 8K), asynchronous seem to be better. Perhaps, when you use ASync to receive larger buffers, Async func has gone ahead and gotten few more bytes fer you while you were chomping up previously received chunk.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜