vary-network-load.R 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ## The waiting time for a node (assuming no overloaded nodes)
  2. ## x: 1/bandwidth
  3. ## q: selection probability
  4. ## L: network load
  5. wait <- function(x,q,L) {
  6. a <- q*L*x*x
  7. b <- 2*(1-q*x*L)
  8. return (x + a/b)
  9. }
  10. ## The weighted wait time
  11. wwait <- function(x,q,L) {
  12. return (q*wait(x,q,L))
  13. }
  14. ## Average latency, returning NA for infinite
  15. netLatency <- function(x, q, L) {
  16. if (any(x*q*L <0 | x*q*L >1)) {
  17. return (NA)
  18. } else {
  19. return (sum(wwait(x, q, L)))
  20. }
  21. }
  22. ## Load in data files
  23. t1 <- read.table("opt_1e-6.pickle.dat", header=TRUE)
  24. t2 <- read.table("opt_1e-3.pickle.dat", header=TRUE)
  25. t3 <- read.table("opt_1e-1.pickle.dat", header=TRUE)
  26. t4 <- read.table("opt_0.75.pickle.dat", header=TRUE)
  27. t5 <- read.table("opt_0.5.pickle.dat", header=TRUE)
  28. t6 <- read.table("opt_0.25.pickle.dat", header=TRUE)
  29. t7 <- read.table("opt_0.1.pickle.dat", header=TRUE)
  30. tt <- read.table("opt_tor.pickle.dat", header=TRUE)
  31. ## Node bandwidth and reciprocal
  32. bw <- t1$bw
  33. x <- 1/bw
  34. ## Calculate network capcity
  35. capacity <- sum(bw)
  36. ## Calculate selection probabilties that Tor uses
  37. torProb <- bw/sum(bw)
  38. ## Load values to try
  39. varyLoad <- seq(0.01,0.93,0.01)
  40. latencyTor <- c()
  41. latency3 <- c()
  42. latency4 <- c()
  43. latency5 <- c()
  44. for (L in varyLoad) {
  45. latencyTor <- append(latencyTor,
  46. netLatency(x, torProb, capacity*L))
  47. latency3 <- append(latency3,
  48. netLatency(x, t3$prob, capacity*L))
  49. latency4 <- append(latency4,
  50. netLatency(x, t4$prob, capacity*L))
  51. latency5 <- append(latency5,
  52. netLatency(x, t5$prob, capacity*L))
  53. }
  54. ## Output graph
  55. pdf("vary-network-load.pdf")
  56. ## Set up axes
  57. yFac <- 1000
  58. xFac <- 100
  59. ylim <- range(na.omit(c(latencyTor, latency3, latency4, latency5)))
  60. ylim <- c(0,0.015) * yFac
  61. xlim <- c(0,1) * xFac
  62. plot(NA, NA,
  63. xlim=xlim, ylim=ylim,
  64. frame.plot=FALSE,
  65. xlab = "Network load (%)",
  66. ylab = "Average queuing delay (ms)",
  67. main = "Latency for varying network loads")
  68. ## Plot data
  69. col <- rainbow(8)
  70. lines(varyLoad*xFac, latency3*yFac, col=col[3])
  71. lines(varyLoad*xFac, latency4*yFac, col=col[4])
  72. lines(varyLoad*xFac, latency5*yFac, col=col[5])
  73. lines(varyLoad*xFac, latencyTor*yFac)
  74. ## Plot points at which selection probabilities are optimal
  75. par(xpd=TRUE)
  76. points(c(0.9, 0.75, 0.5, 1)*xFac, rep(par("usr")[3], 4),
  77. col=c(col[3:5], "black"), pch=20,
  78. cex=2)
  79. ## Close output device
  80. dev.off()