Commit 3f8dfa4c authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Update in simulations

parent 9abaa20d
Bug :
possible bug in the upnp refresh, when refreshing after a too long time
To be done : To be done :
Test the package Test the package
......
...@@ -41,7 +41,7 @@ class main(object): ...@@ -41,7 +41,7 @@ class main(object):
def __init__(self): def __init__(self):
self.cert_duration = 365 * 86400 self.cert_duration = 365 * 86400
self.time_out = 86400 self.time_out = 45000
self.refresh_interval = 600 self.refresh_interval = 600
self.last_refresh = time.time() self.last_refresh = time.time()
......
...@@ -42,7 +42,7 @@ def getConfig(): ...@@ -42,7 +42,7 @@ def getConfig():
_('--registry', required=True, _('--registry', required=True,
help="HTTP URL of the discovery peer server," help="HTTP URL of the discovery peer server,"
" with public host (default port: 80)") " with public host (default port: 80)")
_('--peers-db-refresh', default=3600, type=int, _('--peers-db-refresh', default=43200, type=int,
help='the time (seconds) to wait before refreshing the peers db') help='the time (seconds) to wait before refreshing the peers db')
_('-l', '--log', default='/var/log', _('-l', '--log', default='/var/log',
help='Path to re6stnet logs directory') help='Path to re6stnet logs directory')
......
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
max_peers = 30 max_peers = 30
nFiles = 2 nFiles = 4
nRounds = 3000 nRounds = 900
file_names = ['out_%s.csv' % i for i in range(nFiles)] file_names = ['out_%s.csv' % i for i in range(nFiles)]
distance = [0] * nRounds distance = [0] * nRounds
arityLat = [[0] * (max_peers - 9) for i in range(10)]
arity = [[0] * 31 for i in range(nRounds)] arity = [[0] * (max_peers + 1) for i in range(nRounds)]
for file_name in file_names: for file_name in file_names:
# open the file # open the file
...@@ -16,27 +17,38 @@ for file_name in file_names: ...@@ -16,27 +17,38 @@ for file_name in file_names:
for line in lines: for line in lines:
vals = line.split(',') vals = line.split(',')
if len(vals) < 2:
continue
i = int(vals[0]) i = int(vals[0])
if i >= nRounds:
continue
distance[i] += float(vals[1]) distance[i] += float(vals[1])
for j in range(0, 31): for j in range(10, 31):
arity[i][j] += float(vals[j + 2]) arity[i][j] += float(vals[j - 6])
for j in range(0, 10):
for k in range(0, max_peers - 9):
arityLat[j][k] += int(vals[48 + 22 * j + k])
for i in range(0, nRounds): for i in range(0, nRounds):
distance[i] = distance[i] / len(file_names) distance[i] = distance[i] / len(file_names)
for j in range(0, 31): for j in range(0, 31):
arity[i][j] = arity[i][j] / len(file_names) arity[i][j] = arity[i][j] / len(file_names)
plt.plot(range(31), arity[1], range(31), arity[nRounds - 1]) for i in range(0, 10):
plt.legend(('Random network', 'After %s iterations' % nRounds)) s = sum(arityLat[i])
for j in range(0, max_peers - 9):
arityLat[i][j] = float(arityLat[i][j]) / float(s)
#plt.plot(range(31), arity[1], range(31), arity[nRounds - 1])
#plt.legend(('Random network', 'After %s iterations' % nRounds))
#plt.xlabel('Arity')
#plt.axis([10, 30, 0, 0.3])
latRange = range(10, 31)
plt.plot(latRange, arityLat[0], latRange, arityLat[9])
plt.legend(('average latency < 50ms', 'average latency > 90ms'), loc=2)
plt.xlabel('Arity') plt.xlabel('Arity')
plt.ylabel('Ratio of node')
plt.axis([10, 30, 0, 0.4]) #plt.plot(range(0, nRounds), distance)
#plt.xscale('log')
#plt.yscale('log')
plt.show() plt.show()
#include "main.h" #include "main.h"
Graph::Graph(int size, int k, int maxPeers, mt19937& rng, Latency* latency) : Graph::Graph(int size, int k, int maxPeers, mt19937& rng, Latency* latency, double minKillProba, double maxKillProba) :
generator(mt19937(rng())), size(size), k(k), maxPeers(maxPeers), latency(latency), generator(mt19937(rng())), size(size), k(k), maxPeers(maxPeers), latency(latency),
distrib(uniform_int_distribution<int>(0, size-1)) distrib(uniform_int_distribution<int>(0, size-1))
{ {
adjacency = new unordered_set<int>[size]; adjacency = new unordered_set<int>[size];
generated = new unordered_set<int>[size]; generated = new unordered_set<int>[size];
killProba = new double[size];
uniform_real_distribution<double> kill_distrib(minKillProba, maxKillProba);
for(int i=0; i<size; i++) for(int i=0; i<size; i++)
{
SaturateNode(i); SaturateNode(i);
killProba[i] = kill_distrib(generator);
}
} }
Graph::Graph(Graph& g) : Graph::Graph(Graph& g) :
...@@ -328,11 +333,11 @@ void Graph::KillMachines(float proportion) ...@@ -328,11 +333,11 @@ void Graph::KillMachines(float proportion)
} }
} }
void Graph::Reboot(double proba, int round) void Graph::Reboot()
{ {
uniform_real_distribution<double> d(0.0, 1.0); uniform_real_distribution<double> d(0.0, 1.0);
for(int i=0; i<size; i++) for(int i=0; i<size; i++)
if(d(generator) <= proba) if(d(generator) <= killProba[i])
{ {
stack<int> toSaturate; stack<int> toSaturate;
...@@ -376,6 +381,18 @@ void Graph::GetArityLat(int arity[][10]) ...@@ -376,6 +381,18 @@ void Graph::GetArityLat(int arity[][10])
arity[adjacency[i].size()][max(min((int)(latency->avgLatencyToOthers[i] - 45000)/5000, 9), 0)]++; arity[adjacency[i].size()][max(min((int)(latency->avgLatencyToOthers[i] - 45000)/5000, 9), 0)]++;
} }
void Graph::GetArityKill(int arity[][10])
{
for(int i=0; i<10; i++)
for(int a=0; a<=maxPeers; a++)
arity[a][i] = 0;
for(int i=0; i<size; i++)
{
arity[adjacency[i].size()][max(min((int)(killProba[i]*200.0), 9), 0)]++;
}
}
double Graph::GetAvgDistanceHop() double Graph::GetAvgDistanceHop()
{ {
double avgDist = 0; double avgDist = 0;
......
...@@ -27,6 +27,8 @@ Latency::Latency(const char* filePath, int size) : size(size) ...@@ -27,6 +27,8 @@ Latency::Latency(const char* filePath, int size) : size(size)
values[a-1][b-1] = latency; values[a-1][b-1] = latency;
} }
fclose(file);
for(int i=0; i<size; i++) for(int i=0; i<size; i++)
{ {
avgLatencyToOthers[i] = 0; avgLatencyToOthers[i] = 0;
...@@ -35,7 +37,6 @@ Latency::Latency(const char* filePath, int size) : size(size) ...@@ -35,7 +37,6 @@ Latency::Latency(const char* filePath, int size) : size(size)
avgLatencyToOthers[i] /= size; avgLatencyToOthers[i] /= size;
} }
fclose(file);
} }
void Latency::Rewrite(int n) void Latency::Rewrite(int n)
...@@ -76,6 +77,7 @@ Latency::~Latency() ...@@ -76,6 +77,7 @@ Latency::~Latency()
for(int i=0; i<size; i++) for(int i=0; i<size; i++)
delete[] values[i]; delete[] values[i];
delete[] values; delete[] values;
delete[] avgLatencyToOthers;
} }
double Latency::GetAverageDistance() double Latency::GetAverageDistance()
......
...@@ -13,44 +13,47 @@ void simulate(int size, int k, int maxPeer, int seed, Latency* latency, const ch ...@@ -13,44 +13,47 @@ void simulate(int size, int k, int maxPeer, int seed, Latency* latency, const ch
FILE* output = fopen(outName, "wt"); FILE* output = fopen(outName, "wt");
int fno = fileno(output); int fno = fileno(output);
double nRoutesKilled = 0; double nRoutesKilled = 0;
int arityLatDistrib[maxPeer+1][10]; //int arityKillDistrib[maxPeer+1][10];
double avgDistance, unreachable; double avgDistance, unreachable;
double arityDistrib[31], bcArity[31]; double arityDistrib[31], bcArity[31];
Graph graph(size, k, maxPeer, rng, latency); Graph graph(size, k, maxPeer, rng, latency, 0, 0.05);
cout << "\r" << 0 << "/" << 3000; cout << "\r" << 0 << "/" << 3000;
cout.flush(); cout.flush();
for(int i=0; i<3000; i++) for(int i=0; i<3000; i++)
{ {
/*for(float a=0.05; a<1; a+=0.05) /*if(i>=100)
{ {
Graph copy(graph); for(float a=0.05; a<1; a+=0.05)
copy.KillMachines(a); {
fprintf(output, "%d,%f,%f\n",i , a , copy.GetUnAvalaibility()); Graph copy(graph);
fflush(output); copy.KillMachines(a);
fsync(fno); fprintf(output, "%d,%f,%f\n",i , a , copy.GetUnAvalaibility());
fflush(output);
fsync(fno);
}
}*/ }*/
//graph.Reboot(1.0/(100 + 1.0), i); //graph.Reboot();
graph.UpdateLowRoutes(avgDistance, unreachable, nRoutesKilled, arityDistrib, bcArity, 1, i); graph.UpdateLowRoutes(avgDistance, unreachable, nRoutesKilled, arityDistrib, bcArity, 1, i);
graph.GetArityLat(arityLatDistrib); //graph.GetArityKill(arityKillDistrib);
fprintf(output, "%d,%f,%f,A", i, avgDistance, nRoutesKilled); fprintf(output, "%d,%f,%f", i, avgDistance, nRoutesKilled);
for(int j=k; j<=30; j++) for(int j=k; j<=30; j++)
fprintf(output, ",%f", arityDistrib[j]); fprintf(output, ",%f", arityDistrib[j]);
fprintf(output, ",B"); /*fprintf(output, ",B");
for(int j=k; j<=30; j++) for(int j=k; j<=30; j++)
fprintf(output, ",%f", bcArity[j]); fprintf(output, ",%f", bcArity[j]);
for(int j=0; j<10; j++) for(int j=0; j<10; j++)
{ {
fprintf(output, ",L%d", j); fprintf(output, ",K%d", j);
for(int a=k; a<=maxPeer; a++) for(int a=k; a<=maxPeer; a++)
fprintf(output, ",%d", arityLatDistrib[a][j]); fprintf(output, ",%d", arityKillDistrib[a][j]);
} }*/
fprintf(output, "\n"); fprintf(output, "\n");
fflush(output); fflush(output);
fsync(fno); fsync(fno);
...@@ -74,7 +77,7 @@ void testOptimized(int size, int k, int maxPeer, int seed, Latency* latency, con ...@@ -74,7 +77,7 @@ void testOptimized(int size, int k, int maxPeer, int seed, Latency* latency, con
FILE* input = fopen("update_order", "r"); FILE* input = fopen("update_order", "r");
mt19937 rng(seed); mt19937 rng(seed);
Graph graph(size, k, maxPeer, rng, latency); Graph graph(size, k, maxPeer, rng, latency, 0, 0.1);
double nRoutesKilled = 0; double nRoutesKilled = 0;
int arityDistrib[maxPeer+1]; int arityDistrib[maxPeer+1];
...@@ -98,7 +101,7 @@ void testOptimized(int size, int k, int maxPeer, int seed, Latency* latency, con ...@@ -98,7 +101,7 @@ void testOptimized(int size, int k, int maxPeer, int seed, Latency* latency, con
fflush(output); fflush(output);
fsync(fno); fsync(fno);
graph.Reboot(1.0/(2500 + 1.0), i); graph.Reboot();
cout << "\r" << i+1 << "/" << 3000; cout << "\r" << i+1 << "/" << 3000;
cout.flush(); cout.flush();
...@@ -118,7 +121,7 @@ void Optimize(int size, int k, int maxPeer, int seed, Latency* latency, const ch ...@@ -118,7 +121,7 @@ void Optimize(int size, int k, int maxPeer, int seed, Latency* latency, const ch
int fno = fileno(output); int fno = fileno(output);
mt19937 rng(seed); mt19937 rng(seed);
Graph* graph = new Graph(size, k, maxPeer, rng, latency); Graph* graph = new Graph(size, k, maxPeer, rng, latency, 0, 0.1);
int range = maxPeer - k + 1; int range = maxPeer - k + 1;
int updates[range]; int updates[range];
...@@ -181,7 +184,7 @@ void Optimize(int size, int k, int maxPeer, int seed, Latency* latency, const ch ...@@ -181,7 +184,7 @@ void Optimize(int size, int k, int maxPeer, int seed, Latency* latency, const ch
fflush(output); fflush(output);
fsync(fno); fsync(fno);
graph->Reboot(1.0/(2500 + 1.0), i); graph->Reboot();
cout << "\r" << i+1 << "/" << 3000;cout.flush(); cout << "\r" << i+1 << "/" << 3000;cout.flush();
} }
...@@ -193,7 +196,7 @@ void Optimize(int size, int k, int maxPeer, int seed, Latency* latency, const ch ...@@ -193,7 +196,7 @@ void Optimize(int size, int k, int maxPeer, int seed, Latency* latency, const ch
string computeDist(int size, int k, int maxPeer, int seed, Latency* latency) string computeDist(int size, int k, int maxPeer, int seed, Latency* latency)
{ {
mt19937 rng(seed); mt19937 rng(seed);
Graph graph(size, k, maxPeer, rng, latency); Graph graph(size, k, maxPeer, rng, latency, 0, 0.1);
double avgDistLatency = 0; double avgDistLatency = 0;
int nRoutes[size], prevs[size], distances[size]; int nRoutes[size], prevs[size], distances[size];
...@@ -215,12 +218,12 @@ int main(int argc, char** argv) ...@@ -215,12 +218,12 @@ int main(int argc, char** argv)
mt19937 rng(time(NULL)); mt19937 rng(time(NULL));
Latency* latency = new Latency("datasets/latency_2_2500", 2500); Latency* latency = new Latency("datasets/latency_2_2500", 2500);
//cout << "Optimal distance : " << latency->GetAverageDistance() << endl; cout << "Optimal distance : " << latency->GetAverageDistance() << endl;
//cout << "Average ping : " << latency->GetAveragePing() << endl; cout << "Average ping : " << latency->GetAveragePing() << endl;
vector<future<void>> threads; vector<future<void>> threads;
for(int i=0; i<1; i++) for(int i=0; i<4; i++)
{ {
int seed = rng(); int seed = rng();
char* out = new char[100]; char* out = new char[100];
......
...@@ -38,18 +38,19 @@ private: ...@@ -38,18 +38,19 @@ private:
class Graph class Graph
{ {
public: public:
Graph(int size, int k, int maxPeers, mt19937& generator, Latency* latency); Graph(int size, int k, int maxPeers, mt19937& generator, Latency* latency, double minKillProba, double maxKillProba);
Graph(Graph& g); Graph(Graph& g);
~Graph() { delete[] adjacency; delete[] generated;}; ~Graph() { delete[] adjacency; delete[] generated; delete[] killProba;};
int UpdateLowRoutes(double& avgDistance, double& unreachable, double& nRoutesKilled, double* arityDistrib, double* bcArity, int nRefresh, int round); int UpdateLowRoutes(double& avgDistance, double& unreachable, double& nRoutesKilled, double* arityDistrib, double* bcArity, int nRefresh, int round);
double GetUnAvalaibility(); double GetUnAvalaibility();
void Reboot(double proba, int round); void Reboot();
void KillMachines(float proportion); void KillMachines(float proportion);
pair<double, double> UpdateLowRoutesArity(int arityToUpdate); pair<double, double> UpdateLowRoutesArity(int arityToUpdate);
void GetArity(int* arity); void GetArity(int* arity);
void GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances); void GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances);
double GetAvgDistanceHop(); double GetAvgDistanceHop();
void GetArityLat(int arity[][10]); void GetArityLat(int arity[][10]);
void GetArityKill(int arity[][10]);
private: private:
void SaturateNode(int node); void SaturateNode(int node);
...@@ -67,4 +68,5 @@ private: ...@@ -67,4 +68,5 @@ private:
unordered_set<int>* adjacency; unordered_set<int>* adjacency;
unordered_set<int>* generated; unordered_set<int>* generated;
Latency* latency; Latency* latency;
double* killProba;
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment