From owner-freebsd-questions@FreeBSD.ORG Fri Apr 2 08:10:47 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 05FCF16A4FA for ; Fri, 2 Apr 2004 08:10:47 -0800 (PST) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9460A43D1F for ; Fri, 2 Apr 2004 08:10:46 -0800 (PST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.10/8.12.10) id i32GAhox097837; Fri, 2 Apr 2004 10:10:43 -0600 (CST) (envelope-from dan) Date: Fri, 2 Apr 2004 10:10:42 -0600 From: Dan Nelson To: Irwan Hadi Message-ID: <20040402161041.GA6724@dan.emsphone.com> References: <20040402063921.GB54789@phxby.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040402063921.GB54789@phxby.com> X-OS: FreeBSD 5.2-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i cc: questions@freebsd.org Subject: Re: High context switches on FreeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Apr 2004 16:10:47 -0000 X-List-Received-Date: Fri, 02 Apr 2004 16:10:47 -0000 In the last episode (Apr 01), Irwan Hadi said: > When I tested this web server on my FreeBSD 5.2.1 box, on a P IV 3 > Ghz Processor and 1 GB memory, I'm getting an enormous number of > context switches, as you can see below: > > # vmstat 1 > procs memory page disks faults cpu > r b w avm fre flt re pi po fr sr da0 da1 in sy cs us sy id > 0 0 0 119644 736348 0 0 0 0 4 0 4 0 308 0 303 0 1 99 > 0 0 0 119644 736348 0 0 0 0 0 0 0 0 301 0 221 0 0 100 > 0 0 0 119644 736348 0 0 0 0 0 0 0 0 300 0 215 0 0 100 > 1 0 0 121336 736092 82 0 0 0 19 0 0 0 9203 0 50953 9 18 73 > 1 0 0 121336 736040 13 0 0 0 0 0 0 0 18315 0 130743 14 46 40 > 0 0 2 121336 735984 14 0 0 0 0 0 0 0 18514 0 128537 18 41 41 > 1 0 0 121336 735928 14 0 0 0 0 0 0 0 20378 0 103812 15 40 45 Horrible word-wrap fixed. You might want to rebuild your vmstat binary, since it looks like it's not counting syscalls at all. > When I run the same code on a Linux box, I'm only getting at most > 33000 context per second, thus it gives a better performance. > > My question now is, is there a way I can trace the source of these > context switches, network, or disk? I'm thinking it may be disk, > though it is also possible that it is caused because of network. > Also, I tried testing the web server by using ramdisk, and the result > is still the same. The context switches stays around 100,000 at peak. > > I'm hoping by reducing the number of context switches, I can increase > my web server performance. Oh by the way, again this web server is my > own, and I just use read(2), and write(2) to read and write to the > socket, and to read the file from the disk. I don't think my numbers are quite that high, but I am seeing a high number of context switches also, even when idle (~200, just like the above output). An idle 4.8 box does ~10/sec, and even a busy server rarely goes above 3000. A simple du on a -current machine bumps the cs rate to 6000 (4BSD scheduler). -- Dan Nelson dnelson@allantgroup.com