On Github kleibl / human_scale_quizz
Taken from Erik Meijer's talk in "Principles of Reactive programming" at Coursera.org
trait Socket { def readFromMemory(): Array[Byte] def sendToEurope(packet: Array[Byte]): Array[Byte] } val socket = Socket() val packet = socket.readFromMemory() val confirmation = socket.sendToEurope(packet)
trait Socket { def readFromMemory(): Array[Byte] def sendToEurope(packet: Array[Byte]): Array[Byte] } val socket = Socket() val packet = socket.readFromMemory() // block for 250,000 ns // only continue if there is no exception val confirmation = socket.sendToEurope(packet) // block for (more than) 150,000,000 ns // only continue if there is no exception
1 nanosecond
->
1 second
(then hours/days/months/years)
1 nanosec -> 1 sec
execute typical instruction 1 nanosec fetch from L1 cache memory 0.5 nanosec branch misprediction 5 nanosec fetch from L2 cache memory 7 nanosec Mutex lock/unlock 25 nanosec fetch from main memory 100 nanosec send 2K bytes over 1Gbps network 20,000 nanosec read 1MB sequentially from memory 250,000 nanosec fetch from new disk location (seek) 8,000,000 nanosec read 1MB sequentially from disk 20,000,000 nanosec send packet US to Europe and back 150 milliseconds = 150,000,000 nanosec1 nanosec
->
1 second
7 nanosec
->
a) 1 second
b) 17 second
c) 7 second
d) 0.7 second
20,000 nanosec
->
a) 5.5 hours
b) 18 minutes
c) 3 days
d) 1 month
250,000 nanosec
->
a) 1.5 year
b) 19 hours
c) 3 days
d) 7 weeks
8,000,000 nanosec
->
a) 6 days
b) 5 months
c) 13 weeks
d) 3 years
20,000,000 nanosec
->
a) 27 days
b) 6.5 months
c) 9 years
d) 1.5 year
150 milliseconds = 150,000,000 nanosec
->
a) 5 years
b) 11 months
c) 17 years
d) 3 weeks
trait Socket { def readFromMemory(): Array[Byte] def sendToEurope(packet: Array[Byte]): Array[Byte] } val socket = Socket() val packet = socket.readFromMemory() // block for 3 days // only continue if there is no exception val confirmation = socket.sendToEurope(packet) // block for 5 years // only continue if there is no exception
karol.kleibl@asseco-ce.com