Re: Proxying bytes from one socket to another...

From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 02/26/04

  • Next message: Tom Hall: "Re: Proxying bytes from one socket to another..."
    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
    

  • Next message: Tom Hall: "Re: Proxying bytes from one socket to another..."

    Relevant Pages

    • (patch for Bash) regex case statement
      ... Following up on my previous patch for regex conditional tests, ... /* Return an array of strings; ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
      (comp.unix.shell)
    • Re: Strategy or Iterator?
      ... It would be possible to write a class that returns the variations ... GNU General Public License for more details. ... protected CombinatoricOperator(Telements, int r) { ... An integer array backing up the original one to keep track of the ...
      (comp.lang.java.programmer)
    • (patch for Bash) regex conditional tests
      ... 'regex' are returned in array variable SUBMATCH. ... Skipping of positional parameters, array elements, string ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
      (comp.unix.shell)
    • Re: Warning on assigning a function-returning-a-pointer-to-arrays
      ... This declares pfunc as a function taking no arguments and returning ... int x, y; ... Presumably pfuncwill return a pointer to a single int, ... or the first of a sequence of "array 5 of int"s. ...
      (comp.lang.c)
    • Re: Memory Allocation Problem, please help
      ... typedef struct word_tag{ ... array is not an array. ... static int total_word_count; ... static int word_index(const char *word); ...
      (comp.lang.c)

    Loading