NetworkStream performance issues

G

Guest

I'm trying to serialize data through a network stream, deserialize it on the server side and then serialize a response back through the network stream to the client
I'm running into very severe performance issues when trying this ... If I try this on the same computer, I'm getting about 1000 transmissions per second with a custom class ; but if I try this with a client other than the server machine, I'm getting 10 transactions per second
What is even more intriguing is that if I skip the response part back, doing just sends with the client that is - I'll get 1500 transactions on the local machine and 3000 (!!!) with another machine
Does anyone have any idea why a succession of serialize and deserialize on a networkstream is so slow ? Am I doing something wrong ?
 
J

Jon Skeet [C# MVP]

Harry said:
I'm trying to serialize data through a network stream, deserialize it
on the server side and then serialize a response back through the
network stream to the client. I'm running into very severe performance
issues when trying this ... If I try this on the same computer, I'm
getting about 1000 transmissions per second with a custom class ; but
if I try this with a client other than the server machine, I'm getting
10 transactions per second. What is even more intriguing is that if I
skip the response part back, doing just sends with the client that is
- I'll get 1500 transactions on the local machine and 3000 (!!!) with
another machine. Does anyone have any idea why a succession of
serialize and deserialize on a networkstream is so slow ? Am I doing
something wrong ?

Are you sure it's NetworkStream itself that's the problem? Have you
measured how much data is actually coming through it and how long it
takes? How are you reading the response back from the NetworkStream?
Could you perhaps save bandwidth by not using "standard" serialization
but sending back your own formatted response?
 
G

Guest

Are you sure it's NetworkStream itself that's the problem? Have you
measured how much data is actually coming through it and how long it
takes? How are you reading the response back from the NetworkStream?
Could you perhaps save bandwidth by not using "standard" serialization
but sending back your own formatted response

I did some further testing, and it seems I put my foot in my mouth - the problem also happens with a normal socket connection, whatever I send, at one condition : sending the size of the data before the data itself
This gives the following pattern for the client
- Send data siz
- Send dat
- Receive response siz
- Receive respons
and vice-versa on the server. If I skip the data size bits, when using a fixed data size for instance, I do not run in this problem and I get good performance as expected. I'll try to do both sends at once, aggregating the size to the data buffer, to see if this solves things. Though it won't help me with serializing since I'm serializing on the network stream and I don't have any control on how to send things ..
I'll post an update to let you know how things go, thanks for the response !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top