httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk-Willem van Gulik <Dirk.vanGu...@jrc.it>
Subject [PATCH] move cleanup in proxy to later stage
Date Mon, 08 Mar 1999 20:47:19 GMT
Small patch, only cursory testing on FreeBSD which moves the
fork&detach prior to cleanup to _after_ the main 'is it time' 
yet check. So as to avoid fork()ing needlessly after too many 
a request. Needs a bit of scrutiny as I also simplifed the 
signal block a bit, and am not that familiar with this code.

Dw.

diff -c3 -r apache-work/apache-1.3/src/modules/proxy/proxy_cache.c apache/apache-1.3/src/modules/proxy/proxy_cache.c
*** apache-work/apache-1.3/src/modules/proxy/proxy_cache.c      Sun Feb 
7 15:48:31 1999
--- apache/apache-1.3/src/modules/proxy/proxy_cache.c   Mon Mar  8
08:30:20 1999
***************
*** 118,126 ****
  
  static int sub_garbage_coll(request_rec *r, array_header *files,
                            const char *cachedir, const char *cachesubdir);
! static void help_proxy_garbage_coll(request_rec *r);
  #if !defined(WIN32) && !defined(MPE) && !defined(OS2)
! static void detached_proxy_garbage_coll(request_rec *r);
  #endif
  
  
--- 118,129 ----
  
  static int sub_garbage_coll(request_rec *r, array_header *files,
                            const char *cachedir, const char *cachesubdir);
! 
! static int need_proxy_garbage_coll(request_rec *r);
! static void do_proxy_garbage_coll(request_rec *r);
! 
  #if !defined(WIN32) && !defined(MPE) && !defined(OS2)
! static void detached_do_proxy_garbage_coll(request_rec *r);
  #endif
  
  
***************
*** 137,149 ****
        inside = 1;
      (void) ap_release_mutex(garbage_mutex);
  
!     ap_block_alarms();                /* avoid SIGALRM on big cache
cleanup */
  #if !defined(WIN32) && !defined(MPE) && !defined(OS2)
!     detached_proxy_garbage_coll(r);
  #else
!     help_proxy_garbage_coll(r);
! #endif
!     ap_unblock_alarms();
  
      (void) ap_acquire_mutex(garbage_mutex);
      inside = 0;
--- 140,155 ----
        inside = 1;
      (void) ap_release_mutex(garbage_mutex);
  
!     if (need_proxy_garbage_coll(r) > 0) {
!       ap_block_alarms();              /* avoid SIGALRM on big cache
cleanup */
! 
  #if !defined(WIN32) && !defined(MPE) && !defined(OS2)
!       detached_do_proxy_garbage_coll(r);
  #else
!       do_proxy_garbage_coll(r);
! #endif        
!       ap_unblock_alarms();
!       };
  
      (void) ap_acquire_mutex(garbage_mutex);
      inside = 0;
***************
*** 199,205 ****
  }
  
  #if !defined(WIN32) && !defined(MPE) && !defined(OS2)
! static void detached_proxy_garbage_coll(request_rec *r)
  {
      pid_t pid;
      int status;
--- 205,211 ----
  }
  
  #if !defined(WIN32) && !defined(MPE) && !defined(OS2)
! static void detached_do_proxy_garbage_coll(request_rec *r)
  {
      pid_t pid;
      int status;
***************
*** 247,253 ****
                        exit(1);
                    }
  #endif
!                   help_proxy_garbage_coll(r);
                    exit(0);
  
                default:    /* Father */
--- 253,259 ----
                        exit(1);
                    }
  #endif
!                   do_proxy_garbage_coll(r);
                    exit(0);
  
                default:    /* Father */
***************
*** 264,280 ****
  }
  #endif /* ndef WIN32 */
  
