Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
More instrumentation (#44)
Browse files Browse the repository at this point in the history
* Initial check-in

* Mark memo as usable outside the module.

* Comments from review
  • Loading branch information
mrose17 authored Mar 13, 2018
1 parent 573a72e commit ec2c97d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,14 @@ Client.prototype.publishersInfo = function (publishers, callback) {
this._publishersInfo(callback)
}

Client.prototype.memo = function (who, args) {
if (!this.memos) this.memos = []
if (this.memos.length > 5) this.memos.splice(0, this.memos.length - 5)
this.memos.push(JSON.stringify({ who: who, what: args || {}, when: underscore.now() }))

this._log(who, args)
}

Client.prototype._publishersInfo = function (callback) {
const self = this

Expand Down Expand Up @@ -1443,11 +1451,14 @@ Client.prototype.credentialSubmit = function (credential, surveyor, data, callba
}

Client.prototype._fuzzing = function (synopsis) {
let ratio, window
let duration = 0
let remaining = this.state.reconcileStamp - underscore.now()
let advance, memo, ratio, window

if ((!synopsis) || (remaining > (3 * msecs.day)) || (this.boolion(process.env.LEDGER_NO_FUZZING))) return
if ((!synopsis) ||
(remaining > (3 * msecs.day)) ||
(this.options && this.options.noFuzzing) ||
(this.boolion(process.env.LEDGER_NO_FUZZING))) return

synopsis.prune()
underscore.keys(synopsis.publishers).forEach((publisher) => {
Expand All @@ -1456,10 +1467,22 @@ Client.prototype._fuzzing = function (synopsis) {

// at the moment hard-wired to 30 minutes every 30 days
ratio = duration / (30 * msecs.minute)
memo = { duration: duration, ratio1: ratio, numFrames: synopsis.options.numFrames, frameSize: synopsis.options.frameSize }
window = synopsis.options.numFrames * synopsis.options.frameSize
if (window > 0) ratio *= (30 * msecs.day) / window
if (ratio >= 1.0) return

memo.window = window
memo.ratio2 = ratio

advance = Math.round((this.state.properties.days * msecs.day) * (1.0 - ratio))
memo.advance1 = advance
if (advance > (3 * msecs.day)) advance = 3 * msecs.day
memo.advance2 = advance
this.state.reconcileStamp += advance
memo.reconcileStamp = this.state.reconcileStamp

if (ratio < 1.0) this.state.reconcileStamp += Math.round((this.state.properties.days * msecs.day) * (1.0 - ratio))
this.memo('_fuzzing', memo)
}
/*
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bat-client",
"version": "2.0.11",
"version": "2.1.0",
"description": "An example of client code for the BAT.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ec2c97d

Please sign in to comment.