Re: max buffer for send?

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

From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 09/10/04


Date: Fri, 10 Sep 2004 09:57:31 -0700

Prioritizing the data is clearly your application's responsibility.
Do not queue more data in the socket than the lag you are
willing to introduce. Don't queue too little data either, because
the network will be starved and performance will suffer. I've
usually found a send buffer of 8KB to be adequate for my
purposes. Your needs may be different.

Also, consider using two sockets instead of one. It's usually
not recommended, but for certain applications it might be the
right choice.

-- 
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Peter Carlson" <peter@__N.O.S.P.A.M__howudodat.com> wrote in message 
news:ue63GbulEHA.2224@tk2msftngp13.phx.gbl...
> Maybe my understanding of overlapped sends isn't good enough.   Here's a
> possible scenario
> Lot's of Q1 data comes in...that's heavy in volume but not time critical 
> to
> get to the other side.  So now we have 1mb or so of this data queued from
> calling send or even WSASend.  Now here comes several Q0 buffers, those 
> are
> time critical, for example streaming audio.  Simply calling send or 
> WSASend
> places them at the end of the buffers and means they wont get sent until
> after the 1mb of non-critical data is sent.
>
> Using a queue allows us to insert a critical packet before a non-critical
> packet.
>
> Peter
>
> "Alexander Nickolov" <agnickolov@mvps.org> wrote in message
> news:OeV$ANtlEHA.3544@TK2MSFTNGP15.phx.gbl...
>> Why don't you consider using overlapped sends (WSASend)?
>>
>> -- 
>> =====================================
>> Alexander Nickolov
>> Microsoft MVP [VC], MCSD
>> email: agnickolov@mvps.org
>> MVP VC FAQ: http://www.mvps.org/vcfaq
>> =====================================
>>
>> "Peter Carlson" <peter@__N.O.S.P.A.M__howudodat.com> wrote in message
>> news:OBQK$iplEHA.3896@tk2msftngp13.phx.gbl...
>> > Alun,
>> >
>> > I understand the concepts you outlined below.  Bringing all the pieces
>> > together then my questions:
>> > Given:
>> >        non-blocking sockets
>> >        WSAAsyncSelect Architecture
>> >        I can *theoretically* shove as much data as possible through
> send()
>> >
>> > Problem...how do you go about implementing a weighted queue or simple 2
>> > queue system.
>> > In theory you would do somthing like:
>> >
>> > Send(char *buf, int len, int queue) {
>> >    if (SocketIsWriting)
>> >        Queue[queue].AddBuffer(buf, len);
>> >    else
>> >        send(m_hSocket, buf, len);
>> > }
>> >
>> > What we do now requires that everything is put in the queue.  It works
>> > well,
>> > but I am trying to remove the overhead of putting it in the queue if I
>> > dont
>> > need to.
>> >
>> > Send (char *buf, int len, int queue) {
>> >    Queue[queue].AddBuffer(buf, len);
>> >    if (_bOk2Send) PostMessage (WM_SOCKET_NOTIFY, m_hSocket, FD_WRITE);
>> >    _bOk2Send = false;
>> > }
>> >
>> > OnNotifyWrite() {
>> >    int nCtr = 0;
>> >    while (++ctr < 5) {    // < 2, < 3, we're still experimenting
>> >        const char *buf = NULL; int nLen = 0;
>> >        // always send queue 0 first
>> >        if (Queue[0].Size() > 0)  Queue[0].GetBuffer(buf, &nLen);
>> >        else                                Queue[1].GetBuffer(buf,
> &nLen);
>> >
>> >        if (!buf) { _bOk2Send = true; return; }    // queues are empty
>> >        if (send(m_hSocket, buf, nLen) == SOCKET_ERROR) return;
>> >    }
>> >
>> >    // allow something else in this thread to work too
>> >    PostMessage (WM_SOCKET_NOTIFY, m_hSocket, FD_WRITE);
>> > }
>> >
>> >
>> > "Alun Jones [MSFT]" <alunj@online.microsoft.com> wrote in message
>> > news:er5AeGplEHA.536@TK2MSFTNGP11.phx.gbl...
>> >> "Peter Carlson" <peter@__N.O.S.P.A.M__howudodat.com> wrote in message
>> >> news:OX1kLinlEHA.2764@TK2MSFTNGP11.phx.gbl...
>> >> > I wouldn't *actually* use the code I wrote in my first post :)  But
> now
>> > I
>> >> > have a different question.
>> >> >
>> >> > We have our own buffering system similar to a fair weighted queue.
> Is
>> >> there
>> >> > a way to tell if the socket is currently "writing"?  So the basic
> logic
>> >> > would look like:
>> >>
>> >> That would depend on your definition of "writing".
>> >>
>> >> When you call send(), you are asking the socket stack _only_ to queue
> the
>> >> data for transmission to the remote host.  If you are using blocking
>> >> sockets, send() will return when it's finished queuing the data.  If
> you
>> > are
>> >> using non-blocking sockets, send() will indicate how much, if any, 
>> >> data
>> > has
>> >> been queued up to send.  There is no useful information for you, the
>> >> application, until the point at which you receive some form of
>> >> acknowledgement of that data from the remote application.
>> >>
>> >> Note that while there are acknowledgements in TCP, those
> acknowledgements
>> >> are available to the TCP stack only, not to you, because they are
>> >> meaningless to you - you want to know "has the application received 
>> >> and
>> >> processed the data I sent it", and you don't want to know "is the data
>> >> somewhere between the TCP stack and the application, maybe in the TCP
>> > stack,
>> >> maybe in the application, maybe processed yet, maybe not".
>> >>
>> >> So, after you've called "send", and the data has all been accepted by
> the
>> >> network stack, you should picture it as being in a nebulous cloud
>> > somewhere
>> >> between your application and the remote application, until such time 
>> >> as
>> > you
>> >> get a response from the remote application that indicates it received
>> >> your
>> >> data.
>> >>
>> >> This is, at once, the simplest and hardest concept in networking -
> unlike
>> >> many other aspects of computing, you have zero control over it.  Once
> you
>> >> can accept that and move on, you will be a better network developer.
>> > There
>> >> is no "unqueue", no "flush".  Data that you have queued to send is not
>> > your
>> >> data (in the sense of "being under your control") any more.  You
>> > relinquish
>> >> it to the network.
>> >>
>> >> Alun.
>> >> ~~~~
>> >>
>> >>
>> >
>> >
>>
>>
>
> 


