write sampling CDF to csv file

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-09-05 10:03:11 +02:00
parent 6cd3f9af53
commit f799a11341
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
1 changed files with 30 additions and 18 deletions

48
das.nim
View File

@ -1,5 +1,5 @@
import import
std/[random, math], std/[random, math, strformat],
chronicles, chronicles,
chronos, chronos,
libp2pdht/discv5/crypto as dhtcrypto, libp2pdht/discv5/crypto as dhtcrypto,
@ -94,7 +94,7 @@ proc sample(s: Slice[int], len: int): seq[int] =
when isMainModule: when isMainModule:
proc main() {.async.} = proc main() {.async.} =
let var
nodecount = 100 nodecount = 100
delay_pernode = 10 # in millisec delay_pernode = 10 # in millisec
blocksize = 256 blocksize = 256
@ -106,6 +106,7 @@ when isMainModule:
delay_init = 60.minutes delay_init = 60.minutes
upload_timeout = 4.seconds upload_timeout = 4.seconds
sampling_delay = 4.seconds sampling_delay = 4.seconds
filename: string
assert(log2(blocksize.float).ceil.int <= segmentsize * 8 ) assert(log2(blocksize.float).ceil.int <= segmentsize * 8 )
assert(samplesize <= blocksize) assert(samplesize <= blocksize)
@ -186,23 +187,34 @@ when isMainModule:
info "sample", by = n.localNode, pass, cnt = passcount, time info "sample", by = n.localNode, pass, cnt = passcount, time
return (pass, passcount, time) return (pass, passcount, time)
# all nodes start sampling in parallel proc sampleDAMany() {.async.} =
var samplings = newSeq[Future[(bool, int, Duration)]]() # all nodes start sampling in parallel
for n in 1 ..< nodecount: var samplings = newSeq[Future[(bool, int, Duration)]]()
samplings.add(sampleDA(nodes[n][0])) for n in 1 ..< nodecount:
await allFutures(samplings) samplings.add(sampleDA(nodes[n][0]))
await allFutures(samplings)
# print statistics # print statistics
var let csvFile = open(fmt"{filename}.csv", fmWrite)
passed = 0 defer: csvFile.close()
for f in samplings:
if f.finished(): var
let (pass, passcount, time) = await f passed = 0
passed += pass.int for f in samplings:
debug "sampleStats", pass, cnt = passcount, time if f.finished():
else: let (pass, passcount, time) = await f
error "This should not happen!" passed += pass.int
info "sampleStats", passed, total = samplings.len, ratio = passed/samplings.len debug "sampleStats", pass, cnt = passcount, time
if pass:
csvFile.writeLine(time.milliseconds)
else:
csvFile.writeLine("100000") # using large value here as Gnuplot has issues with NaN
else:
error "This should not happen!"
info "sampleStats", passed, total = samplings.len, ratio = passed/samplings.len
filename = fmt"n{nodecount},dpn{delay_pernode},dinit{delay_init},bs{blocksize},ss{samplesize},sthr{samplethreshold}"
await sampleDAMany()
waitfor main() waitfor main()