Commit 90eb7b67 authored by Mart Lubbers's avatar Mart Lubbers

Idle a bit more smart

parent 6be758d6
......@@ -51,7 +51,7 @@ defaultEngineOptions world
, sessionTime = {tv_sec=60,tv_nsec=0} // 1 minute, (the client pings every 10 seconds by default)
, persistTasks = False
, autoLayout = True
, timeout = Just 100
, timeout = Just 500
, webDirPath = appDir </> appName +++ "-www"
, storeDirPath = appDir </> appName +++ "-data" </> "stores"
, tempDirPath = appDir </> appName +++ "-data" </> "tmp"
......
......@@ -18,10 +18,14 @@ from TCPIP import :: Timeout
import Data.Queue
import Text
import StdDebug, StdMisc, StdString
timeout :: !(Maybe Timeout) !*IWorld -> (!Maybe Timeout,!*IWorld)
timeout mt iworld = case read taskEvents iworld of //Check if there are events in the queue
(Ok (Queue [] []),iworld=:{sdsNotifyRequests})
= (minListBy lesser [mt/*:map getTimoutFromClock sdsNotifyRequests*/], iworld)
timeout mt iworld = case read taskEvents iworld of
//No events
(Ok (Queue [] []),iworld=:{sdsNotifyRequests,world})
# (ts, world) = nsTime world
= ( minListBy lesser [mt:map (getTimoutFromClock ts) sdsNotifyRequests]
, {iworld & world = world})
(Ok _,iworld) = (Just 0,iworld) //There are still events, don't wait
(Error _,iworld) = (Just 500,iworld) //Keep retrying, but not too fast
where
......@@ -29,12 +33,15 @@ where
lesser (Just _) Nothing = True
lesser Nothing Nothing = False
getTimoutFromClock :: SDSNotifyRequest -> Maybe Int
getTimoutFromClock snr=:{cmpParam=(ts :: ClockParameter Timespec)}
getTimoutFromClock :: Timespec SDSNotifyRequest -> Maybe Int
getTimoutFromClock now snr=:{cmpParam=(ts :: ClockParameter Timespec)}
| startsWith "$IWorld:timespec$" snr.reqSDSId
= mt
# fire = iworldTimespecNextFire now snr.reqTimespec ts
= Just (max 0 (toMs fire - toMs now))
= mt
getTimoutFromClock _ = mt
getTimoutFromClock _ _ = mt
toMs x = x.tv_sec * 1000 + x.tv_nsec / 1000000
updateClock :: !*IWorld -> *(!MaybeError TaskException (), !*IWorld)
updateClock iworld=:{IWorld|clock,world}
......
......@@ -152,9 +152,18 @@ destroyIWorld :: !*IWorld -> *World
, interval :: a
}
iworldTimespec :: SDS (ClockParameter Timespec) Timespec Timespec
iworldTimestamp :: SDS (ClockParameter Timestamp) Timestamp Timestamp
iworldLocalDateTime :: ReadOnlyShared DateTime
iworldTimespec :: SDS (ClockParameter Timespec) Timespec Timespec
/*
* Calculate the next fire for the given timespec
*
* @param now
* @param registration time
* @param clock parameter
* @result time to fire next
*/
iworldTimespecNextFire :: Timespec Timespec (ClockParameter Timespec) -> Timespec
iworldTimestamp :: SDS (ClockParameter Timestamp) Timestamp Timestamp
iworldLocalDateTime :: ReadOnlyShared DateTime
iworldLocalDateTime` :: !*IWorld -> (!DateTime, !*IWorld)
......
......@@ -122,17 +122,21 @@ where
read _ iworld=:{IWorld|clock} = (Ok clock,iworld)
write _ timestamp iworld = (Ok pred, {iworld & clock = timestamp})
where
pred reg {start,interval}
pred reg p=:{start,interval}
| interval == zero = True // We don't divide by zero
| timestamp < start = False // Start time has not passed
# start = toI start
interval = toI interval
reg = toI reg
passed = reg - start
nextFire = toT (start + ((passed / interval + one) * interval))
= timestamp > nextFire
toI x = toInteger x.tv_sec * toInteger 1000000000 + toInteger x.tv_nsec
toT x = {tv_sec=toInt (x/toInteger 1000000000), tv_nsec=toInt (x rem toInteger 1000000000)}
= timestamp > iworldTimespecNextFire timestamp reg p
iworldTimespecNextFire :: Timespec Timespec (ClockParameter Timespec) -> Timespec
iworldTimespecNextFire now reg {start,interval}
# start = toI start
interval = toI interval
reg = toI reg
passed = reg - start
= toT (start + ((passed / interval + one) * interval))
where
toI x = toInteger x.tv_sec * toInteger 1000000000 + toInteger x.tv_nsec
toT x = {tv_sec=toInt (x/toInteger 1000000000), tv_nsec=toInt (x rem toInteger 1000000000)}
iworldTimestamp :: SDS (ClockParameter Timestamp) Timestamp Timestamp
iworldTimestamp = mapReadWrite (timespecToStamp, const o Just o timestampToSpec)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment