]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
I realised that my DMB<->DMB sync code has the property that the
authorAndrew Tridgell <tridge@samba.org>
Mon, 31 Aug 1998 06:59:23 +0000 (06:59 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 31 Aug 1998 06:59:23 +0000 (06:59 +0000)
amount of network traffic grows as the square of the number of
workgroups. It probably wouldn't have caused problems but to be safe I
changed the code to use random() to decrease the probability of a
DMB<->DMB sync in proportion to the number of known workgroups. This
keeps the nice browse connectivity while making the traffic rise only
linearly with the number of workgroups.

source/nmbd/nmbd.c
source/nmbd/nmbd_browsesync.c

index feb9c2420e3a51e1f2483f740b2a8d2ebb1459e2..72cc9408d511e569939d25db9e9e21644ecbf905 100644 (file)
@@ -567,6 +567,8 @@ int main(int argc,char *argv[])
 
   StartupTime = time(NULL);
 
+  srandom(time(NULL) ^ getpid());
+
   TimeInit();
 
   pstrcpy( debugf, NMBLOGFILE );
index 8136568c6aa88fefbea897ed796f55823f858bbd..b1fb4e631fd2043e102ff8ab273d4c46b82ae7c0 100644 (file)
@@ -556,12 +556,17 @@ void collect_all_workgroup_names_from_wins_server(time_t t)
 
 /****************************************************************************
  If we are a domain master browser on the unicast subnet, do a regular sync
- with all other DMBs that we know of on that subnet
+ with all other DMBs that we know of on that subnet.
+
+To prevent exponential network traffic with large numbers of workgroups
+we use a randomised system where sync probability is inversely proportional
+to the number of known workgroups
 **************************************************************************/
 void sync_all_dmbs(time_t t)
 {
        static time_t lastrun = 0;
        struct work_record *work;
+       int count=0;
 
        /* Only do this if we are using a WINS server. */
        if(we_are_a_wins_client() == False)
@@ -575,13 +580,24 @@ void sync_all_dmbs(time_t t)
        if (!AM_DOMAIN_MASTER_BROWSER(work))
                return;
 
-       if ((lastrun != 0) && (t < lastrun + (15 * 60)))
+       if ((lastrun != 0) && (t < lastrun + (5 * 60)))
                return;
      
+       /* count how many syncs we might need to do */
+       for (work=unicast_subnet->workgrouplist; work; work = work->next) {
+               if (strcmp(global_myworkgroup, work->work_group) &&
+                   !ip_equal(work->dmb_addr, ipzero)) {
+                       count++;
+               }
+       }
 
+       /* sync with a probability of 1/count */
        for (work=unicast_subnet->workgrouplist; work; work = work->next) {
                if (strcmp(global_myworkgroup, work->work_group) &&
                    !ip_equal(work->dmb_addr, ipzero)) {
+
+                       if (((unsigned)random()) % count != 0) continue;
+
                        lastrun = t;
 
                        DEBUG(3,("initiating DMB<->DMB sync with %s(%s)\n",