Performance regression ‘newgrp’ since upstream shadow-utils 4.0.11

Solution In Progress - Updated -

Issue

  • The performance of the execution of the ‘newgrp’ command went from near-instant in Red Hat Enterprise Linux 4 to almost 5 seconds in Red Hat Enterprise Linux 5. Browsing through the upstream code commits was showing a possible cause in the form of an added while() loop in 4.0.11, with comment “find_matching_group - search all groups of a given group id for membership of a given username”, specifically the following revision
  • After trying out the upstream 4.0.10 and 4.0.11 versions, the 4.0.10 version was as expected almost instant, and the 4.0.11 version showing the slowdown. Modifying the source code of ‘newgrp.c’ shows the following result, and code parts at the bottom:
$ ./bin/newgrp
debug: 'while ((gr = getgrent ()) != NULL)', elapsed 4.750450 seconds
debug: 'while ((gr = getgrent ()) != NULL)', did 1377 checks

static struct group *find_matching_group (const char *name, gid_t gid)
{
                [..]
                int c_getgrent = 0;
struct timeval tv1, tv2;

                /* DEBUG: time taken purely by the 'while ((gr = getgrent ()) != NULL)' loop */
setgrent();
gettimeofday(&tv1, NULL); while ((gr = getgrent()) != NULL); gettimeofday(&tv2, NULL);
endgrent();

fprintf (stderr, _("debug: 'while ((gr = getgrent ()) != NULL)', elapsed %f seconds\n"),
(double)(tv2.tv_usec - tv1.tv_usec)/1000000 + (double)(tv2.tv_sec - tv1.tv_sec));
/* DEBUG: end */

setgrent ();
while ((gr = getgrent ()) != NULL) {
c_getgrent++;
[..]
                }
                fprintf (stderr, _("debug: 'while ((gr = getgrent ()) != NULL)', did %d checks\n"), c_getgrent);
endgrent ();
return gr;
}
  • We use LDAP for user/group lookups, and each getgrent() call results in a ~1ms delay from the LDAP server. Tuning NSCD didn't improve anything, disabling NSCD yields the same "performance".

Environment

  • Red Hat Enterprise Linux (RHEL) 5, 6 and 7
  • shadow-utils-4.0.17-20.el5 and later

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.