httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@trudge.engr.sgi.com (Mike Abbott)
Subject [PATCH] 10x performance increase patch #6
Date Wed, 21 Jul 1999 05:06:58 GMT
Apache Developers,

Here is my sixth patch increasing Apache's performance.  This one
eliminates the getsockname() system call per request when possible.

The base for this patch is Apache/1.3.6 + 10x performance increase
patches #1 through #5.

As always, I welcome your review, questions, and feedback.
--
Michael J. Abbott    mja@sgi.com

========================================================================

diff -Naur apache_1.3.6+01-05/src/include/httpd.h apache_1.3.6+01-06/src/include/httpd.h
--- apache_1.3.6+01-05/src/include/httpd.h	Tue Jul 20 16:26:22 1999
+++ apache_1.3.6+01-06/src/include/httpd.h	Tue Jul 20 17:14:58 1999
@@ -917,6 +917,7 @@
     struct sockaddr_in local_addr;	/* local IP address and port */
     int fd;
     int used;			/* Only used during restart */
+    int unique;			/* is local_addr unique (not wild)? */
 /* more stuff here, like which protocol is bound to the port */
 };
 
diff -Naur apache_1.3.6+01-05/src/main/http_config.c apache_1.3.6+01-06/src/main/http_config.c
--- apache_1.3.6+01-05/src/main/http_config.c	Thu Jul  8 12:17:08 1999
+++ apache_1.3.6+01-06/src/main/http_config.c	Tue Jul 20 21:53:50 1999
@@ -1454,6 +1454,7 @@
     new->local_addr.sin_port = htons(s->port ? s->port : DEFAULT_HTTP_PORT);
     new->fd = -1;
     new->used = 0;
+    new->unique = new->local_addr.sin_addr.s_addr != htonl(INADDR_ANY);
     new->next = NULL;
     ap_listeners = new;
 }
diff -Naur apache_1.3.6+01-05/src/main/http_core.c apache_1.3.6+01-06/src/main/http_core.c
--- apache_1.3.6+01-05/src/main/http_core.c	Thu Jul  8 13:34:58 1999
+++ apache_1.3.6+01-06/src/main/http_core.c	Tue Jul 20 21:53:50 1999
@@ -2422,6 +2422,7 @@
     new->local_addr.sin_port = htons(port);
     new->fd = -1;
     new->used = 0;
+    new->unique = new->local_addr.sin_addr.s_addr != htonl(INADDR_ANY);
     new->next = ap_listeners;
     ap_listeners = new;
     return NULL;
diff -Naur apache_1.3.6+01-05/src/main/http_main.c apache_1.3.6+01-06/src/main/http_main.c
--- apache_1.3.6+01-05/src/main/http_main.c	Tue Jul 20 16:29:00 1999
+++ apache_1.3.6+01-06/src/main/http_main.c	Tue Jul 20 17:17:27 1999
@@ -289,7 +289,7 @@
 
 static server_rec *server_conf;
 static JMP_BUF APACHE_TLS jmpbuffer;
-static int sd;
+static listen_rec *listener;
 static fd_set listenfds;
 static int listenmaxfd;
 static pid_t pgrp;
@@ -3789,11 +3789,11 @@
 		lr = find_ready_listener(&main_fds);
 		if (lr == NULL)
 		    continue;
-		sd = lr->fd;
+		listener = lr;
 	    }
 	    else {
 		/* only one socket, just pretend we did the other stuff */
-		sd = ap_listeners->fd;
+		listener = head_listener;
 	    }
 
 	    /* if we accept() something we don't want to die, so we have to
@@ -3805,7 +3805,7 @@
 #endif
 	    for (;;) {
 		clen = sizeof(sa_client);
-		csd = accept(sd, &sa_client, &clen);
+		csd = accept(listener->fd, &sa_client, &clen);
 		if (csd >= 0 || errno != EINTR)
 		    break;
 #ifndef NO_GRACEFUL
@@ -3921,10 +3921,23 @@
 	 * socket options, file descriptors, and read/write buffers.
 	 */
 
-	clen = sizeof(sa_server);
-	if (getsockname(csd, &sa_server, &clen) < 0) {
-	    ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "getsockname");
-	    continue;
+	if (listener->unique) {
+	    /*
+	     * The connection was accepted from a socket listening to
+	     * just one address so we don't need to call getsockname().
+	     */
+	    sa_server = *((struct sockaddr *) &listener->local_addr);
+	} else {
+	    /*
+	     * The connection was accepted from a socket listening to
+	     * multiple addresses so we need to find out which one
+	     * provided.
+	     */
+	    clen = sizeof(sa_server);
+	    if (getsockname(csd, &sa_server, &clen) < 0) {
+		ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "getsockname");
+		continue;
+	    }
 	}
 
 	sock_disable_nagle(csd);
@@ -5298,7 +5311,7 @@
     pchild = ap_make_sub_pool(pconf);
 
     ap_standalone = 1;
-    sd = -1;
+    listener = NULL;
     nthreads = ap_threads_per_child;
     max_jobs_after_exit_request = ap_excess_requests_per_child;
     max_jobs_per_exe = ap_max_requests_per_child;
@@ -5470,12 +5483,12 @@
 
 	    lr = find_ready_listener(&main_fds);
 	    if (lr != NULL) {
-		sd = lr->fd;
+		listener = lr;
 	    }
 	}
 	do {
 	    clen = sizeof(sa_client);
-	    csd = accept(sd, (struct sockaddr *) &sa_client, &clen);
+	    csd = accept(listener ? listener->fd : -1, (struct sockaddr *) &sa_client, &clen);
 #ifdef WIN32
 	    if (csd == INVALID_SOCKET) {
 		csd = -1;

Mime
View raw message