• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

TestClusterHash.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   TestClusterHash.cc
00027  ****************************************************************************/
00028 #include "Cluster.h"
00029 #include "libts.h"
00030 
00031 
00032 //
00033 // This test function produces the table included
00034 // in Memo.ClusterHash
00035 //
00036 
00037 void
00038 test()
00039 {
00040   int n[CLUSTER_MAX_MACHINES];
00041   int i;
00042   Machine *m;
00043   int j;
00044   ink_hrtime t, t2;
00045   int total;
00046   int high, low, share;
00047   int version = 7;
00048 
00049   while (version > -1) {
00050 
00051     // the select the version
00052     //
00053     machineClusterHash = !!(version & 1);
00054     boundClusterHash = !!(version & 2);
00055     randClusterHash = !!(version & 4);
00056 
00057     // fabricate fake cluster
00058 
00059     clusterProcessor.this_cluster = new Cluster;
00060     ClusterConfiguration *cc = new ClusterConfiguration;
00061     cc->n_machines = 1;
00062     cc->machines[0] = this_cluster_machine();
00063     memset(cc->hash_table, 0, CLUSTER_HASH_TABLE_SIZE);
00064     clusterProcessor.this_cluster->configurations.push(cc);
00065 
00066     ClusterConfiguration *c = this_cluster()->current_configuration();
00067 
00068     printf("hash by %s - %s - %s\n",
00069            (machineClusterHash ? "MACHINE" : "BUCKET"),
00070            (boundClusterHash ? "BOUNDED" : "UNBOUND"), (randClusterHash ? "RAND" : "LINEAR CONGUENCE"));
00071 
00072     // from 1 to 32 machines
00073 
00074     for (i = 1; i < 32; i++) {
00075       m = new ClusterMachine(*this_cluster_machine());
00076       m->ip += i;
00077       t = ink_get_hrtime();
00078       cc = configuration_add_machine(c, m);
00079       t2 = ink_get_hrtime();
00080 
00081       //
00082       // Compute new distribution
00083       //
00084       high = 0;
00085       low = CLUSTER_HASH_TABLE_SIZE + 1;
00086       for (j = 0; j < cc->n_machines; j++)
00087         n[j] = 0;
00088       for (j = 0; j < CLUSTER_HASH_TABLE_SIZE; j++) {
00089         ink_assert(cc->hash_table[j] < cc->n_machines);
00090         n[cc->hash_table[j]]++;
00091       }
00092       total = CLUSTER_HASH_TABLE_SIZE;
00093       for (j = 0; j < cc->n_machines; j++) {
00094         total -= n[j];
00095         if (low > n[j])
00096           low = n[j];
00097         if (high < n[j])
00098           high = n[j];
00099       }
00100       ink_assert(!total);
00101       printf("n = %d:", i);
00102       printf(" high = %d low = %d high/low = %f", high, low, (float) high / (float) low);
00103 
00104       //
00105       // Compute sharing with n-1
00106       //
00107       share = 0;
00108       for (j = 0; j < CLUSTER_HASH_TABLE_SIZE; j++) {
00109         if (c->machines[c->hash_table[j]] == cc->machines[cc->hash_table[j]])
00110           share++;
00111       }
00112       printf(" shared = %d %%%6.2f", share, (float) share / (float) CLUSTER_HASH_TABLE_SIZE);
00113 
00114       printf(" time = %f secs\n", ((float) (t2 - t) / (float) HRTIME_SECONDS(1)));
00115       c = cc;
00116     }
00117 
00118     version--;
00119   }
00120 }

Generated by  doxygen 1.7.1