Relevant Pages

  • Example: Socket code (Was Re: ClientServer App)
    ... protocol, such as HTTP, as your application middleware backbone?". ... control of the server with Flash Data Management Services?" ... just enter an asterix "*" for the Queue Name and then click ... thought was to use sockets with xml-rpc but then thought there has to ...
    (comp.lang.java.programmer)
  • Re: Interrupts handling in ADA
    ...     select ... You have some piece of code executing while ... Queue of entry calls: ... sockets but accessing the same data through "pointers"? ...
    (comp.lang.ada)
  • Messages accumulating using send() function from the socket
    ... using Sockets. ... The trading server is connected to the client side through the advanced ... queuing system of oracle and to the message distributor through sockets. ... Second the order will be queued in a queue called "Receive Queue" using ...
    (Tru64-UNIX-Managers)
  • Re: max buffer for send?
    ... Problem...how do you go about implementing a weighted queue or simple 2 ... > acknowledgement of that data from the remote application. ... > somewhere between the TCP stack and the application, ... > can accept that and move on, you will be a better network developer. ...
    (microsoft.public.win32.programmer.networks)
  • Re: The rationale for IOCP
    ... >> to check all the sockets just to discover one. ... IOCP tells you that an operation completed, ... GQCS is more analogous to popping an item off a queue in user-space. ... of the I/O operation, ...
    (comp.programming.threads)