netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rémi Denis-Courmont" <rdenis@simphalempin.com>
To: Hirokazu Takahashi <taka@valinux.co.jp>
Cc: johaahn@gmail.com, netdev@vger.kernel.org
Subject: Re: [PATCH] sendfile() and UDP socket
Date: Fri, 19 Sep 2008 16:14:12 +0300	[thread overview]
Message-ID: <200809191614.14763.rdenis@simphalempin.com> (raw)
In-Reply-To: <20080919.212854.19019802.taka@valinux.co.jp>

Le vendredi 19 septembre 2008 15:28:54 Hirokazu Takahashi, vous avez écrit :
> > > UDP is a datagram protocol, so I think applications using UDP should
> > > care about the size of packets they are going to send rather than
> > > expecting that the messages will be split into several packets
> > > automatically. If some of the packets have lost, it will be really hard
> > > for the applications to re-create the same ones to send again.
> >
> > Also, why use UDP for this... If you want stream semantics, why not use
> > TCP or SCTP instead?
>
> I think a lot of VoIP and video streaming services are working on UDP.

VoIP uses lots of small packets, considering the typical packetization times. 
Using send(MSG_MORE) + sendfile would definitely be slower than a single 
sendmsg() in such case, because the per-packet memcpy() will be quite short.

Video streaming typically does send lots of large packets, and might well read 
the data from a mmap-able file. But video streaming protocols such as RTP 
typically try to avoid fragmentation, so large sendfile() won't work.

> > > If you want send a large file over UDP, the typical code will be like:
> > >
> > > while (...) {
> > >         sendmsg(fd, &apl_header, sizeof(apl_header), MSG_MORE);
> > >         offset += sendfile(fd, offset, count);
> > > }
> >
> > Correct me if I am wrong, but... Unless you have a big MTU (as _not_ in
> > 1500 bytes :D), doing an extra syscall might be slower than copying data
> > in a single vectorized sendmsg() syscall.
>
> That's not true.
> Even if the MTU is small, you can send a UDP message whose size can be
> up to 64KB at once. They will be split into several IP packets without
> any copies.

And you will encounter fragmentation, which sucks at high data rates.
As for low rates, you typically would not bother to optimize memcpy. But more 
importantly, you should not assume that the other end is only talking to 
you - it might as well be talking to many different people and not appreciate 
if all of them send lots of fragments.

And lets not get into how poorly fragmentation works through middleboxes...

> And more, copying data will pollute the cache memory much, which cannot
> be ignored if you want send tons of data of files.

-- 
Rémi Denis-Courmont
http://www.remlab.net/

  reply	other threads:[~2008-09-19 13:14 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-14 10:25 [PATCH] sendfile() and UDP socket Johann Baudy
2008-09-16  4:17 ` Simon Horman
2008-09-16  4:24   ` Simon Horman
2008-09-16 12:01 ` Hirokazu Takahashi
2008-09-18 17:31   ` Rémi Denis-Courmont
2008-09-19 12:28     ` Hirokazu Takahashi
2008-09-19 13:14       ` Rémi Denis-Courmont [this message]
2008-09-21  8:04 ` David Miller
2008-09-22  0:21   ` Evgeniy Polyakov
2008-09-22  0:44     ` David Miller
2008-09-22  1:08       ` Evgeniy Polyakov
2008-09-22  2:07         ` David Miller
2008-09-22  4:19           ` Evgeniy Polyakov
2008-09-22  4:27             ` David Miller
2008-09-22  4:40               ` Evgeniy Polyakov
2008-09-22  5:06                 ` David Miller
2008-09-22  5:49                   ` Evgeniy Polyakov
2008-09-22  6:54                     ` David Miller
2008-09-22  7:04                       ` Evgeniy Polyakov
2008-09-23  4:54                         ` Herbert Xu
2008-09-23  6:27                           ` Evgeniy Polyakov
2008-09-23  7:01                             ` Herbert Xu
2008-09-23  7:07                               ` Evgeniy Polyakov
2008-09-24  4:53                               ` Bill Fink
     [not found]                                 ` <7e0dd21a0810140009k49c8876ax66f744d0a3a4931b@mail.gmail.com>
2008-10-14  7:10                                   ` Johann Baudy
2008-09-25 13:03             ` Using skb_get() to recycle skbs Ram.Natarajan
2008-09-25 14:28               ` Evgeniy Polyakov
  -- strict thread matches above, loose matches on Subject: below --
2008-09-10 12:39 [PATCH] sendfile() and UDP socket Johann Baudy
2008-09-10 20:16 ` David Miller

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=200809191614.14763.rdenis@simphalempin.com \
    --to=rdenis@simphalempin.com \
    --cc=johaahn@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=taka@valinux.co.jp \
    /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;
as well as URLs for NNTP newsgroup(s).