You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ed Korthof <ed...@organic.com> on 1997/01/31 17:51:25 UTC

[PATCH] Performance improvement for mod_include

Earlier, someone noted that mod_include still does a feof and ferror test
for every character read.  According to my a reference on C/C++ (I can't
find my K&R C book, so if anyone knows if this is true or not, please
say), getc returns EOF on either end of file or on error.  In the latter
case, the FILE * pointer has the appropriate error bit set; given that,
all we should need to test for is if we recieved EOF when we tried to get
the next character.

This patch fixes that.  Ideally, of course, it'd probably be better to
rewrite the whole section to mmap the file or use some other similarly
efficient system, but I don't have time to rewrite the code in each place
where the GET_CHAR macro is used.  It'd also make sense to try to figure
out what the error is, but I'm not sure what function to use to get the
error from the FILE * stream.

     -- Ed Korthof        |  Web Server Engineer --
     -- ed@organic.com    |  Organic Online, Inc --
     -- (415) 278-5676    |  Fax: (415) 284-6891 --

*** mod_include.c.orig	Mon Jan 20 00:00:16 1997
--- mod_include.c	Fri Jan 31 08:47:31 1997
***************
*** 116,122 ****
  #define GET_CHAR(f,c,r,p) \
   { \
     int i = getc(f); \
!    if(feof(f) || ferror(f) || (i == -1)) { \
          pfclose(p,f); \
          return r; \
     } \
--- 116,126 ----
  #define GET_CHAR(f,c,r,p) \
   { \
     int i = getc(f); \
!    if (i == EOF) { /* either EOF or error--needs error handling if latter */ \
!         if (ferror(f) && r && r->server) \
!         { \
!             log_printf(r->server,"error in GET_CHAR macro in mod_include"); \
!         } \
          pfclose(p,f); \
          return r; \
     } \


Re: [PATCH] Performance improvement for mod_include

Posted by Marc Slemko <ma...@znep.com>.
On Fri, 31 Jan 1997, Ed Korthof wrote:

> Earlier, someone noted that mod_include still does a feof and ferror test
> for every character read.  According to my a reference on C/C++ (I can't
> find my K&R C book, so if anyone knows if this is true or not, please
> say), getc returns EOF on either end of file or on error.  In the latter
> case, the FILE * pointer has the appropriate error bit set; given that,
> all we should need to test for is if we recieved EOF when we tried to get
> the next character.

Sounds reasonable to me.

> 
> This patch fixes that.  Ideally, of course, it'd probably be better to
> rewrite the whole section to mmap the file or use some other similarly
> efficient system, but I don't have time to rewrite the code in each place
> where the GET_CHAR macro is used.  It'd also make sense to try to figure
> out what the error is, but I'm not sure what function to use to get the
> error from the FILE * stream.

I haven't looked at the code, but we really shouldn't have to mmap this to
get decent performance, although there shouldn't be too many problems with
mmap if we are just reading (ie. most of the trouble on various platforms
comes in with multiple read and write accesses, size changes, etc.).  mmap
is already (optionally) used for the scoreboard.

Would it be possible to change GET_CHAR to read a block at a time, and
just dole it out a char at a time, reading more as needed?

> 
>      -- Ed Korthof        |  Web Server Engineer --
>      -- ed@organic.com    |  Organic Online, Inc --
>      -- (415) 278-5676    |  Fax: (415) 284-6891 --
> 
> *** mod_include.c.orig	Mon Jan 20 00:00:16 1997
> --- mod_include.c	Fri Jan 31 08:47:31 1997
> ***************
> *** 116,122 ****
>   #define GET_CHAR(f,c,r,p) \
>    { \
>      int i = getc(f); \
> !    if(feof(f) || ferror(f) || (i == -1)) { \
>           pfclose(p,f); \
>           return r; \
>      } \
> --- 116,126 ----
>   #define GET_CHAR(f,c,r,p) \
>    { \
>      int i = getc(f); \
> !    if (i == EOF) { /* either EOF or error--needs error handling if latter */ \
> !         if (ferror(f) && r && r->server) \
> !         { \
> !             log_printf(r->server,"error in GET_CHAR macro in mod_include"); \
> !         } \
>           pfclose(p,f); \
>           return r; \
>      } \
> 


Re: [PATCH] Performance improvement for mod_include

Posted by ra...@mail1.bellglobal.com.
> Do we really want to implement a mmap interface or couldn't we just point
> people at an mmap-based stdlib dropin... i.e. do we feel like dealing with
> the portability issues.

I am not sure there are a lot of portability issues here.  As long as we
have the ability to turn off mmap, I don't see a problem.

-Rasmus


Re: [PATCH] Performance improvement for mod_include

Posted by Dean Gaudet <dg...@arctic.org>.
Do we really want to implement a mmap interface or couldn't we just point
people at an mmap-based stdlib dropin... i.e. do we feel like dealing with
the portability issues.

Dean

On Fri, 31 Jan 1997, Ed Korthof wrote:

> Earlier, someone noted that mod_include still does a feof and ferror test
> for every character read.  According to my a reference on C/C++ (I can't
> find my K&R C book, so if anyone knows if this is true or not, please
> say), getc returns EOF on either end of file or on error.  In the latter
> case, the FILE * pointer has the appropriate error bit set; given that,
> all we should need to test for is if we recieved EOF when we tried to get
> the next character.
> 
> This patch fixes that.  Ideally, of course, it'd probably be better to
> rewrite the whole section to mmap the file or use some other similarly
> efficient system, but I don't have time to rewrite the code in each place
> where the GET_CHAR macro is used.  It'd also make sense to try to figure
> out what the error is, but I'm not sure what function to use to get the
> error from the FILE * stream.
> 
>      -- Ed Korthof        |  Web Server Engineer --
>      -- ed@organic.com    |  Organic Online, Inc --
>      -- (415) 278-5676    |  Fax: (415) 284-6891 --
> 
> *** mod_include.c.orig	Mon Jan 20 00:00:16 1997
> --- mod_include.c	Fri Jan 31 08:47:31 1997
> ***************
> *** 116,122 ****
>   #define GET_CHAR(f,c,r,p) \
>    { \
>      int i = getc(f); \
> !    if(feof(f) || ferror(f) || (i == -1)) { \
>           pfclose(p,f); \
>           return r; \
>      } \
> --- 116,126 ----
>   #define GET_CHAR(f,c,r,p) \
>    { \
>      int i = getc(f); \
> !    if (i == EOF) { /* either EOF or error--needs error handling if latter */ \
> !         if (ferror(f) && r && r->server) \
> !         { \
> !             log_printf(r->server,"error in GET_CHAR macro in mod_include"); \
> !         } \
>           pfclose(p,f); \
>           return r; \
>      } \
> 
>