DirectoryService high CPU utilization
Jul 14, '10 07:30:00AM
Contributed by: tache
I had been experiencing extremely high CPU utilization by the DirectoryService process. Most of the time it was at 65% CPU usage, and sometimes it was up to 190%.
I traced this to my usage of the /etc/hosts file (with 16K+ entries) to combat website ads. Each entry in the /etc/host file had the form: 127.0.0.1 <hostname>.
Here is an alternative method of host redirection that reduces the CPU burden of DirectoryService to nearly nothing. Dnsmasq is a small footprint DNS/DHCP server designed for small networks, or is this case, a single machine.
- Install a localhost version of dnsmasq. (I used MacPorts but you can download the source from the above linked site.
- Configure the network settings to resolve DNS queries to localhost (127.0.0.1).
- Made sure the firewall accepted the queries for dnsmasq.
- Configured /etc/dnsmasq.conf to forward unresolved hosts out to my normal DNS servers. Also configured the /etc/dnsmasq.conf file to read my blocked ad hosts from a file.
- Made sure dnsmasq would start at system boot.
- Verified both normal entries resolved and ad hosts resolved correctly.
The efficient dnsmasq process does not even register any percentage, sticking at 0.0%. Afterwards, DirectoryService CPU utilization now sits at 0.0%.
[crarko adds: I haven't tested this one. There obviously are browser specific adblockers but the use of the hosts file is a time-honored method of address redirection. There is further explanation of how to use dnsmasq and some examples in this article.]
Comments (19)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20100713190059936