High context switches on FreeBSD
Dan Nelson
dnelson at allantgroup.com
Fri Apr 2 08:10:47 PST 2004
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 at allantgroup.com
More information about the freebsd-questions
mailing list