evantahler/actionHero — pull request #246 by evantahler (2013-11-06 06:32:20+00:00)
Title: buffered stats

This branch reworks the stats initializer.

Having many calls to redis on each connection (to increment stats) significantly slowed down actionHero, even in an async world. We have changed how recording stats works to be on a timed buffer. We will store stat deltas locally and then write those deltas to redis at a fixed, configurable interval.

In this update, we remove the notion of 'global' and 'local' stats in favor of configurable stats storage hashes in redis. You can still emulate the behavior of 'global' and 'local' stats by supplying 2 backends of the form:

```javascript
configData.stats = {
witeFrequency: 1000,
keys: [
'actionHero:stats',
'actionHero:stats:' + api.id
],
```

Method Updates:

- `api.stats.increment = function(key, count)` ( no longer takes a callback )
- `api.stats.get = function(key, collection, next)` (can optionally provide which backend hash to lookup from, `collection`)
- `api.stats.getAll = function(collections, next)` (can optionally provide which backend(s) hash to lookup from, `collections`)

`api.stats.set` is removed

In simple tests, this speeds up the performance of actions about ~2x