Sockets, Performance, Messaging, NetworkStream

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



If anyone can help that will be much appreciated.

I have implemented async socket server & client, functionally both work
well, when connected through loopback, performance is reasonably good. The
issue comes when i run the software over the network while functionally it
remains stable, performance wise it begins to suffer. I suspect it has
something to do with buffering, although I cant seem to pin point where :)


Initially I have worked directly with sockets, i.e. socket.beginread
socket.begin write etc..
Then I added the NetworkStream object, assuming that it will do the first
line of buffering and then actually write the data into the socket. The
situation improved but not by much.

One of the rules is that a message needs tobe delivered to the other side as
soon as it is completed, which means I can not use buffered stream and wait
for the
buffer to fill up.

message class:
MessageHeader Header;
byte[] data;
end message class


Send function (sync write) pseudo code:
byte[] message_header = header2bytes(currentmessage.messageheader)
socket (or networkstream).Write(currentmessage.header)
socket (or networkstream).Write(message.data)

reader function is async read

I suppose I lack the true understanding of what the purpose of NetworkStream
class is (other then being able to chain crypto and other streams why would
anyone use it?)

If anyone has anything coherent on the subject - please let me know.

Current performance is about 8 messages per second where server sends to
client and client sends it back
Message size is 84 bytes (with header)
Network 100 mb full duplex
MTU 1500
network latency 25 microseconds (just an L2 switch)
cpu utilization on systems running server and client is below 1%

as a side note, if i increase message size to 5k i get the same message rate
:)

tia
.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)