Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Willy Tarreau <w@1wt.eu>
Cc: netdev@vger.kernel.org
Subject: Re: TCP: orphans broken by RFC 2525 #2.17
Date: Sun, 26 Sep 2010 23:01:11 +0200	[thread overview]
Message-ID: <1285534871.2357.19.camel@edumazet-laptop> (raw)
In-Reply-To: <20100926184914.GC12373@1wt.eu>

Le dimanche 26 septembre 2010 à 20:49 +0200, Willy Tarreau a écrit :
> On Sun, Sep 26, 2010 at 08:35:15PM +0200, Eric Dumazet wrote:
> > I was referring to this code. It works well for me.
> > 
> > shutdown(fd, SHUT_RDWR);
> > while (recv(fd, buff, sizeof(buff), 0) > 0)
> > 	;
> > close(fd);
> 
> Ah this one yes, but it's overkill. We're actively pumping data from the
> other side to drop it on the floor until it finally closes while we only
> need to know when it has ACKed the FIN. In practice, doing that on a POST
> request which causes a 302 or 401 will result in the whole amount of data
> being transferred twice. Not only this is bad for the bandwidth, this is
> also bad for the user, as we're causing him to experience a complete upload
> twice, just to be sure it has received the FIN, while it's pretty obvious
> that it's not necessary in 99.9% of the cases.
> 

I dont understand how recv() could transfert data twice.

Once you issued shutdown(RDWR), socket rx buffer is freezed and no more
incoming data should be accepted/queued.

You only read from the socket receive queue to null buffer, and in most
cases a single recv() call will be enough to drain the queue.


> Since this method is the least efficient one and clearly not acceptable
> for practical cases, I wanted to dig at the root, where the information
> is known. And the TCP recv code is precisely the place where we know
> exactly when it's safe to reset.
> 

And its safe to reset exactly when application just does close(), if
unread data was not drained. Not only its safe, but required. A new RFC
might be needed ?


> Also there's another issue in doing this. It requires polling of the
> receive side for all requests, which adds one epoll_ctl() syscall and
> one recv() call, which have a much noticeable negative performance
> impact at high rates (at 100000 connections per second, every syscall
> counts). For now I could very well consider that I do this only for
> POST requests, which currently are the ones exhibiting the issue the
> most, but since HTTP browsers will try to enable pipelining again
> soon, the problem will generalize to all types of requests. Hence my
> attempts to do it the optimal way.

This might be overkill but is a portable way of doing this, on all
versions of linux.

Sure, you could patch kernel to add a new system call

close_proper(fd);

As shutdown() only uses two bits, you can eventually add another bit to
flush receive queue as well (to avoid the copy of it)

Another question, is : why the server closes the socket, if you believe
more pipelining is coming soon ?




  reply	other threads:[~2010-09-26 21:01 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-26 13:17 TCP: orphans broken by RFC 2525 #2.17 Willy Tarreau
2010-09-26 17:02 ` Eric Dumazet
2010-09-26 17:40   ` Willy Tarreau
2010-09-26 18:35     ` Eric Dumazet
2010-09-26 18:49       ` Willy Tarreau
2010-09-26 21:01         ` Eric Dumazet [this message]
2010-09-26 21:46           ` Willy Tarreau
2010-09-26 22:19             ` David Miller
2010-09-26 22:10         ` David Miller
2010-09-26 19:16     ` Willy Tarreau
2010-09-26 22:14       ` David Miller
2010-09-26 22:13 ` David Miller
2010-09-26 22:34   ` Willy Tarreau
2010-09-26 22:38     ` David Miller
2010-09-26 22:54       ` Willy Tarreau
2010-09-26 23:08         ` David Miller
2010-09-26 23:25           ` Willy Tarreau
2010-09-27  1:12             ` David Miller
2010-09-27  5:39               ` Willy Tarreau
2010-09-27  5:48                 ` Eric Dumazet
2010-09-27  6:04                   ` Willy Tarreau
2010-09-27  6:44                   ` David Miller
2010-09-27  6:42                 ` David Miller
2010-09-27  7:34                   ` Willy Tarreau
2010-09-27  7:42                     ` David Miller
2010-09-27 19:21                       ` Willy Tarreau
2010-09-27 23:28                         ` Herbert Xu
2010-09-28  5:12                           ` Willy Tarreau
2010-09-28  5:32                             ` David Miller
2010-09-28  5:37                               ` Willy Tarreau
2010-09-27  9:12                     ` Julian Anastasov
2010-09-27 19:24                       ` Willy Tarreau
2010-09-27 20:00                         ` Eric Dumazet
2010-09-28  9:01                         ` Julian Anastasov
2010-09-28  9:26                           ` Willy Tarreau
2010-09-27  8:02 ` Herbert Xu
2010-09-27 20:00   ` Willy Tarreau
2010-09-27 20:08     ` Rick Jones
2010-09-27 20:20       ` Willy Tarreau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1285534871.2357.19.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox