forked from pyr/cyanite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
engine: simplify in-memory aggregation logic. add instrumentation.
This commit brings in a number of changes: - [X] Handle input drift globally. A new component is introduced. to facilitate testing, the wall-clock is abstrated into its own component as well which the drift component depends on. - [X] Simplify the way the engine holds on to values in memory. Values are stored in an atom and updates trigger a `swap!` on the atom, yielding snapshots. - [X] Move queueing mechanism into a proper component - [X] Allow per-queue capacity and pool-size parameters. A good rule of thumb is to make room for twice your average input size, which gives the system some time to cope with bursts. - [X] Instrument critical operations, such as taking snapshots these are available as JMX by default. Configuration support will be provided to handle reporting destinations.
- Loading branch information
Showing
6 changed files
with
190 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns io.cyanite.engine.drift | ||
"Drift handling component. Relies on a clock implementation | ||
which can yield an epoch with a second based resolution." | ||
(:require [com.stuartsierra.component :as component])) | ||
|
||
(defprotocol Drift | ||
(drift! [this ts] "Take new drift into account for this timestamp") | ||
(skewed-epoch! [this] "Yield an approximate epoch, accounting for drift")) | ||
|
||
(defprotocol Clock | ||
(epoch! [this] "Give us an epoch")) | ||
|
||
;; System Clock is a basic wall clock | ||
;; No configuration possible here. | ||
(defrecord SystemClock [] | ||
component/Lifecycle | ||
(start [this] this) | ||
(stop [this] this) | ||
Clock | ||
(epoch! [this] | ||
(quot (System/currentTimeMillis) 1000))) | ||
|
||
;; Hold the state of our drift in an agent | ||
;; This way we ensure that we have fast | ||
;; execution of drift computation from | ||
;; the caller site. this should eventually | ||
;; rely on send-via to ensure we have our | ||
;; own pool of threads to handle the max calls | ||
(defrecord AgentDrift [slot clock] | ||
component/Lifecycle | ||
(start [this] | ||
(assoc this :slot (agent 0))) | ||
(stop [this] | ||
(assoc this :slot nil)) | ||
Drift | ||
(drift! [this ts] | ||
(let [drift (- ts (epoch! clock))] | ||
(when (pos? drift) | ||
(send-off slot max drift)))) | ||
(skewed-epoch! [this] | ||
(- (epoch! clock) @slot)) | ||
clojure.lang.IDeref | ||
(deref [this] | ||
@slot)) |
Oops, something went wrong.