! static void help_proxy_garbage_coll(request_rec *r)
  {
      const char *cachedir;
      void *sconf = r->server->module_config;
      proxy_server_conf *pconf =
      (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
      const struct cache_conf *conf = &pconf->cache;
-     array_header *files;
      struct stat buf;
!     struct gc_ent *fent;
!     int i, timefd;
      static time_t lastcheck = BAD_DATE;               /* static
(per-process) data!!! */
  
      cachedir = conf->root;
--- 270,284 ----
  }
  #endif /* ndef WIN32 */
  
! static int need_proxy_garbage_coll(request_rec *r)
  {
      const char *cachedir;
      void *sconf = r->server->module_config;
      proxy_server_conf *pconf =
      (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
      const struct cache_conf *conf = &pconf->cache;
      struct stat buf;
!     int timefd;
      static time_t lastcheck = BAD_DATE;               /* static
(per-process) data!!! */
  
      cachedir = conf->root;
***************
*** 284,300 ****
      every = conf->gcinterval;
  
      if (cachedir == NULL || every == -1)
!       return;
      garbage_now = time(NULL);
      /* Usually, the modification time of <cachedir>/.time can only increase.
       * Thus, even with several child processes having their own copy of
       * lastcheck, if time(NULL) still < lastcheck then it's not time
       * for GC yet.
       */
!     if (garbage_now != -1 && lastcheck != BAD_DATE && garbage_now <
lastcheck + every)
!       return;
  
!     ap_block_alarms();                /* avoid SIGALRM on big cache
cleanup */
  
      filename = ap_palloc(r->pool, strlen(cachedir) + HASH_LEN + 2);
      strcpy(filename, cachedir);
--- 288,309 ----
      every = conf->gcinterval;
  
      if (cachedir == NULL || every == -1)
!       return 0;
! 
      garbage_now = time(NULL);
      /* Usually, the modification time of <cachedir>/.time can only increase.
       * Thus, even with several child processes having their own copy of
       * lastcheck, if time(NULL) still < lastcheck then it's not time
       * for GC yet.
       */
!     if (garbage_now < 0) {
!       ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
!                "proxy: time(%s)", filename);
!       return 0;
!       }
  
!     if (lastcheck != BAD_DATE && garbage_now < lastcheck + every)
!       return 0;
  
      filename = ap_palloc(r->pool, strlen(cachedir) + HASH_LEN + 2);
      strcpy(filename, cachedir);
***************
*** 303,310 ****
        if (errno != ENOENT) {
            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
                         "proxy: stat(%s)", filename);
!           ap_unblock_alarms();
!           return;
        }
        if ((timefd = creat(filename, 0666)) == -1) {
            if (errno != EEXIST)
--- 312,318 ----
        if (errno != ENOENT) {
            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
                         "proxy: stat(%s)", filename);
!           return 0;
        }
        if ((timefd = creat(filename, 0666)) == -1) {
            if (errno != EEXIST)
***************
*** 312,332 ****
                             "proxy: creat(%s)", filename);
            else
                lastcheck = garbage_now;        /* someone else got in
there */
!           ap_unblock_alarms();
!           return;
        }
        close(timefd);
      }
      else {
        lastcheck = buf.st_mtime;       /* save the time */
        if (garbage_now < lastcheck + every) {
!           ap_unblock_alarms();
!           return;
        }
        if (utime(filename, NULL) == -1)
            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
                         "proxy: utimes(%s)", filename);
      }
      files = ap_make_array(r->pool, 100, sizeof(struct gc_ent));
      curbytes.upper = curbytes.lower = 0L;
  
--- 320,354 ----
                             "proxy: creat(%s)", filename);
            else
                lastcheck = garbage_now;        /* someone else got in
there */
!           return 0;
        }
        close(timefd);
      }
      else {
        lastcheck = buf.st_mtime;       /* save the time */
        if (garbage_now < lastcheck + every) {
!           return 0;
        }
        if (utime(filename, NULL) == -1)
            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
                         "proxy: utimes(%s)", filename);
      }
+ 
+     return 1;
+ }
+ 
+ static void do_proxy_garbage_coll(request_rec *r)
+ {
+     void *sconf = r->server->module_config;
+     proxy_server_conf *pconf =
+     (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+     const struct cache_conf *conf = &pconf->cache;
+     array_header *files;
+     struct gc_ent *fent;
+     int i;
+     const char *cachedir = conf->root;
+ 
+ 
      files = ap_make_array(r->pool, 100, sizeof(struct gc_ent));
      curbytes.upper = curbytes.lower = 0L;
  
***************
*** 336,342 ****
        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
                         "proxy GC: Cache is %ld%% full (nothing deleted)",
                         (long)(((curbytes.upper<<20)|(curbytes.lower>>10))*100/conf->space));
-       ap_unblock_alarms();
        return;
      }
  
--- 358,363 ----
***************
*** 367,373 ****
      ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
                         "proxy GC: Cache is %ld%% full (%d deleted)",
                        
(long)(((curbytes.upper<<20)|(curbytes.lower>>10))*100/conf->space), i);
!     ap_unblock_alarms();
  }
  
  static int sub_garbage_coll(request_rec *r, array_header *files,
--- 388,394 ----
      ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
                         "proxy GC: Cache is %ld%% full (%d deleted)",
                        
(long)(((curbytes.upper<<20)|(curbytes.lower>>10))*100/conf->space), i);
! 
  }
  
  static int sub_garbage_coll(request_rec *r, array_header *files,

Mime
View raw message