đ Profiling Squid Servers
Is Squid running too slow? Would you like to investigate why and try to help us make Squid perform faster? Hereâs a few pointers.
đ What should I be looking at?
In short: everything. Disk IO, memory use, CPU use, network use. You need to get a handle on what your equipment is capable of and identify things that are out of whack. It doesnât take much practice to be able to do this, so donât worry too much!
đ CPU usage
Squid is a CPU-intensive application (since, after all, it spends all of its time processing incoming data and generating data to send.) But thereâs many different types of CPU usage which can identify what youâre running out of.
- CPU spent in user-space: This is the CPU time spent by the Squid process itself.
- CPU spent in kernel-space: This could be anything kernel-related, but generally reflects non-device kernel processing. So stuff like queueing/dequeueing disk and network IO, filesystem processing and some network layer processing.
- CPU spent in interrupt-space: This is generally CPU spent dealing with physical devices - Disk and Network. You should generally spend very little time in interrupt space with well-programmed device drivers and well-behaving hardware. Things, however, arenât always well-behaved.
- CPU spent in IOWAIT - somewhat of a Linux-ism as far as Iâm aware, this reflects the amount of time the CPU is spending waiting for IO to complete. This is generally because your device(s) require more attention than they should need to complete stuff.
đ Resource usage
The commonly available UNIX tools vmstat and iostat let you scratch the surface of your current server resource usage. vmstat will generally display information pertaining to memory usage, CPU usage, device interrupts, disk IO (in and out) and the amount of system paging going on. iostat lets you drill down into the IO operations scheduled on each physical disk.
I generally run them as vmstat 1 and iostat 1, keeping an eye on things. You should also consider setting up graphing to track various resource variables and watch usage trends.
đ What sort of things impact the performance of my Squid ?
Squid will start suffering if you run out of any of your server resources. Thereâs a few things that frequently occur:
- You just plain run out of CPU. This is where all of your resources are low save your kernel and user CPU usage. This may be because youâre still using poll() or select() for your network IO which just donât scale under modern loads.
- Some crappy hardware (such as slow IDE disks and really cheap network cards) arenât that great at shoveling data around and require a lot of hand-holding by the CPU. If you see your interrupt/IOWAIT times up then it might be due to your hardware choices. Iâve seen this sort of thing happen with desktop-grade hardware pretending to be a server - eg the Sun âDesktopâ hardware running Linux and using SATA disks. Lots of disk IO == Lots of time spent in IOWAIT.
- Some hardware allows you to tune how much overhead it imposes on the system. Gigabit network cards are a good example of this. You trade off a few ms of latency versus a high interrupt load, but this doesnât matter on a server which is constantly handling packets. Take a look at your hardware documentation and see whats available.
- Linux servers spending a lot of time in IOWAIT can also be because youâre overloading your disks with IO. See what your disk IO looks like in vmstat. You could look at moving to the aufs/diskd cache_dir if youâre using UFS. COSS also can drastically drop IOWAIT times under heavy disk loads.
- Youâre swapping! This happens quite often when people wind up cache_mem and donât watch how much RAM Squid is actually using. Watch the output of vmstat and see how much free memory is available. If you see your server paging memory in and out of disk then youâre in trouble. Either decrease cache_mem or add more physical RAM.
đ How can I see what Squid is actually doing?
The best thing you can do to identify where all your CPU usage is going is to use a process or system profiler. Personally, I use oprofile. gprof isnât at all accurate with modern CPU clockspeeds. Thereâs other options - hwpmc under FreeBSD, for example, can do somewhat what oprofile can but it currently has trouble getting any samples from Squid in userspace. Grr. perfmon is also an option if you donât have root access on the server.
OProfile under Linux is easy to use and has quite a low overhead.
Hereâs how I use oprofile:
- Install oprofile
- Check whats available - opcontrol -l
- If you see a single line regarding âtimer interrupt modeâ, youâre stuffed. Go read the OProfile FAQ and see if you can enable ACPI. You wonât get any meaningful results out of OProfile in timer interrupt mode.
- Set it up - opcontrol âsetup -c 4 -p library,kernel âno-vmlinux (if you have a vmlinux image, read the opcontrol manpage for instructions on telling opcontrol where its hiding.)
- Start it up - opcontrol âstart
- Wait a few minutes - a busy squid server will quickly generate a lot of profiling information!
- Then use opreport -l /path/to/squid/binary to grab out information on Squid CPU use.
Just remember:
- Make sure youâve got the debugging libraries and library symbols installed - under Ubuntu thats âlibc6-dbgâ.
- Donât try using it under timer interrupt mode, itâll suffer similar accuracy issues to gprof and other timer-based profilers.
đ Load Testing Tools
Itâs also useful to profile the connection and request limits. Here are some tools for testing behaviour at various request and connection loads.
To the FAQ Index
Navigation: Site Search, Site Pages, Categories, đŒ go up