httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Victor J. Orlikowski" <v.j.orlikow...@gte.net>
Subject Re: woah, "GET /" with autoindex
Date Wed, 10 Jan 2001 22:24:58 GMT
(*blink blink*)
Huh?
(victor scrounges around. darn - not on his backup cd's...maybe in
new-httpd archives - yes....)

Sorry - re-packaging old source from another project rots the brain.

This patch was only a preliminary idea, and showed slightly better
performance, but it is still up for improvement. I've updated it to
work against the current build tree.

Index: include/httpd.h
===================================================================
RCS file: /cvs/apache/httpd-2.0/include/httpd.h,v
retrieving revision 1.129
diff -u -d -r1.129 httpd.h
--- httpd.h	2001/01/05 20:44:39	1.129
+++ httpd.h	2001/01/10 22:25:26
@@ -809,6 +809,18 @@
     /** A flag to determine if the eos bucket has been sent yet
      *  @defvar int eos_sent */
     int eos_sent;
+    /** A buffer to hold data to be coalesced into a reasonable size bucket
+     *  @defvar char *coalesce_buf */
+    char *coalesce_buf;
+    /** A pointer to the current position in coalesce_buf
+     *  @defvar char *coalesce_buf_cur */
+    char *coalesce_buf_cur;
+    /** Space used in coalesce_buf
+     * @defvar apr_size_t coalesce_cnt */
+    apr_size_t coalesce_cnt;
+    /** Space remaining in coalesce_buf
+     * @defvar apr_size_t coalesce_avail */
+    apr_size_t coalesce_avail;
 
 /* Things placed at the end of the record to avoid breaking binary
  * compatibility.  It would be nice to remember to reorder the entire
Index: modules/http/http_protocol.c
===================================================================
RCS file: /cvs/apache/httpd-2.0/modules/http/http_protocol.c,v
retrieving revision 1.265
diff -u -d -r1.265 http_protocol.c
--- http_protocol.c	2001/01/02 19:22:09	1.265
+++ http_protocol.c	2001/01/10 22:25:29
@@ -1466,6 +1466,10 @@
     r->the_request     = NULL;
     r->output_filters  = conn->output_filters;
     r->input_filters   = conn->input_filters;
+    r->coalesce_buf    = apr_pcalloc(r->pool, MAX_STRING_LEN);
+    r->coalesce_buf_cur = r->coalesce_buf;
+    r->coalesce_cnt    = 0;
+    r->coalesce_avail  = MAX_STRING_LEN;
 
     apr_setsocketopt(conn->client_socket, APR_SO_TIMEOUT, 
                      (int)(conn->keptalive
@@ -2678,6 +2682,7 @@
         r = r->next;
     }
     /* tell the filter chain there is no more content coming */
+    ap_rflush(r);
     if (!r->eos_sent) {
         end_output_stream(r);
     }
@@ -2995,29 +3000,70 @@
 }
 #endif /* APR_HAS_MMAP */
 
