Bug 49085 - [PATCH] Speed up file I/O
Summary: [PATCH] Speed up file I/O
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: 1.3.9
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-11 15:27 UTC by Stefan Fuhrmann
Modified: 2010-04-20 19:20 UTC (History)
0 users



Attachments
File I/O speedup patch (19.14 KB, patch)
2010-04-11 15:27 UTC, Stefan Fuhrmann
Details | Diff
File I/O speedup patch - v2 (24.70 KB, patch)
2010-04-20 19:17 UTC, Stefan Fuhrmann
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Fuhrmann 2010-04-11 15:27:31 UTC
Created attachment 25251 [details]
File I/O speedup patch

The current file I/O comes with large call overhead,
in particular under Windows. For some common usage
that translates into a large relative overhead.

These usages are: reading individual bytes (parser)
or writing small chunks of data (generator outputs).
If we are using non-buffered or multi-threaded files,
some larger sync / OS overhead is required in any 
case. So, we only optimize for the buffered, single-
threaded case.

Another optimization is not buffering large chunks
of data on the write path. That saves extra copies 
and does not pollute the data buffer.

[[[
Minimize relative overhead for buffered I/O of 
small data blocks. Also, eliminate mutex overhead
from single-threaded Win32 code.

* file_io/unix/readwrite.c
  (apr_file_write): add "shortcut" for small buffers;
  don't buffer large chunks at all
  (apr_file_putc, apr_file_getc): add shortcut 
  for the common case

* file_io/win32/readwrite.c
  (apr_file_read): use mutex only if the file is
  possibly accessed from multiple threads
  (apr_file_write_locked): new function, factored
  out from apr_file_flush
  (apr_file_write): defer OVERLAPPED handling;
  use mutex only if the file is possibly accessed 
  from multiple threads; add "shortcut" for small 
  buffers; don't buffer large chunks at all
  (apr_file_putc, apr_file_getc): add shortcut 
  for the common case
  (apr_file_flush): moved most code to 
  apr_file_write_locked

patch by stefanfuhrmann < at > alice-dsl.de
]]]
Comment 1 Stefan Fuhrmann 2010-04-20 19:17:15 UTC
Created attachment 25326 [details]
File I/O speedup patch - v2

update patch
Comment 2 Stefan Fuhrmann 2010-04-20 19:20:55 UTC
Updated patch comment:

[[[
Minimize relative overhead for buffered I/O of 
small data blocks. Also, eliminate mutex overhead
from single-threaded Win32 code.

* file_io/unix/readwrite.c
  (file_read_buffered): don't buffer large chunks at all
  (apr_file_write): add "shortcut" for small buffers;
  don't buffer large chunks at all
  (apr_file_putc, apr_file_getc): add shortcut 
  for the common case

* file_io/win32/readwrite.c
  (apr_file_read): use mutex only if the file is
  possibly accessed from multiple threads;
  don't buffer large chunks at all
  (apr_file_write_locked): new function, factored
  out from apr_file_flush
  (apr_file_write): defer OVERLAPPED handling;
  use mutex only if the file is possibly accessed 
  from multiple threads; add "shortcut" for small 
  buffers; don't buffer large chunks at all
  (apr_file_putc, apr_file_getc): add shortcut 
  for the common case
  (apr_file_flush): moved most code to 
  apr_file_write_locked

patch by stefanfuhrmann < at > alice-dsl.de
]]]