Bug 44193 - Inefficient apr_file_copy() buffer size
Summary: Inefficient apr_file_copy() buffer size
Status: RESOLVED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: All All
: P2 normal with 1 vote (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-09 12:26 UTC by kmradke
Modified: 2008-04-24 00:03 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kmradke 2008-01-09 12:26:42 UTC
The function apr_file_transfer_contents() called by apr_file_copy() in 
file_io/unix/copy.c uses the standard BUFSIZ constant as a buffer size to copy 
file contents.

This can be very inefficient on large files when done over a network due to 
the numerous small packets sent.  This standard constant is typically very 
small.  (512 is the default on windows.)

It is suggested to use the existing APR_FILE_BUFSIZE contant which defaults to 
a larger value of 4096 on Windows, or create a new constant such as 
APR_COPY_BUFSIZE which can be configured to an appropriately large size per 
platform.

Using a larger buffer can increase copy times of larger files by over 2x when 
done on a network prototol such as NFS or SMB.

The performance problem was originally seen when using Subversion.  Some 
background discussion is available at these locations:

http://subversion.tigris.org/servlets/ReadMsg?listName=dev&msgNo=82087
http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=133582

Here is the suggest patch:

--- copy-old.c  2008-01-09 14:07:51.000068000 -0600
+++ copy.c      2008-01-09 14:08:25.000121000 -0600
@@ -54,7 +54,7 @@

     /* Copy bytes till the cows come home. */
     while (1) {
-        char buf[BUFSIZ];
+        char buf[APR_FILE_BUFSIZE];
         apr_size_t bytes_this_time = sizeof(buf);
         apr_status_t read_err;
         apr_status_t write_err;
Comment 1 Bojan Smojver 2008-04-24 00:03:58 UTC
Fixed in trunk in r651174.