import static groovyx.gpars.GParsPool.withPool as parallel def list = ['http://google.com','http://bing.com','http://dogpile.com','http://ask.com','http://hbsecurity.com'] int maxThreads = list.size() Range range = list.size()+1..1 // +1 for warmup round boolean randomizeUrl = true Long ts // start time for each thread size println "WARMUP " + "*" * 40 (range).each { throttle -> ts = Calendar.instance.timeInMillis parallel( Math.min(maxThreads, throttle) ) { // restrict the thread pool size list.eachParallel { Long t = Calendar.instance.timeInMillis if (randomizeUrl) it += "/?" + Math.random()*10 it.toURL().text // blockin call println Thread.currentThread().toString() + " [$it] DONE >> seconds: " + ((Calendar.instance.timeInMillis - t) /1000) } } println "total time: " + ((Calendar.instance.timeInMillis - ts) / 1000) println "*" * 40 } println "==DONE=="
source: (here)
No comments:
Post a Comment