Published
Edited
Nov 3, 2020
1 star
Insert cell
md`# Network "Simulator"`
Insert cell
viewof num_nodes = slider({
title: "Number of nodes",
min:0,
max: 100000,
value: 10000,
step: 1000,
description: "Number of nodes in the network",
})
Insert cell
Insert cell
viewof network_latency = slider({
min: 0,
title: "Network latency (ms)",
max: 2000,
step: 100,
value: 100,
description: "Network latency between nodes"
})
Insert cell
viewof dhtBuckets = slider({
min: 0,
title: "DHT Buckets",
max: 100,
step: 10,
value: 20,
description: "K-buckets in the DHT"
})
Insert cell
viewof ttl = slider({
min: 0,
title: "Bitswap TTL",
max: 20,
step: 1,
value:1,
description: "TTL enabled for Bitswap"
})
Insert cell
// TTL = 0 is vanilla Bitswap
viewof degree = slider({
min: 0,
title: "Bitswap Degree",
max: num_links*num_nodes,
step: 1,
value: 1,
description: "TTL Degree for Bitswap"
})
Insert cell
viewof content_popularity = slider({
min: 1,
title: "Content popularity",
max: num_nodes/10,
step: 10,
value: 1,
description: "Number of nodes storing the content"
})
Insert cell
data = dhtLatency(num_nodes, network_latency, dhtBuckets).concat(ttlLatency(num_nodes, network_latency, ttl, degree, content_popularity))
Insert cell
md`# Lookup latency`
Insert cell
vl.markBar({stroke: "black", fill: "#EEBCDD"})
.height(250)
.width(400)
.data(data)
.encode(
vl.x().fieldN("scheme").sort({field:"scheme", order:"descending"}).scale({paddingInner: .4}),
vl.y().fieldQ("latency"),
vl.tooltip().fieldQ("latency")
)
.render()
Insert cell
prob_data = [{scheme: "DHT", probability:1}, {scheme: "TTL", probability:ttlLatency(num_nodes, network_latency, ttl, degree, content_popularity)[0].probability}]
Insert cell
ttlLatency(num_nodes, network_latency, ttl, degree)
Insert cell
md`# Probability finding content`
Insert cell
vl.markBar({stroke: "black", fill: "#EEBCDD"})
.height(250)
.width(400)
.data(prob_data)
.encode(
vl.x().fieldN("scheme").sort({field:"scheme", order:"descending"}).scale({paddingInner: .4}),
vl.y().fieldQ("probability"),
vl.tooltip().fieldQ("probability")
)
.render()
Insert cell
function connectionLatency(latency){
const rtt = 2*latency
const conn = rtt //Initiate connection
const noise = 1.5*rtt //XX pattern for noise
const multistream = rtt // Multistream negotiation.
const stream_negotiation = rtt // Bitswap or DHT
return conn + noise + multistream
}
Insert cell
function dhtLatency(nodes, latency, kBuckets) {
const conn = connectionLatency(latency)
const reqResp = 2*latency
const worstCase = conn + Math.log2(nodes)*reqResp
const avgCase = conn + Math.log(nodes)/Math.log(kBuckets)*reqResp
//TODO: Take popularity of the content into account in the DHT lookup
return [{scheme: "DHT (avg)", latency: avgCase}, {scheme: "DHT (worst)", latency: worstCase} ]
}
Insert cell
function ttlLatency(nodes, latency, ttl, degree, popularity) {
const conn = connectionLatency(latency)
const reqResp = 4*latency //WANT-HAVE -- WANT-BLOCK
let res = 0
let probability = 0
for (let i = 0; i<=ttl; i++) {
probability += probability_find_ttl(nodes, i, degree, popularity)
res += probability_find_ttl(nodes, i, degree, popularity)*reqResp
}
return [{scheme: "TTL", latency: conn + res, probability: Math.min(1, probability)}]
}
Insert cell
// Probability of finding the content in the current ttl
function probability_find_ttl(nodes, current_ttl, degree, content_popularity){
let subset = nodes/content_popularity
return (Math.pow(degree,current_ttl+1))/(Math.max(1,subset-Math.pow(degree,current_ttl+1)))
}
Insert cell
// Check: https://observablehq.com/@d3/sticky-force-layout?collection=@d3/d3-drag
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more