+#define RMIN_BUCKET_SIZE 4096
+static void coalesce_buf_create_bucket(request_rec *r, ap_bucket_brigade *bb)
+{
+    ap_bucket *b = ap_bucket_create_transient(r->coalesce_buf, r->coalesce_cnt);
+    AP_BRIGADE_INSERT_TAIL(bb, b);
+    r->coalesce_buf_cur = r->coalesce_buf;
+    r->coalesce_cnt = 0;
+    r->coalesce_avail = MAX_STRING_LEN;
+}
+
+static void coalesce_buf_insertc(request_rec *r, char c)
+{
+    *r->coalesce_buf_cur = c;
+    r->coalesce_buf_cur++;
+    r->coalesce_cnt++;
+    r->coalesce_avail--;
+}
+
+static void coalesce_buf_insertb(request_rec *r, ap_bucket_brigade *bb, 
+                                 const void *buf, int len)
+{
+    ap_bucket *b;
+
+    if (len < RMIN_BUCKET_SIZE) {
+        if (len > r->coalesce_avail) {
+            bb = ap_brigade_create(r->pool);
+            coalesce_buf_create_bucket(r, bb);
+        }
+        memcpy(r->coalesce_buf_cur, buf, len);
+        r->coalesce_cnt += len;
+        r->coalesce_buf_cur += len;
+        r->coalesce_avail -= len;
+    }
+    else {
+        bb = ap_brigade_create(r->pool);
+        coalesce_buf_create_bucket(r, bb);
+        b = ap_bucket_create_transient(buf, len);
+        AP_BRIGADE_INSERT_TAIL(bb, b);
+    }
+}
+
 AP_DECLARE(int) ap_rputc(int c, request_rec *r)
 {
     ap_bucket_brigade *bb = NULL;
-    ap_bucket *b;
     char c2 = (char)c;
 
     if (r->connection->aborted) {
 	return EOF;
     }
 
+    if (r->coalesce_avail == 0) {
     bb = ap_brigade_create(r->pool);
-    b = ap_bucket_create_transient(&c2, 1);
-    AP_BRIGADE_INSERT_TAIL(bb, b);
+        coalesce_buf_create_bucket(r, bb);
     ap_pass_brigade(r->output_filters, bb);
+    }
 
+    coalesce_buf_insertc(r, c2);
     return c;
 }
 
 AP_DECLARE(int) ap_rputs(const char *str, request_rec *r)
 {
     ap_bucket_brigade *bb = NULL;
-    ap_bucket *b;
-    apr_size_t len;
+    int len;
 
     if (r->connection->aborted)
         return EOF;
@@ -3025,9 +3071,9 @@
         return 0;
 
     len = strlen(str);
-    bb = ap_brigade_create(r->pool);
-    b = ap_bucket_create_transient(str, len);
-    AP_BRIGADE_INSERT_TAIL(bb, b);
+
+    coalesce_buf_insertb(r, bb, str, len);
+    if (bb)
     ap_pass_brigade(r->output_filters, bb);
 
     return len;
@@ -3036,17 +3082,16 @@
 AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r)
 {
     ap_bucket_brigade *bb = NULL;
-    ap_bucket *b;
 
     if (r->connection->aborted)
         return EOF;
     if (nbyte == 0)
         return 0;
 
-    bb = ap_brigade_create(r->pool);
-    b = ap_bucket_create_transient(buf, nbyte);
-    AP_BRIGADE_INSERT_TAIL(bb, b);
+    coalesce_buf_insertb(r, bb, buf, nbyte);
+    if (bb)
     ap_pass_brigade(r->output_filters, bb);
+
     return nbyte;
 }
 
@@ -3054,13 +3099,18 @@
 {
     ap_bucket_brigade *bb = NULL;
     apr_size_t written;
+    int send_it = 0;
 
     if (r->connection->aborted)
         return EOF;
 
     bb = ap_brigade_create(r->pool);
+    if (r->coalesce_cnt > 0) {
+        coalesce_buf_create_bucket(r, bb);
+        send_it = 1;
+    }
     written = ap_brigade_vprintf(bb, fmt, va);
-    if (written != 0)
+    if (written != 0 || send_it != 0)
         ap_pass_brigade(r->output_filters, bb);
     return written;
 }
@@ -3084,28 +3134,43 @@
 }
 
 AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r, ...)
-{
+ {
     ap_bucket_brigade *bb = NULL;
     apr_size_t written;
+    const char *str;
+    int len;
     va_list va;
 
     if (r->connection->aborted)
         return EOF;
-    bb = ap_brigade_create(r->pool);
+ 
     va_start(va, r);
-    written = ap_brigade_vputstrs(bb, va);
+    for (written = 0;;) {
+        str = va_arg(va, const char *);
+        if (str == NULL)
+            break;
+        len = strlen(str);
+        coalesce_buf_insertb(r, bb, str, len);
+        written += len;
+    }
     va_end(va);
-    if (written != 0)
+    if (written != 0 && bb)
         ap_pass_brigade(r->output_filters, bb);
     return written;
 }
 
 AP_DECLARE(int) ap_rflush(request_rec *r)
 {
-    /* we should be using a flush bucket to flush the stack, not buff code. */
     ap_bucket_brigade *bb;
     ap_bucket *b;
 
+    if (r->coalesce_cnt > 0) {
+        bb = ap_brigade_create(r->pool);
+        coalesce_buf_create_bucket(r, bb);
+        ap_pass_brigade(r->output_filters, bb);
+    }
+
+    /* we should be using a flush bucket to flush the stack, not buff code. */
     bb = ap_brigade_create(r->pool);
     b = ap_bucket_create_flush();
     AP_BRIGADE_INSERT_TAIL(bb, b);

Victor
-- 
Victor J. Orlikowski
======================
v.j.orlikowski@gte.net
vjo@raleigh.ibm.com
vjo@us.ibm.com


Mime
View raw message