when sftp client connects to sftp-server and does "ls -l" command on a large directory (many files), performance is unacceptably slow when the sftp-server node used ldap/kerberos/NIS/...(etc) to look up EVERY uid/gid on every file. a simple fix is to cache/buffer the uid/gid of the previous file from the stat()/fstat() & chk to see if they have changed before issuing the lookup of the same uid/gid (ergo inhibiting a wait-for-network to get info that we already have) same issue true for v4.1p1 through current.
Isn't this the role of nscd (or similar)?
nscd helped on this issue, issuing e.g. 'ls -l' is now as fast as expected. Cache times within nscd.conf could be quite small, e.g. between 20 and 60 seconds, it you want to avoid that services rely on outdated information.
Created attachment 1779 [details] sftp-namecache.patch Add a small LRU to cache user and group names.
deraadt points out that similar functions (user_from_uid and group_from_gid) exist in OpenBSD's libc ( both keep a 64-entry hash table as a cache) We have just commited a change with that. We'll add these functions to the compat library for any platform that doesn't have them.
With the release of 5.4p1, this bug is now considered closed.