call stat less often on krb5.conf
authorKen Raeburn <raeburn@mit.edu>
Sat, 30 Oct 2004 05:43:18 +0000 (05:43 +0000)
committerKen Raeburn <raeburn@mit.edu>
Sat, 30 Oct 2004 05:43:18 +0000 (05:43 +0000)
Changes suggested by lxs to reduce stat frequency to once per second.
In parallel loops creating and destroying krb5 contexts on Mac OS X, this
seems to improve performance by 10%, though it's hard to be sure because
the times are variable.

* prof_int.h (STAT_ONCE_PER_SECOND): Define.
(struct _prf_data_t) [STAT_ONCE_PER_SECOND]: New field LAST_STAT.
* prof_file.c (scan_shared_trees_locked, scan_shared_trees_unlocked): Redefine
to do nothing for now.
(profile_update_file_data) [STAT_ONCE_PER_SECOND]: If the current time is the
same time as the last stat of the file, just return; otherwise, save away the
current time.

ticket: new
status: open

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16847 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/ChangeLog
src/util/profile/prof_file.c
src/util/profile/prof_int.h

index 1366bd4d1cbbb0063966a3082b67724a4311d42e..79a263f95e81b7b8ece6df9ef9a5440bf1f9da02 100644 (file)
@@ -1,3 +1,13 @@
+2004-10-30  Ken Raeburn  <raeburn@mit.edu>
+
+       * prof_int.h (STAT_ONCE_PER_SECOND): Define.
+       (struct _prf_data_t) [STAT_ONCE_PER_SECOND]: New field LAST_STAT.
+       * prof_file.c (scan_shared_trees_locked,
+       scan_shared_trees_unlocked): Redefine to do nothing for now.
+       (profile_update_file_data) [STAT_ONCE_PER_SECOND]: If the current
+       time is the same time as the last stat of the file, just return;
+       otherwise, save away the current time.
+
 2004-10-26  Ken Raeburn  <raeburn@mit.edu>
 
        Permit exporting profile file data into a buffer.
index f47e5404be92b050ab9a796d697e4f5d65dd7cd1..028253720690e2007221ccffd4d8628a047a1b40 100644 (file)
@@ -66,6 +66,8 @@ void profile_library_finalizer(void)
 
 static void profile_free_file_data(prf_data_t);
 
+#if 0
+
 #define scan_shared_trees_locked()                             \
        {                                                       \
            prf_data_t d;                                       \
@@ -89,6 +91,13 @@ static void profile_free_file_data(prf_data_t);
            k5_mutex_unlock(&g_shared_trees_mutex);     \
        }
 
+#else
+
+#define scan_shared_trees_locked()     { ; }
+#define scan_shared_trees_unlocked()   { ; }
+
+#endif
+
 static int rw_access(const_profile_filespec_t filespec)
 {
 #ifdef HAVE_ACCESS
@@ -295,6 +304,9 @@ errcode_t profile_update_file_data(prf_data_t data)
        errcode_t retval;
 #ifdef HAVE_STAT
        struct stat st;
+#ifdef STAT_ONCE_PER_SECOND
+       time_t now;
+#endif
 #endif
        FILE *f;
 
@@ -303,11 +315,21 @@ errcode_t profile_update_file_data(prf_data_t data)
            return retval;
 
 #ifdef HAVE_STAT
+#ifdef STAT_ONCE_PER_SECOND
+       now = time(0);
+       if (now == data->last_stat) {
+           k5_mutex_unlock(&data->lock);
+           return 0;
+       }
+#endif
        if (stat(data->filespec, &st)) {
            retval = errno;
            k5_mutex_unlock(&data->lock);
            return retval;
        }
+#ifdef STAT_ONCE_PER_SECOND
+       data->last_stat = now;
+#endif
        if (st.st_mtime == data->timestamp) {
            k5_mutex_unlock(&data->lock);
            return 0;
index d2761228cb5205a0df7b597a46aeba8ee1fdb9ee..b7c90961e9f4997110da3094f6c40bbdd9c2d9bb 100644 (file)
@@ -14,6 +14,8 @@
 #include "com_err.h"
 #include "profile.h"
 
+#define STAT_ONCE_PER_SECOND
+
 #if defined(_WIN32)
 #define SIZEOF_INT      4
 #define SIZEOF_SHORT    2
@@ -36,6 +38,9 @@ struct _prf_data_t {
        k5_mutex_t      lock;
        char            *comment;
        struct profile_node *root;
+#ifdef STAT_ONCE_PER_SECOND
+       time_t          last_stat;
+#endif
        time_t          timestamp; /* time tree was last updated from file */
        int             flags;  /* r/w, dirty */
        int             upd_serial; /* incremented when data changes */