opendirectoryd consumes 40% of CPU

The problem is related to the dead symlinks in Dropbox. Find them using:

find ~/Dropbox -type l -printf "%Y %p\n" | grep "^N"

The solution is: Remove the dead symlinks. If find doesn't have the printf option, use:

find -L ~/Dropbox -type l

References

To find dead symlinks


As mentioned by @juanpablo, this may be caused by symlinks.

Apparently, if a symlink points to /home, autofs or automountd fire and take a lot of CPU to figure out that the place indeed doesn't exist.

Take a look at /etc/auto_home and /etc/autofs.conf.

To see if you're being hit by this particular problem, set

AUTOMOUNTD_VERBOSE=TRUE

option in autofs.conf, restart automountd

sudo launchctl stop com.apple.automountd

and review the syslog.log (you may use application: Console). You're affected by this problem if you see something like that:

May 20 17:53:43 xxx automountd[31709]: od_search failed

To workaround, edit the file /etc/auto_master and remove (or hash out #) the line starting with /home. Then run:

sudo automount -vc

For me what really solved it was unplugging ethernet cable from my iMac. Crazy as it sounds :) I was being attacked from outside, bruteforce on my sshd. The router I have (from UPC, Cisco EPC3925) by default forwards all the traffic from outside to the single ethernet port it has. By unplugging the cable the attack stopped as the iMac was left on WiFi only.

Apparently sshd is using opendirectoryd and that's why this was happening.