-
Notifications
You must be signed in to change notification settings - Fork 5
Add the py-dht repo as a submodule #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cortze
wants to merge
10
commits into
codex-storage:develop
Choose a base branch
from
cortze:feat/add-dht-module
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
808f857
add cortze/py-dht as submodule + add DHT related parameters to the DA…
9939089
add basic DHT network init to the DAS.simulator + add DHTClient to th…
02c5a18
update to lastest version of py-dht
5543d41
make first lookup phase for the block-builder dht sample seeding
7541ed3
update py-dht dependencies
14c4034
update ignore file
f79e7a6
add DHT seeding + retrieval study to DAS
d257817
fixing submodule URL
cskiraly 1cabe9d
clean up non-finished integration of the DHT simulation into DAS module
cortze d108c18
update dependencies for DHT module
cortze File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
*.swp | ||
*.pyc | ||
results/* | ||
myenv*/ | ||
*env*/ | ||
doc/_build | ||
!results/plots.py | ||
Frontend/ | ||
.idea | ||
|
||
# DHT module related | ||
DHT/imgs | ||
DHT/csvs | ||
DHT/.ipynb_checkpoints |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "py-dht"] | ||
path = py-dht | ||
url = https://github.com/cortze/py-dht |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# DHT simulations for DAS | ||
Simulate the seeding and the retrieval of Ethereum DAS samples in a Kademlia-based DHT. | ||
|
||
## Dependencies | ||
The DHT module relies on [`py-dht`](https://github.com/cortze/py-dht) to run, however it is already installed together with the DAS block disemination dependencies. | ||
```shell | ||
# once the venv is created (make sure the venv name match with the `install_dependencies.sh` one) | ||
das-research$ bash install_dependencies.sh | ||
``` | ||
|
||
## How to run it | ||
To run the seeding and retrieval simulation of the DHT, these are the steps that would need to be taken: | ||
1. configure the desired parameters in the `dhtConf.py`. NOTE: the script will create the CSV and IMG folders for you! | ||
2. execute the experiment by running: | ||
```shell | ||
# venv needs to be activated | ||
# $ source venv/bin/activate | ||
das-research/DHT$ python3 dhtStudy.py dhtSmallConf.py | ||
``` | ||
the output should look like this for each of the possible configurations: | ||
```shell | ||
network init done in 52.08381795883179 secs | ||
[===============================================================================================================================================================================================================================] 100% | ||
test done in 159.97085118293762 secs | ||
DHT fast-init jobs:8 done in 52.08381795883179 secs | ||
12000 nodes, k=20, alpha=3, 10000 lookups | ||
mean time per lookup : 0.010750784277915955 | ||
mean aggr delay (secs): 0.31828715 | ||
mean contacted nodes: 8.7223 | ||
time to make 10000 lookups: 107.50784277915955 secs | ||
|
||
done with the studies in 167.69087147712708 | ||
``` | ||
3. all the visualization graphs can be generated using the `retrieval_on_das_plotting.ipynb` notebook. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from plots import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,270 @@ | ||
import time | ||
import progressbar | ||
import random | ||
import numpy as np | ||
import pandas as pd | ||
import dht | ||
from utils import getStrFromDelayRange | ||
|
||
TOTAL_PERCENTAGE = 100 | ||
PERCENTAGE_INTERVALS = 1 | ||
|
||
|
||
class SingleDHTretrievalStudy: | ||
|
||
def __init__(self, csvFolder, imgFolder, jobs, nn, rn, samples, | ||
fErrR, sErrR, cDelR, fDelR, sDelR, k, a, b, y, stepsToStop): | ||
self.csvFolder = csvFolder | ||
self.imgFolder = imgFolder | ||
self.jobs = jobs | ||
self.nn = nn | ||
self.rn = rn | ||
self.samples = samples | ||
self.fastErrorRate = fErrR | ||
self.slowErrorRate = sErrR | ||
self.connDelayRange = cDelR | ||
self.fastDelayRange = fDelR | ||
self.slowDelayRange = sDelR # timeouts | ||
self.k = k | ||
self.alpha = a | ||
self.beta = b | ||
self.gamma = y | ||
self.stepsToStop = stepsToStop | ||
# namings | ||
s = "" | ||
s += f"_nn{nn}" | ||
s += f"_rn{rn}" | ||
s += f"_sampl{samples}" | ||
s += f"_fer{fErrR}" | ||
s += f"_ser{sErrR}" | ||
s += f"_cdr{getStrFromDelayRange(cDelR)}" | ||
s += f"_fdr{getStrFromDelayRange(fDelR)}" | ||
s += f"_sdr{getStrFromDelayRange(sDelR)}" | ||
s += f"_k{k}" | ||
s += f"_a{a}" | ||
s += f"_b{b}" | ||
s += f"_y{y}" | ||
s += f"_steps{stepsToStop}" | ||
self.studyName = s | ||
print(f"Retrieval Study => {s}") | ||
|
||
def run(self): | ||
# Init the DHT Network | ||
testInitTime = time.time() | ||
network = dht.DHTNetwork( | ||
0, | ||
self.fastErrorRate, | ||
self.slowErrorRate, | ||
self.connDelayRange, | ||
self.fastDelayRange, | ||
self.slowDelayRange, | ||
self.gamma) | ||
initStartTime = time.time() | ||
network.init_with_random_peers( | ||
self.jobs, | ||
self.nn, | ||
self.k, | ||
self.alpha, | ||
self.beta, | ||
self.stepsToStop) | ||
self.networkInitTime = time.time() - initStartTime | ||
print(f"network init done in {self.networkInitTime} secs") | ||
|
||
# get random node to propose publish the | ||
builderNode = network.nodestore.get_node(random.randint(0, self.nn)) | ||
|
||
# create and publish @@@ number of samples to the network | ||
# lookups metrics | ||
ks = [] | ||
nns = [] | ||
stepstostops = [] | ||
fastErrorRate = [] | ||
slowErrorRate = [] | ||
connDelayRange = [] | ||
fastDelayRange = [] | ||
slowDelayRange = [] | ||
alphas = [] | ||
betas = [] | ||
gammas = [] | ||
providers = [] | ||
sampleNames = [] | ||
provideLookupAggrTime = [] | ||
provideAggrTime = [] | ||
provideOperationAggrTime = [] | ||
provideSuccNodes = [] | ||
provideFailedNodes = [] | ||
samples = [] | ||
|
||
for i in range(self.samples): | ||
sampleContent = f"sample {i}" | ||
summary, _ = builderNode.provide_block_segment(sampleContent) | ||
samples.append((sampleContent, sampleContent, summary)) | ||
# add metrics for the csv | ||
ks.append(self.k) | ||
alphas.append(self.alpha) | ||
betas.append(self.beta) | ||
gammas.append(self.gamma) | ||
nns.append(self.nn) | ||
stepstostops.append(self.stepsToStop) | ||
fastErrorRate.append(f"{self.fastErrorRate}") | ||
slowErrorRate.append(f"{self.slowErrorRate}") | ||
connDelayRange.append(f"{getStrFromDelayRange(self.connDelayRange)}") | ||
fastDelayRange.append(f"{getStrFromDelayRange(self.fastDelayRange)}") | ||
slowDelayRange.append(f"{getStrFromDelayRange(self.slowDelayRange)}") | ||
providers.append(builderNode.ID) | ||
sampleNames.append(sampleContent) | ||
provideLookupAggrTime.append(summary['lookupDelay']) | ||
provideAggrTime.append(summary['provideDelay']) | ||
provideOperationAggrTime.append(summary['operationDelay']) | ||
provideSuccNodes.append(len(summary['succesNodeIDs'])) | ||
provideFailedNodes.append(len(summary['failedNodeIDs'])) | ||
|
||
# save the provide data | ||
df = pd.DataFrame({ | ||
"number_nodes": nns, | ||
"k": ks, | ||
"alpha": alphas, | ||
"beta": betas, | ||
"gamma": gammas, | ||
"stop_steps": stepstostops, | ||
"fast_error_rate": fastErrorRate, | ||
"slow_error_rate": slowErrorRate, | ||
"connection_delay_range": connDelayRange, | ||
"fast_delay_range": fastDelayRange, | ||
"slow_delay": slowDelayRange, | ||
"provider": providers, | ||
"sample": sampleNames, | ||
"provide_lookup_aggr_time": provideLookupAggrTime, | ||
"provide_aggr_time": provideAggrTime, | ||
"provide_operation_aggr_time": provideOperationAggrTime, | ||
"provide_succ_nodes": provideSuccNodes, | ||
"provide_fail_nodes": provideFailedNodes, | ||
}) | ||
|
||
df.to_csv(self.csvFolder + f"/retrieval_provide{self.studyName}.csv") | ||
network.reset_network_metrics() | ||
del df | ||
|
||
nns = [] | ||
ks = [] | ||
alphas = [] | ||
betas = [] | ||
gammas = [] | ||
stepstostops = [] | ||
fastErrorRate = [] | ||
slowErrorRate = [] | ||
connDelayRange = [] | ||
fastDelayRange = [] | ||
slowDelayRange = [] | ||
retrievers = [] | ||
sampleNames = [] | ||
lookupTimes = [] | ||
lookupAggrDelays = [] | ||
attemptedNodes = [] | ||
finishedConnAttempts = [] | ||
successfullCons = [] | ||
failedCons = [] | ||
valRetrievable = [] | ||
totalDiscNodes = [] | ||
accuracies = [] | ||
|
||
bar = progressbar.ProgressBar( | ||
maxval=self.rn, | ||
widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()]) | ||
bar.start() | ||
|
||
for i in range(self.rn): | ||
retrieverNode = network.nodestore.get_node(random.randint(0, self.nn)) | ||
while retrieverNode.ID == builderNode.ID: | ||
retrieverNode = network.nodestore.get_node(random.randint(0, self.nn)) | ||
|
||
for l in range(self.samples): | ||
sampleContent = f"sample {l}" | ||
sh = dht.Hash(sampleContent) | ||
lstime = time.time() | ||
closest, val, summary, aggrDelay = retrieverNode.lookup_for_hash( | ||
key=sh, trackaccuracy=True, finishwithfirstvalue=True) | ||
lduration = time.time() - lstime | ||
|
||
if val == sampleContent: | ||
valRetrievable.append(1) | ||
else: | ||
valRetrievable.append(0) | ||
|
||
nns.append(self.nn) | ||
ks.append(self.k) | ||
alphas.append(self.alpha) | ||
betas.append(self.beta) | ||
gammas.append(self.gamma) | ||
stepstostops.append(self.stepsToStop) | ||
fastErrorRate.append(f"{self.fastErrorRate}") | ||
slowErrorRate.append(f"{self.slowErrorRate}") | ||
connDelayRange.append(f"{getStrFromDelayRange(self.connDelayRange)}") | ||
fastDelayRange.append(f"{getStrFromDelayRange(self.fastDelayRange)}") | ||
slowDelayRange.append(f"{getStrFromDelayRange(self.slowDelayRange)}") | ||
retrievers.append(retrieverNode.ID) | ||
sampleNames.append(sampleContent) | ||
lookupTimes.append(lduration) | ||
lookupAggrDelays.append(aggrDelay) | ||
finishedConnAttempts.append(summary['connectionFinished']) | ||
attemptedNodes.append(summary['connectionAttempts']) | ||
successfullCons.append(summary['successfulCons']) | ||
failedCons.append(summary['failedCons']) | ||
totalDiscNodes.append(summary['totalNodes']) | ||
accuracies.append(summary['accuracy']) | ||
|
||
# clean up the memory | ||
del sh | ||
del summary | ||
del closest | ||
|
||
# percentajes | ||
bar.update(i + 1) | ||
|
||
bar.finish() | ||
|
||
testDuration = time.time() - testInitTime | ||
print(f"test done in {testDuration} secs") | ||
print(f"DHT fast-init jobs:{self.jobs} done in {self.networkInitTime} secs") | ||
print(f"{self.nn} nodes, k={self.k}, alpha={self.alpha}, {len(lookupTimes)} lookups") | ||
print(f"mean time per lookup : {np.mean(lookupTimes)}") | ||
print(f"mean aggr delay (secs): {np.mean(lookupAggrDelays) / 1000}") | ||
print(f"mean contacted nodes: {np.mean(attemptedNodes)}") | ||
print(f"time to make {len(lookupTimes)} lookups: {np.sum(lookupTimes)} secs") | ||
print() | ||
|
||
# Create the panda objs and export the to csvs | ||
df = pd.DataFrame({ | ||
"number_nodes": nns, | ||
"k": ks, | ||
"alpha": alphas, | ||
"beta": betas, | ||
"gamma": gammas, | ||
"stop_steps": stepstostops, | ||
"fast_error_rate": fastErrorRate, | ||
"slow_error_rate": slowErrorRate, | ||
"connection_delay_range": connDelayRange, | ||
"fast_delay_range": fastDelayRange, | ||
"slow_delay": slowDelayRange, | ||
"retriever": retrievers, | ||
"sample": sampleNames, | ||
"lookup_wallclock_time": lookupTimes, | ||
"lookup_aggregated_delay": lookupAggrDelays, | ||
"attempted_nodes": attemptedNodes, | ||
"finished_connection_attempts": finishedConnAttempts, | ||
"successful_connections": successfullCons, | ||
"failed_connections": failedCons, | ||
"total_discovered_nodes": totalDiscNodes, | ||
"retrievable": valRetrievable, | ||
"accuracy": accuracies, | ||
}) | ||
df.to_csv(self.csvFolder + f"/retrieval_lookup{self.studyName}.csv") | ||
|
||
# save the network metrics | ||
networkMetrics = network.connection_metrics() | ||
network_df = pd.DataFrame(networkMetrics) | ||
network_df.to_csv(self.csvFolder + f"/retrieval_lookup_network{self.studyName}.csv") | ||
|
||
del network | ||
del df | ||
del network_df |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.