Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Rate-counter/E/rate-counter-1.e
Normal file
24
Task/Rate-counter/E/rate-counter-1.e
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
def makeLamportSlot := <import:org.erights.e.elib.slot.makeLamportSlot>
|
||||
|
||||
The rate counter:
|
||||
|
||||
/** Returns a function to call to report the event being counted, and an
|
||||
EverReporter slot containing the current rate, as a float64 in units of
|
||||
events per millisecond. */
|
||||
def makeRateCounter(timer, reportPeriod) {
|
||||
var count := 0
|
||||
var start := timer.now()
|
||||
def &rate := makeLamportSlot(nullOk[float64], null)
|
||||
|
||||
def signal() {
|
||||
def time := timer.now()
|
||||
count += 1
|
||||
if (time >= start + reportPeriod) {
|
||||
rate := count / (time - start)
|
||||
start := time
|
||||
count := 0
|
||||
}
|
||||
}
|
||||
|
||||
return [signal, &rate]
|
||||
}
|
||||
34
Task/Rate-counter/E/rate-counter-2.e
Normal file
34
Task/Rate-counter/E/rate-counter-2.e
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/** Dummy task: Retrieve http://localhost/ and return the content. */
|
||||
def theJob() {
|
||||
return when (def text := <http://localhost/> <- getText()) -> {
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
/** Repeatedly run 'action' and wait for it until five seconds have elapsed. */
|
||||
def repeatForFiveSeconds(action) {
|
||||
def stopTime := timer.now() + 5000
|
||||
def loop() {
|
||||
if (timer.now() < stopTime) {
|
||||
when (action <- ()) -> {
|
||||
loop()
|
||||
}
|
||||
}
|
||||
}
|
||||
loop()
|
||||
}
|
||||
|
||||
def whenever := <import:org.erights.e.elib.slot.whenever>
|
||||
|
||||
def [signal, &rate] := makeRateCounter(timer, 1000)
|
||||
|
||||
# Prepare to report the rate info.
|
||||
whenever([&rate], fn {
|
||||
println(`Rate: ${rate*1000} requests/sec`)
|
||||
}, fn {true})
|
||||
|
||||
# Do some stuff to be counted.
|
||||
repeatForFiveSeconds(fn {
|
||||
signal()
|
||||
theJob()
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue