Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "Cluster.h"
00029 #include "libts.h"
00030
00031
00032
00033
00034
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
00052
00053 machineClusterHash = !!(version & 1);
00054 boundClusterHash = !!(version & 2);
00055 randClusterHash = !!(version & 4);
00056
00057
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
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
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
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 }