Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 7758 invoked by uid 500); 5 Jul 2002 21:20:51 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Delivered-To: moderator for dev@apr.apache.org Received: (qmail 7609 invoked from network); 5 Jul 2002 08:48:47 -0000 Date: Fri, 5 Jul 2002 04:47:07 -0400 (EDT) From: rbb@apache.org X-Sender: rbb@shell.ntrnet.net To: dev@apr.apache.org Cc: Ian Holsman Subject: Re: [PATCH] speed up network timeout processing In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Here is the patch to use apr_poll instead of select. This is just being posted for completeness, not because I believe it will actually perform as well as the standard poll() implementation. Bill offered to benchmark it, so I am posting it. I will re-implement apr_poll() tomorrow to offer much better performance, and I will post a new patch based on that sometime tomorrow. Once we have actual numbers for all three implementations of wait_for_io_or_timeout, we can have an intelligent conversation about the best one to use, based on code complexity and performance. Ryan Index: network_io/unix/sendrecv.c =================================================================== RCS file: /home/cvs/apr/network_io/unix/sendrecv.c,v retrieving revision 1.85 diff -u -d -b -w -u -r1.85 sendrecv.c --- network_io/unix/sendrecv.c 2 Jul 2002 21:33:43 -0000 1.85 +++ network_io/unix/sendrecv.c 5 Jul 2002 08:39:44 -0000 @@ -65,36 +65,33 @@ apr_status_t apr_wait_for_io_or_timeout(apr_socket_t *sock, int for_read) { - struct timeval tv, *tvptr; - fd_set fdset; int srv; + int n = 1; + apr_pool_t *p; + apr_pollfd_t *pollset; + int type = for_read ? APR_POLLIN : APR_POLLOUT; + apr_pool_create(&p, sock->cntxt); + apr_poll_setup(&pollset, 1, p); do { - FD_ZERO(&fdset); - FD_SET(sock->socketdes, &fdset); - if (sock->timeout < 0) { - tvptr = NULL; + apr_int16_t result; + apr_poll_socket_add(pollset, sock, type); + srv = apr_poll(pollset, &n, sock->timeout); + + if (srv != APR_SUCCESS && APR_STATUS_IS_EINTR(srv)) { + continue; } - else { - tv.tv_sec = sock->timeout / APR_USEC_PER_SEC; - tv.tv_usec = sock->timeout % APR_USEC_PER_SEC; - tvptr = &tv; + apr_poll_revents_get(&result, sock, pollset); + if ((result & type) || APR_STATUS_IS_TIMEUP(srv)) { + break; } - srv = select(sock->socketdes + 1, - for_read ? &fdset : NULL, - for_read ? NULL : &fdset, - NULL, - tvptr); + /* TODO - timeout should be smaller on repeats of this loop */ - } while (srv == -1 && errno == EINTR); + } while (1); - if (srv == 0) { - return APR_TIMEUP; - } - else if (srv < 0) { - return errno; - } - return APR_SUCCESS; + apr_pool_destroy(p); + + return srv; } apr_status_t apr_send(apr_socket_t *sock, const char *buf, apr_size_t *len) _______________________________________________________________________________ Ryan Bloom rbb@apache.org 550 Jean St Oakland CA 94610 -------------------------------------------------------------------------------