Class: HotCell::Timing
- Inherits:
-
Object
- Object
- HotCell::Timing
- Defined in:
- lib/hot_cell/timing.rb
Overview
One request's timing ledger, carried through the worker instead of the two loose values it replaces.
It exists for the base instant rather than for tidiness. perform_ms means time spent performing where
performing happened, and time since the request arrived where it did not — a request refused for a
protocol mismatch never performed anything, so measuring it from the start is the only meaningful number.
That distinction used to live in the argument every caller passed: refuse's since was started on
three paths and began on a fourth, and getting it wrong would have been invisible. The base moves once,
here, when performing is called.
Phases accumulate as they complete, so a refusal reports the ones that finished before the failure. An
unreadable verdict that arrives with no operation_ms says exactly where it got to.
Instance Attribute Summary collapse
-
#queued_ms ⇒ Object
readonly
Returns the value of attribute queued_ms.
-
#started ⇒ Object
readonly
Returns the value of attribute started.
Instance Method Summary collapse
-
#elapsed_ms ⇒ Object
The whole request as the cell saw it, including reading the message.
-
#initialize(queued_ms) ⇒ Timing
constructor
A new instance of Timing.
- #measure(phase) ⇒ Object
-
#performing ⇒ Object
Performing starts now, so this is what perform_ms measures from.
- #to_h ⇒ Object
Constructor Details
#initialize(queued_ms) ⇒ Timing
Returns a new instance of Timing.
18 19 20 21 22 23 |
# File 'lib/hot_cell/timing.rb', line 18 def initialize(queued_ms) @queued_ms = queued_ms @started = Clock.now @base = @started @phases = {} end |
Instance Attribute Details
#queued_ms ⇒ Object (readonly)
Returns the value of attribute queued_ms.
16 17 18 |
# File 'lib/hot_cell/timing.rb', line 16 def queued_ms @queued_ms end |
#started ⇒ Object (readonly)
Returns the value of attribute started.
16 17 18 |
# File 'lib/hot_cell/timing.rb', line 16 def started @started end |
Instance Method Details
#elapsed_ms ⇒ Object
The whole request as the cell saw it, including reading the message. For the log line rather than for the caller, who is told what performing cost.
43 44 45 |
# File 'lib/hot_cell/timing.rb', line 43 def elapsed_ms Clock.ms_since started end |
#measure(phase) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hot_cell/timing.rb', line 30 def measure(phase) at = Clock.now result = yield @phases[phase] = Clock.ms_since(at) result end |
#performing ⇒ Object
Performing starts now, so this is what perform_ms measures from.
26 27 28 |
# File 'lib/hot_cell/timing.rb', line 26 def performing @base = Clock.now end |
#to_h ⇒ Object
37 38 39 |
# File 'lib/hot_cell/timing.rb', line 37 def to_h { queued_ms: queued_ms, **@phases, perform_ms: Clock.ms_since(@base) } end |