Re: Proxying bytes from one socket to another...
From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 02/26/04
- Previous message: Yogesh S: "Increase in Memory"
- In reply to: Kevin Z Grey: "Proxying bytes from one socket to another..."
- Next in thread: Tom Hall: "Re: Proxying bytes from one socket to another..."
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 25 Feb 2004 16:17:30 -0800
Suggestion, why are you using t_buff instead of just using buff? In other
words, why the copy? Does the length of the array have importance to your
message builder?
If so then pass in the recv variable using a special overload that only process
a portion of an
array.
If you still have lag times, you need to time each step and let us know what
lines are causing
the real lag. I honestly can't see anything else wrong with the code below
unless
BuildPacket is awful in terms of performance or the Enqueue method is bad.
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers "Kevin Z Grey" <anonymous@discussions.microsoft.com> wrote in message news:E84BACE9-2F7C-4EF7-B36B-0B47081880EB@microsoft.com... > Heya, > > I have a proxy server that essentially encapsulates received data by pre-prending a few integer values for each chunk of data read off the socket. Now when the data is read, it is constructed into a "Message" object which is basically a struct of int, int, byte[], and is then dumped into a queue to schedule it to be sent by another Thread. Since I have multiple Threads, I am forced to make a copy of the incoming byte array and queue the copy so that my data does not get fragmented. The resulting code looks like this: > > byte[] buff = new byte[1024]; > ... > if (conn.Available > 0) > { > // Read Bytes > int recv = conn.Receive(buff); > byte[] t_buff = new byte[recv]; > Array.Copy(buff, 0, t_buff, 0, recv); > // Construct Packet > MessagePacket packet = MessagePacket.BuildPacket(t_buff); > // Send it via the Outbound Socket > EnqueueOutboundMessage(packet); > } > > Is there a way to avoid an ArrayCopy in this scenario? I have found that when receiving numerous small packets the lag time of the packets being proxied through the system is about 200ms, which is totally unacceptible for this server. Can anyone offer some insight on how I can improve its perfomance? > > ~~K
- Previous message: Yogesh S: "Increase in Memory"
- In reply to: Kevin Z Grey: "Proxying bytes from one socket to another..."
- Next in thread: Tom Hall: "Re: Proxying bytes from one socket to another..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading