Return-Path: Delivered-To: apmail-httpd-dev-archive@www.apache.org Received: (qmail 7613 invoked from network); 5 Dec 2004 21:50:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 5 Dec 2004 21:50:54 -0000 Received: (qmail 66848 invoked by uid 500); 5 Dec 2004 21:50:49 -0000 Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 66778 invoked by uid 500); 5 Dec 2004 21:50:48 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 66764 invoked by uid 99); 5 Dec 2004 21:50:48 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of jorton@redhat.com designates 66.187.233.31 as permitted sender) Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by apache.org (qpsmtpd/0.28) with ESMTP; Sun, 05 Dec 2004 13:50:48 -0800 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id iB5LokSR023968 for ; Sun, 5 Dec 2004 16:50:46 -0500 Received: from radish.cambridge.redhat.com (radish.cambridge.redhat.com [172.16.18.90]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id iB5Lojr09079 for ; Sun, 5 Dec 2004 16:50:45 -0500 Received: from radish.cambridge.redhat.com (localhost.localdomain [127.0.0.1]) by radish.cambridge.redhat.com (8.13.1/8.12.7) with ESMTP id iB5LoiB1018938 for ; Sun, 5 Dec 2004 21:50:44 GMT Received: (from jorton@localhost) by radish.cambridge.redhat.com (8.13.1/8.12.10/Submit) id iB5Loiud018937 for dev@httpd.apache.org; Sun, 5 Dec 2004 21:50:44 GMT Date: Sun, 5 Dec 2004 21:50:43 +0000 From: Joe Orton To: dev@httpd.apache.org Subject: Re: svn commit: r109866 - /httpd/httpd/trunk/modules/loggers/mod_log_config.c Message-ID: <20041205215043.GA18374@redhat.com> Mail-Followup-To: dev@httpd.apache.org References: <20041205070523.69174.qmail@minotaur.apache.org> <20041205134744.GA10093@redhat.com> <41B37684.2060506@force-elite.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="rwEMma7ioTxnRzrJ" Content-Disposition: inline In-Reply-To: <41B37684.2060506@force-elite.com> User-Agent: Mutt/1.4.1i X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --rwEMma7ioTxnRzrJ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On Sun, Dec 05, 2004 at 01:58:44PM -0700, Paul Querna wrote: > Joe Orton wrote: > >On Sun, Dec 05, 2004 at 07:05:23AM -0000, Paul Querna wrote: > > > >>Author: pquerna > >>Date: Sat Dec 4 23:05:23 2004 > >>New Revision: 109866 > >> > >>URL: http://svn.apache.org/viewcvs?view=rev&rev=109866 > >>Log: > >>mod_log_config.c: Use iovecs to write the log line to eliminate a memcpy > > > > > >IIRC, writev'ing several small blocks to a file is actually generally > >more expensive than doing a memcpy in userspace and calling write. Did > >you benchmark this to be faster/better/...? > > also that introduced a warning: mod_log_config.c: In function `ap_default_log_writer': mod_log_config.c:1353: warning: assignment discards qualifiers from pointer target type > I did a local mini-benchmark of write w/ memcpy vs writev... and they > came out to almost exactly the same on average with small sets of data. I remember I checked this before too... try the attached compiled with or without -DUSE_WRITEV, copy-and-write comes out about ~10-20% faster than writev on Linux 2.6/ext3 here for a real log vector, or did I screw up the benchmark? rm -f writev.out; sync; sleep 5 ./writev-copy copy+write: 7s330676. rm -f writev.out; sync; sleep 5 ./writev-copy copy+write: 7s327580. rm -f writev.out; sync; sleep 5 ./writev-copy copy+write: 7s360685. rm -f writev.out; sync; sleep 5 ./writev-writev writev: 8s893524. rm -f writev.out; sync; sleep 5 ./writev-writev writev: 8s808458. rm -f writev.out; sync; sleep 5 ./writev-writev writev: 9s052335. joe --rwEMma7ioTxnRzrJ Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="writev.c" #include #include #include #include #include #include #include #include char *strs[] = { "127.0.0.1", " ", "-", " ", "-", " ", "[22/Jul/2003:12:09:58 +0100]", " \"", "GET / HTTP/1.0", "\" ", "200", " ", "1456", "\n" }; #define NVECS (sizeof(strs) / sizeof(char *)) #define ITERS (1000000) #ifdef USE_WRITEV static void do_writev(int fd, struct iovec *vec, size_t nvec, size_t total) { ssize_t ret = writev(fd, vec, nvec); if (ret != total) { printf("writev got %d not %u\n", ret, total); } } #else static void do_writev(int fd, struct iovec *vec, size_t nvec, size_t total) { char *p, *buf; ssize_t ret; p = buf = malloc(total); while (nvec) { memcpy(p, vec[0].iov_base, vec[0].iov_len); p += vec[0].iov_len; nvec--; vec++; } ret = write(fd, buf, total); free(buf); if (ret != total) { printf("write got %d not %u\n", ret, total); } } #endif #define BIG 100 #define TESTFN "./writev.out" int main(int argc, char **argv) { int fd; size_t n, total = 0; struct iovec vecs[NVECS]; int count = 0; struct timeval start, end, diff; unlink(TESTFN); fd = open(TESTFN, O_CREAT | O_WRONLY | O_TRUNC, 0644); if (fd < 0) { perror("open"); return 1; } #if 0 for (n = 1; n < 5; n++) { strs[n] = malloc(BIG * n + 1); memset(strs[n], 'a' + n, BIG * n); strs[n][BIG * n] = 0; } #endif for (n = 0; n < NVECS; n++) { vecs[n].iov_base = strs[n]; vecs[n].iov_len = strlen(strs[n]); total += vecs[n].iov_len; } gettimeofday(&start, NULL); while (count++ < ITERS) do_writev(fd, vecs, NVECS, total); gettimeofday(&end, NULL); timersub(&end, &start, &diff); #ifdef USE_WRITEV printf("writev"); #else printf("copy+write"); #endif printf(": %lds%06ld.\n", diff.tv_sec, diff.tv_usec); close(fd); return 0; } --rwEMma7ioTxnRzrJ--