Skip to content

Instantly share code, notes, and snippets.

@storenth
Forked from oalee/p2p-vs-clientserver.py
Created December 10, 2018 11:18
Show Gist options
  • Save storenth/116210871a8536a80f6d2e6a17119d29 to your computer and use it in GitHub Desktop.
Save storenth/116210871a8536a80f6d2e6a17119d29 to your computer and use it in GitHub Desktop.
p2p vs client server time
# -*- coding: utf-8 -*-
"""
Spyder Editor
"""
import plotly.offline as py
import plotly.graph_objs as go
#{F/u s, ,F/d min, ,NF/( u s + Σ u i )
def p2p(N, filesize, us, up, di):
return max(filesize/us, filesize/di, N*filesize/(us + sum(up)))
#NF/u s, ,F/d mi
def client_server(N, filesize, us, di):
return max(N*filesize/us, filesize/di)
# Consider distributing a file of F = 10 Gbits to N peers. The server has an upload rate of us =
#20Mbps, and each peer has a download rate of di = 1 Mbps and an upload rate of u. For N=10,
#100 and 1000 and u = 200Kbps, 600 Kbps and 1 Mbps
def simulate():
filesize = 10 * 1000 * 1000 #kilo bit
us = 20 * 1000 #kilobit/s
di = 1 * 1000 #kilobit/s
numbers = [10, 100, 1000]
upeers = [200, 600, 1000]
tp2p = []
tclient_server = []
for i in range(0, len(numbers)):
tp2p.append(p2p(numbers[i], filesize, us, [upeers[i]] * numbers[i], di))
tclient_server.append(client_server(numbers[i], filesize, us, di))
print(tp2p)
print(tclient_server)
trace0 = go.Scatter(
x = numbers,
y = tp2p,
mode = 'lines+markers',
name = 'p2p'
)
trace1 = go.Scatter(
x = numbers,
y = tclient_server,
mode = 'lines+markers',
name = 'client server'
)
py.plot([trace0, trace1], filename='time in p2p and clinet server')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment