After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 500150 - [filesink] add property to enable buffering via setvbuf()
[filesink] add property to enable buffering via setvbuf()
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal enhancement
: 0.10.16
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2007-11-28 08:17 UTC by Laurent Glayal
Modified: 2007-12-24 19:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
buffering option (3.64 KB, patch)
2007-11-28 08:17 UTC, Laurent Glayal
needs-work Details | Review
check for stdio_ext.h and getpagesize() function (329 bytes, patch)
2007-12-07 14:45 UTC, Laurent Glayal
none Details | Review
use autoconf checking to use buffering (1.85 KB, patch)
2007-12-07 14:46 UTC, Laurent Glayal
none Details | Review
configure.ac : check for stdio_ext.h and getpagesize() function (754 bytes, patch)
2007-12-10 10:00 UTC, Laurent Glayal
committed Details | Review
gstfilesink.c : use autoconf checking to use buffering (3.43 KB, patch)
2007-12-10 10:09 UTC, Laurent Glayal
committed Details | Review

Description Laurent Glayal 2007-11-28 08:17:24 UTC
Patch to add call to setvbuf() on opened stream if requested by User. The size of the buffer is set by indicating the number of memory pages.
Comment 1 Laurent Glayal 2007-11-28 08:17:45 UTC
Created attachment 99761 [details] [review]
buffering option
Comment 2 Wim Taymans 2007-11-30 11:38:21 UTC
does this patch improve performance in a measurable way?
Comment 3 Laurent Glayal 2007-11-30 12:27:38 UTC
Yes, we use record over NFS for a large number of files (over 100 simultaneously) and for buffers of 20 milliseconds duration. To avoid too many system call, context switching and so on we use this patch. 

Some comparisons :
[root@testg5 /tmp]$strace -f -v gst-launch audiotestsrc num-buffers=10000 ! filesink location=/tmp/t.dat buffer-size=10 2>&1 | grep write | wc -l
525
[root@testg5 /tmp]$strace -f -v gst-launch audiotestsrc num-buffers=10000 ! filesink location=/tmp/t.dat 2>&1 | grep write | wc -l
5023

For us reducing the number of writes reduces overhead on the nfs client and on the nfs server. We also reduce side effect of context switch on the system.
Comment 4 Tim-Philipp Müller 2007-12-06 20:02:35 UTC
Doesn't look particularly portable in its current form (getpagesize, __fbufsize).
Comment 5 Laurent Glayal 2007-12-07 08:28:38 UTC
Right. getpagesize() could be replaced by sysconf() but i don't know if there is a POSIX equivalent to __fbufsize().
Comment 6 Tim-Philipp Müller 2007-12-07 10:29:37 UTC
It's ok to use these things IMO, as long as you add the necessary checks to configure.ac and make sure you #ifdef stuff as appropriate.
Comment 7 Laurent Glayal 2007-12-07 14:45:51 UTC
Created attachment 100527 [details] [review]
check for stdio_ext.h and getpagesize() function
Comment 8 Laurent Glayal 2007-12-07 14:46:46 UTC
Created attachment 100528 [details] [review]
use autoconf checking to use buffering
Comment 9 Laurent Glayal 2007-12-07 14:47:25 UTC
done. Buffering only allowed if getpagesize is available.
Comment 10 David Schleef 2007-12-07 23:01:29 UTC
The buffer size property should be in bytes, not pages.

I have a minor preference for encouraging the use of a reblocking element instead of a property on filesink.

And, if we decide to add this property, I have a minor preference for making setvbuf() the default, with a reasonable buffer size.  Maybe 64kB or so.

Please create patches with 'cvs diff -u'.  Better yet, add 'diff -u' to your ~/.cvsrc.
Comment 11 Laurent Glayal 2007-12-10 10:00:05 UTC
Created attachment 100681 [details] [review]
configure.ac : check for stdio_ext.h and getpagesize() function
Comment 12 Laurent Glayal 2007-12-10 10:09:37 UTC
Created attachment 100682 [details] [review]
gstfilesink.c : use autoconf checking to use buffering
Comment 13 Laurent Glayal 2007-12-10 10:23:36 UTC
Disabling buffering can be useful when you want to smooth I/O ( on local or network FS for ex. and working with large buffers) or reduce amount of data lost in case of process failure. So defaulting to setvbuf may not be a good thing (IMHO).

Switching from pages to bytes unit is not a problem, this way there is no more need to getpagesize(). 
Comment 14 Wim Taymans 2007-12-24 19:15:44 UTC
Commited with these changes:

  - buffer-mode can be controlled. This allows for unbuffered, line and fully
    buffered modes. The default is to not configure any buffering with setvbuf
    and just leave the defaults (which seems to be 4K buffering for files, line
    buffering for teminals, unbuffered for stderr).
  - buffer-size in bytes. There is a default of 64K buffer, enabled when
    buffer-mode is set to the required kind of buffering.
  - the check for getpagesize in configure.ac was not needed anymore.

This should allow you to configure all options of setvbuf.


        Based on Patch by: Laurent Glayal <spglegle at yahoo dot fr>

        * configure.ac:
        Check for stdio_ext.h for the filesink changes.

        * plugins/elements/gstfilesink.c: (buffer_mode_get_type),
        (gst_file_sink_class_init), (gst_file_sink_init),
        (gst_file_sink_dispose), (gst_file_sink_set_property),
        (gst_file_sink_get_property), (gst_file_sink_open_file),
        (gst_file_sink_close_file):
        * plugins/elements/gstfilesink.h:
        Add two properties to control the buffering mode and size.
        API: GstFileSink::buffer-mode
        API: GstFileSink::buffer-size