Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live document stats handler #537

Open
mingard opened this issue Feb 11, 2019 · 0 comments
Open

Live document stats handler #537

mingard opened this issue Feb 11, 2019 · 0 comments

Comments

@mingard
Copy link
Contributor

mingard commented Feb 11, 2019

There are some operations such as hooks and search indexing that have a heavy performance impact on API. We purposefully allow asynchronous methods inside hooks, such as model updates that don't effect the resulting payload, or third party endpoint requests that are again not crucial to the resulting payload.

Search indexing is always asynchronous which has shown to have a heavy impact when updating a large number of documents at once. The measurement of this operation is unfortunately not particularly transparent, but there may be a resolution for both hooks and search that is flexible enough not to impact performance when in production.

Stats handler

One potential is to introduce /workspace/handlers to house lightweight stats methods for logging and alerting, like an extension of consul.time/timeEnd.

Search usage

"settings": {
    "compose": true,
    "cache": false,
    "authenticate": true,
    "searchStatsHandler": "searchStats"
}

Hook usage

const Stats = require('@dadi/api').Stats

module.exports = async (obj, type, data) => {
  const stats = Stats("myStatsHandler").key(obj._id)
  someSlowAsyncPromise()
  .then(() =>  {
    stats.end()
  })
  return obj
}

Example handler

module.exports.settings = {
  maxExecTime: 100
}

module.exports.onExceedLimit = async (stats) => {
  console.log(`Time to execute ${stats.key} exceeded ${this.settings.maxExecTime}`)
}

module.exports.onEnd = async (stats) => {
  console.log(`Time to execute ${stats.key} was ${stats.duration}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant